【问题标题】:how to make following div responsive [closed]如何使以下 div 响应 [关闭]
【发布时间】:2016-08-29 18:29:56
【问题描述】:

I want to make this responsive **我用 html 和 css 设计了这个,我想让这个 div 响应...我该怎么做?

我尝试使用引导列,但它不起作用

如果背景图像的高度固定,请告诉我如何使背景响应。

.im1
{
  /*padding: 10px;*/
  /*margin-left: 60px;*/
  margin-top: 10px;
  z-index: 1;
  width: 250px;
  height: 250px;
  margin-right: -80px;
}

.background1 {
  background: url("../car/car_web.jpg");
  /*border: 2px solid black;*/
  width:1380px;
  height:350px;
  background-repeat: no-repeat;
  padding: 50px;
  padding-top: 10px;
  padding-left: 130px;
  left: 0px;
  /*position: absolute;*/
  /*top: 20px;*/
  margin-left: -155px;
    
}
<section id="COMPARE" style="margin-left: 100px;">
  <div class="container">
    <div class="col-md-12 background1">
        <label class="ll">
      <center><small><strong>Car Comparison lorims info</strong></small>
        <h3>Compare Cars</h3>
      </center>
      </label><br>
         
<div class="im1 col-md-3" style="position:relative; margin-left:40px;">
              <img class="" src="car/1.jpg" width="200px;" height="120px;" style=" position:absolute; z-index=1; top:0px; left:80px;">
              <img src="icon/vs.png" width="55px" height="55px" style="position:absolute; top:30px; left:260px; z-index:3;">
              <img class="" src="car/2.jpg" width="200px;" height="120px;" style=" position:absolute; z-index=1; top:0px; left:300px;">
              <img src="icon/vs.png" width="55px" height="55px" style="position:absolute; top:30px; left:480px; z-index:3;">
              <img class="" src="car/3.jpg" width="200px;" height="120px;" style=" position:absolute; z-index=1; top:0px; left:520px;">
               <img src="icon/vs.png" width="55px" height="55px" style="position:absolute; top:30px; left:700px; z-index:3;">
              <img class="" src="car/4.jpg" width="200px;" height="120px;" style=" position:absolute; z-index=1; top:0px; left:740px;">  
             </div>
          
          
          <div class="col-md-12 de" id="compare">
            <button type="submit" class="btn btn-primary12 btn-lg outline1 " name="login">COMPARE CARS</button></span>
            <br>
            <br>
            <small><strong>Or <a href="#">Click here for custom comparison</a></strong></small>
          </div>
    </div>
  </div>
</section> 

【问题讨论】:

  • 分享你的代码??
  • 请包含您当前拥有的代码
  • 你应该看看这个 - stackoverflow.com/help/asking
  • 要么以百分比形式制作 div 的 css,要么了解 @media queries
  • 复制代码,粘贴到...

标签: html css responsive-design


【解决方案1】:

https://jsfiddle.net/o05yvL1h/
https://jsfiddle.net/o05yvL1h/2/

div {
  display: inline-block;
  width: 23%;
  width: calc(25% - 1em);
  margin: 1em .5em;
  background: silver;
  line-height: 4em;
  text-align: center;
  position: relative;
}

div + div:after {
  content: "VS";
  line-height: 2em;
  width: 2em;
  margin: -1em;
  position: absolute;
  border-radius: 50%;
  background: blue;
  color: white;
  top: 50%;
  left: -.5em;
}

@media all and (max-width: 320px) {
  div {
    display: block;
    width: auto;
  }
  
  div + div:after {
    top: -.5em;
    left: 50%;
  }
}
<div>
  1
</div><div>
  2
</div><div>
  3
</div><div>
  4
</div>

【讨论】:

  • 谢谢...但是在移动设备上看不清汽车图像...
  • 如果我按照@media only 屏幕和 (max-width: 480px) { .carImage{ width: 100%; 显示汽车图像,我应该怎么做才能将“vs”放在图像下方} }
  • @Prasad,添加了媒体查询。
  • 非常感谢您.. 如何使背景图像响应?我已经为此使用了 background1 类...
【解决方案2】:

不幸的是,如果不查看您的编码方式,很难看到问题,您能否复制您的代码以便我们查看您的设置方式?

但是,我会试一试。我将假设这四辆车在一个包装器 div 中,并且当窗口变小时,您希望车辆的图像彼此下方.. 像这样:

/* Standard size */
.carImage{
   width: 25%;
}

/* Tablet Size */
@media only screen and (max-width: 768px) {
   .carImage{
      width: 50%;
   }
}

/* Mobile Size */
@media only screen and (max-width: 480px) {
   .carImage{
      width: 100%;
   }
}

.carImage 更改为您为每个汽车图像设置的任何类 - 但再一次,除非您将代码粘贴进去,否则我无法说出确切的问题。如果这无助于复制代码,我会尝试再次。

编辑:查看您发送的代码后:

https://jsfiddle.net/o05yvL1h/3/

我不会像你那样使用position: absolute;,我个人不经常使用它,所以也许这不会有帮助,但也许它会 - 只是你如何可能的一个简单示例去做吧。我已经更改了图像源,仅作为示例,希望对您有所帮助...

【讨论】:

  • 谢谢...我已经粘贴了我的代码,你能建议更好的新代码吗?
  • 查看 JS fiddle with 以获取示例 - 希望对您有所帮助...
  • 谢谢...它适用于汽车和vs类...现在如何使背景图像响应?我已经为此使用了 background1 类...
  • 我可能会添加 width: 100%; 以允许 div 缩放。然后可能添加background-size: cover; 以确保图像覆盖div。将此添加到.background1 我认为:-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-19
  • 2017-01-06
  • 2014-06-05
  • 1970-01-01
  • 1970-01-01
  • 2015-07-24
相关资源
最近更新 更多