简体   繁体   English

我怎样才能让我的盒子对任何屏幕尺寸做出反应

[英]how can I make my box respond to any screen size

If you check my PEN I am trying to create a responsive box. 如果您选中我的笔,我正在尝试创建一个响应框。

At the moment,If I scale down the page, the items will start hiding. 此刻,如果我按比例缩小页面,则这些项将开始隐藏。 Is there a way I can make this green box adjust to any mobile screen size? 有什么办法可以让这个绿色框适应任何移动屏幕尺寸?

HTML: 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: 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;
}

Hope you can help. 希望能对您有所帮助。

Just apply a width of 100% and a max-width of 500px: 只需应用100%的宽度和500px的最大宽度即可:

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

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

Changing width: 500px; 更改width: 500px; to max-width: 500px; max-width: 500px; at .card-details will adjust the width. .card-details将调整宽度。

If you want to adjust the height you probably will have to change height to auto or try with flexbox or media queries 如果要调整高度,则可能必须将高度更改为自动,或者尝试使用flexbox或媒体查询

Change width to max-width in your .card-details element. 更改widthmax-width.card-details元素。

Do

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

Instead of 代替

.card-details {
  width: 500px;
}

Hope this helps! 希望这可以帮助!

Without any media query you have use this. 没有任何媒体查询,您就可以使用它。

  .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; } 
 <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> 

  .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> 

Hope this does fine. 希望这很好。 First, of all I included the row and column in the container such that it is adjusted even for extra small size screen. 首先,我将行和列包括在容器中,以便即使对于超小尺寸的屏幕也可以对其进行调整。 Secondly, You will have to remove the width and height of the card-details class. 其次,您将必须删除card-details类的宽度和高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM