[英]resize on responsive css div using margin-top etc
大家好,美好的一天!
任何人都可以就如何完成我的css代码提出一些建议,请参阅下面的代码。 当我为响应目的而调整浏览器大小时的当前状态。
<div style="width:100%; height:auto; position:relative;">
<div style="min-width:300px; height:500px; float:left; background-color:orange;">
<!-- some content here -->
</div>
<div style="min-width:300px; height:200px; float:left; margin-top:300px; background-color:green;">
<!-- some content here -->
</div>
</div>
该代码的输出有一个很大的距离,我把它放在css margin-top:300px; 当我调整浏览器的大小到最小尺寸。
是可以解决???
您可以使用媒体查询。
@media screen and (max-width:450px)
{
.divID{
//code goes in here
margin-top:50px;
}
}
所以在这里,当屏幕宽度为450px
或更450px
, margin-top
将减少到50px
。
我建议使用%
或em
而不是px
单位。 因为%
或em
有助于根据可用的屏幕宽度调整元素width
或height
。 pixel
不会这样做。
以下是使用媒体查询的一些参考。 参考
您可以考虑使用框架。
在这种情况下:使用媒体查询。 看看
如果我不明白你想要下一个错误:当你调整浏览器的大小时,边距顶部将是30px(例子)
你可以使用媒体查询
像这样:
<div style="width:100%; height:auto; position:relative;">
<div style="min-width:300px; height:500px; float:left; background-color:orange;">
<!-- some content here -->
</div>
<div id="div2" style="min-width:300px; height:200px; float:left; margin-top:300px; background-color:green;">
<!-- some content here -->
</div>
</div>
CSS代码:
@media (max-width: 300px) {
#div2{
margin-top:30px;
}
}
你也应该使用CSS文件而不是在html中编写样式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.