我有一个div,只有当我设置它的滚动最大宽度时,它才能正常工作。我希望能够在css中将其最大宽度设置为设备宽度,这可能吗?使用viewport.width之类的东西吗?
发布于 2015-04-07 10:34:30
试一试
div{
vw: 100;
}1vw =视口宽度的1%
1vh =视口高度的1%
1vmin = 1vw或1vh,取较小的值1
vmax = 1vw或1vh,以较大者为准
发布于 2015-04-07 10:40:36
在CSS中,您应该能够将max设置为%100。如果div是嵌套的,则可以设置位置绝对。
html,
body {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
position: relative;
}
.not-nested {
display: inline-block;
max-width: 100%;
}
.nested {
display: inline-block;
position: absolute;
max-width: 100%;
}
.half {
display: inline-block;
width: 50%;
}<h1>Not Nested</h1>
<div class="not-nested">This dis has a max width of 100% and the text in it will wrap as it goes on and on and on and on and on and on and on and on.</div>
<h1>Nested</h1>
<div class="half">
<div class="nested">This dis has a max width of 100% and the text in it will wrap as it goes on and on and on and on and on and on and on and on.</div>
</div>
https://stackoverflow.com/questions/29482717
复制相似问题