如何让我的盒子响应任何屏幕尺寸

时间:2016-11-15 08:51:08

标签: html css css3

如果您检查我的PEN我正在尝试创建响应式广告框。

目前,如果我缩小页面,项目将开始隐藏。 有没有办法让这个绿色框适应任何移动屏幕大小?

HTML:

<div class="container">
  <div class="card-details">
      <div class="bo1">
        <img src="" alt="VISA ICON" class="visa">
        <input type="text" >
      </div>
      <div class="bo2">
        <p class="card-number" >CARD NUMBER</p>
        <input class="card-input" type="text" />
      </div>
      <a href="#" class="deposit-now" style="color:white" >DEPOSIT NOW</a> 
  </div>
</div>

CSS:

.container{
  max-width: 600px;
  background-color: blue;
  margin: auto;
}
.card-details{
  position: relative;
  background: green;
  border-radius: 10px;
  width: 500px;
  height: 250px;
  margin: auto;
  padding: 10px;
}
.card-details .bo1 input{
  float: right;
}
.card-details a.deposit-now{
  position: absolute;
  bottom: 0;
  right: 20px;
}

希望你能提供帮助。

5 个答案:

答案 0 :(得分:2)

只需应用100%的宽度和500px的最大宽度:

.card-details{
  max-width: 500px;
  width: 100%;
}

https://codepen.io/anon/pen/dOXjMO

答案 1 :(得分:0)

width: 500px;max-width: 500px;更改为.card-details会调整宽度。

如果您想调整高度,您可能需要将高度更改为自动或尝试使用flexbox或媒体查询

答案 2 :(得分:0)

width元素中的max-width更改为.card-details

待办事项

.card-details {
  max-width: 500px;
}

而不是

.card-details {
  width: 500px;
}

希望这有帮助!

答案 3 :(得分:0)

您没有使用任何媒体查询。

&#13;
&#13;
   .container{
      width: 600px;
      max-width: 100%;
      background-color: blue;
      margin: auto;
    }
    .card-details{
      position: relative;
      background: green;
      border-radius: 10px;
      width: 80%;
      height: 250px;
      margin: auto;
      padding: 10px;
    }
    .card-details .bo1 input{
      float: right;
    }
    .card-details a.deposit-now{
      position: absolute;
      bottom: 0;
      right: 20px;
    }
&#13;
<div class="container">
      <div class="card-details">
          <div class="bo1">
            <img src="" alt="VISA ICON" class="visa">
            <input type="text" >
          </div>
          <div class="bo2">
            <p class="card-number" >CARD NUMBER</p>
            <input class="card-input" type="text" />
          </div>
          <a href="#" class="deposit-now" style="color:white" >DEPOSIT NOW</a> 
      </div>
    </div>
&#13;
&#13;
&#13;

答案 4 :(得分:0)

 .container{
  max-width: 600px;
  background-color: blue;
  margin: auto;
}
.card-details{
  position: relative;
  background: green;
  max-width:500px;
  height:250px;
  border-radius: 10px;
  margin: auto;
  padding: 10px;
}
.card-details .bo1 input{
  float: right;
}
.card-details a.deposit-now{
  position: absolute;
  bottom: 0;
  right: 20px;
}
<div class="container">
        <div class="row">
            <div class="col-xs-12">
  <div class="card-details">
      <div class="bo1">
        <img src="" alt="VISA ICON" class="visa">
        <input type="text" >
      </div>
      <div class="bo2">
        <p class="card-number" >CARD NUMBER</p>
        <input class="card-input" type="text" />
      </div>
      <a href="#" class="deposit-now" style="color:white" >DEPOSIT NOW</a> 
  </div>
</div>

希望这样做很好。首先,我将容器中的行和列包括在内,以便即使对于超小尺寸的屏幕也可以进行调整。其次,您必须删除卡片详细信息类的宽度和高度。

相关问题