CSS:在屏幕外浮动两个 100% 宽度的 div 元素?
我记得不久前问过这个问题,但我似乎找不到了!我已经搜索过,但似乎找不到我正在寻找的解决方案。
假设我有两个 100% 宽度的 div,彼此相邻浮动。当它们占据整个屏幕宽度时,不再有任何空间可供它们浮动,因此第二个 div 出现在第一个 div 的下方。我想要的是让第二个 div 继续浮动在第一个 div 旁边的屏幕上。
我认为我得到的解决方案是将display属性设置为其他内容,但我不完全确定。
有什么建议吗?
I remember asking this question a while back but i can't seem to find it again! I've searched but i can't seem to find the solution i'm looking for.
Let's say i have two divs with 100% width floated next to each other. As they take up the entire screenwidth, there is no longer any space left for them to float on, and therefore the second div appear below the first one. What i want is to make the second div continue floating off screen next to the first one.
I think the solution i got was to set the display property to something else, but i'm not entirely sure.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信你必须有一个容器并将容器宽度设置为 200%。两个宽度为 50% 的内部 div 将适合放入其中。
I believe you would have to have a container and set the container width to 200%. The two inside divs with 50% width will fit inside.
你可以绝对地定位它们。
它们绝对位于相对定位的父级的范围内。
然后在它们之间切换,只需切换左侧的值,分别从 0 到 100%。
You could position them absolutely.
They are positioned absolutely within the bound of the relatively positioned parent.
Then you switch between them you just switch the left values, from 0 to 100% respectively.
给两个 div 50% 的宽度
所以它们一起占据 100% 宽度
give 50% width to both div
so they occupy 100% width together