对于我的元素网站首页,我一直在尝试设置 div,如下图所示。 但我无法获得所需的结果。请帮忙。
主 div(黑色边框)的宽度为 910px。 Div-1、2 和 5 的宽度相同,均为 900px。但是 Div-3 和 Div-4 是不同的,因为它们是内容页面和侧边栏。 Div-3 为 635px 宽,Div-4 为 255px 宽。 如上图所示,Div-3 进一步分为子分区。 所有 div 的高度都应为自动。
如何设置 CSS 和 HTML?
最佳答案
当您有多个水平相邻的 div 时,您需要使用 float (在您的情况下,div 3 和 4,以及所有 div 3 subdivs)。 Here是一个不错的小教程,会对您有很大帮助。
For variable height columns, absolute positioning does not work, so let's come up with another solution.
We can "float" an element to push it as far as possible to the right or to the left, and allow text to wrap around it. This is typically used for images, but we will use it for more complex layout tasks (because it's the only tool we have).
编辑
更多教程:http://www.html.net/tutorials/css/lesson13.php和 http://www.tizag.com/cssT/float.php .
您也可以尝试使用 display: inline-block;
来获得类似的结果。
关于css - 如何在典型布局中设置多个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14513979/