首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要将div max-width设置为device-width

我需要将div max-width设置为device-width
EN

Stack Overflow用户
提问于 2015-04-07 10:28:15
回答 2查看 117关注 0票数 0

我有一个div,只有当我设置它的滚动最大宽度时,它才能正常工作。我希望能够在css中将其最大宽度设置为设备宽度,这可能吗?使用viewport.width之类的东西吗?

EN

回答 2

Stack Overflow用户

发布于 2015-04-07 10:34:30

试一试

代码语言:javascript
复制
div{
  vw: 100;
}

1vw =视口宽度的1%

1vh =视口高度的1%

1vmin = 1vw或1vh,取较小的值1

vmax = 1vw或1vh,以较大者为准

https://css-tricks.com/viewport-sized-typography/

票数 0
EN

Stack Overflow用户

发布于 2015-04-07 10:40:36

在CSS中,您应该能够将max设置为%100。如果div是嵌套的,则可以设置位置绝对。

代码语言:javascript
复制
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%;
}
代码语言:javascript
复制
<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>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29482717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档