简体   繁体   English

Div CSS表格无法正确呈现

[英]Div CSS table is not rendering properly

I have created a DIV + CSS style table like layout. 我创建了一个像布局一样的DIV + CSS样式表。 However, the third column keeps on getting display below the first 2 columns. 但是,第三列继续显示在前两列之下。 Even if I use width as 33% (ie total under 100%) its the case. 即使我使用宽度为33%(即总不到100%)的情况。

HTML tags are as follows: HTML标签如下:

        <div id="container">
            <div id="column1">
                Some Content for the first column.
            </div>
            <div id="column2">
                Some Content for the second column.
            </div>
            <div id="column3">
                Some Content for the third column.
            </div>
        </div>

CSS sheet contains: CSS表包含:

    #column1 {
        float: left;
        width: 33%;
        border: solid;
    }

    #column2 {
        float: left;
        width: 34%;
        border: solid;
    }

    #column3 {
        float: left;
        width: 33%;
        border: solid;
    }

How to make sure they will render properly on all kind of resolutions? 如何确保它们能在各种分辨率下正确呈现?

The default calculation for width does not take the border width into account. 宽度的默认计算不考虑边框宽度。 By adding the following CSS you can have your width calculation including the borders. 通过添加以下CSS,您可以进行宽度计算,包括边框。

    .boxStyle {
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
    }

Modify your HTML to refer to this newly created class 修改HTML以引用此新创建的类

        <div id="container">
            <div id="column1" class="boxStyle">
                Some Content for the first column.
            </div>
            <div id="column2" class="boxStyle">
                Some Content for the second column.
            </div>
            <div id="column3" class="boxStyle">
                Some Content for the third column.
            </div>
        </div>

I think it is happening beecause your div widths sum upto 100 %, which is excluding the small but still existant widths of the borders. 我认为它正在发生,因为你的div宽度总和达到100%,这排除了边界的小但仍然存在的宽度。 You can reduce the width further by 1% to accomodate for the border width. 您可以将宽度进一步减小1%以适应边框宽度。

Check this 检查一下

You can also use a display type of inline-block, this gets around some of the quirks of floated items such as having to clear them. 您还可以使用内联块的显示类型,这可以解决一些浮动项目的怪癖,例如必须清除它们。

One thing to note is you need to remove any white-space between the divs. 需要注意的一点是,您需要删除div之间的任何空白区域。 You can also change the vertical-alignment for more control. 您还可以更改垂直对齐以获得更多控制。

<div>....</div><div>
....
</div><div>
....
</div>

.

#container{
width:100%;
}
#column1,#column2,#column3{
display: inline-block;
vertical-align: top;
width:33.3%;
}

A link with more is here: http://www.vanseodesign.com/css/inline-blocks/ 这里有更多链接: http//www.vanseodesign.com/css/inline-blocks/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM