Html 如何将此div正确地居中放置到其容器中?怎么了?

Html 如何将此div正确地居中放置到其容器中?怎么了?,html,css,layout,xhtml,Html,Css,Layout,Xhtml,我不太喜欢HTML和CSS,我在尝试将div集中到它的容器中时遇到了一些问题,而我已经将div集中到了一个非常旧的legaxy JSP页面中 所以情况是这样的,我有这样的东西: <div class="panel-wrapper"> <div class="panel-content" style="width: 900px"> <div id="table1Container"> // THIS CONTAIN

我不太喜欢HTML和CSS,我在尝试将div集中到它的容器中时遇到了一些问题,而我已经将div集中到了一个非常旧的legaxy JSP页面中

所以情况是这样的,我有这样的东西:

<div class="panel-wrapper">
    <div class="panel-content" style="width: 900px">
        <div id="table1Container">
            // THIS CONTAINS ORRIBLE SHOWED TABLE STRUCTURE
        </div>
    </div>
</div>

这就是我所看到的:

1) 在这里,我在FireBug中选择具有class=“panel wrapper”的外部div,以显示它水平扩展到页面的100%:

2) 在这里,我用FireBug突出显示了相同的页面,内部div具有class=“panel content”,并且我通过内联CSS将固定的宽度设置为900px

因此,正如您从代码和上一个屏幕截图中所看到的,外部(class=“panel wrapper”)似乎扩展到了页面宽度的100%,而更内部的class=“panel content”(我想居中的)具有900px的固定宽度和CSS提供的一些边距(左边距:5%;右边距:5%)

好的,我试着以这种方式改变内联CSS,使其居中:

<div class="panel-content" style="width: 900px; margin-left: 0 !important; margin-right: 0 !important;">

但它不是居中的,而是向左移动(只是没有更多的边距或类似的东西)

这就是我所看到的:

那么,我遗漏了什么呢?我如何才能正确地将具有class=“panel content”的div集中到具有class=“panel wrapper”的div中呢


Tnx

您必须去掉浮动并将文本对齐中心设置为其父对象,请尝试以下操作:

CSS

panel-wrapper {
    overflow: hidden;
    width: 100%;
    display: block;
    text-align: center;
}

.panel-content {
    background: none repeat scroll 0 0 white;
    overflow: hidden;
    position: relative;
    margin: 0 auto;
    display: inline-block;
}

table.standard-table-cls {
    border: 1px solid #76818a;
    border-collapse: collapse;
    color: #76818a;
    font: 11px Verdana,Geneva,Arial,Helvetica,sans-serif;
    margin: 0 !important;
    text-align: center;
    text-decoration: none;
    width: 100%;
}

您必须去除浮动并将文本对齐中心设置为其父对象,请尝试以下操作:

CSS

panel-wrapper {
    overflow: hidden;
    width: 100%;
    display: block;
    text-align: center;
}

.panel-content {
    background: none repeat scroll 0 0 white;
    overflow: hidden;
    position: relative;
    margin: 0 auto;
    display: inline-block;
}

table.standard-table-cls {
    border: 1px solid #76818a;
    border-collapse: collapse;
    color: #76818a;
    font: 11px Verdana,Geneva,Arial,Helvetica,sans-serif;
    margin: 0 !important;
    text-align: center;
    text-decoration: none;
    width: 100%;
}

您必须去除浮动并将文本对齐中心设置为其父对象,请尝试以下操作:

CSS

panel-wrapper {
    overflow: hidden;
    width: 100%;
    display: block;
    text-align: center;
}

.panel-content {
    background: none repeat scroll 0 0 white;
    overflow: hidden;
    position: relative;
    margin: 0 auto;
    display: inline-block;
}

table.standard-table-cls {
    border: 1px solid #76818a;
    border-collapse: collapse;
    color: #76818a;
    font: 11px Verdana,Geneva,Arial,Helvetica,sans-serif;
    margin: 0 !important;
    text-align: center;
    text-decoration: none;
    width: 100%;
}

您必须去除浮动并将文本对齐中心设置为其父对象,请尝试以下操作:

CSS

panel-wrapper {
    overflow: hidden;
    width: 100%;
    display: block;
    text-align: center;
}

.panel-content {
    background: none repeat scroll 0 0 white;
    overflow: hidden;
    position: relative;
    margin: 0 auto;
    display: inline-block;
}

table.standard-table-cls {
    border: 1px solid #76818a;
    border-collapse: collapse;
    color: #76818a;
    font: 11px Verdana,Geneva,Arial,Helvetica,sans-serif;
    margin: 0 !important;
    text-align: center;
    text-decoration: none;
    width: 100%;
}

面板内容
类css更改为

.panel-content {
    background: none repeat scroll 0 0 white;
    margin: 0 auto;
    width: 90%;
}

面板内容
类css更改为

.panel-content {
    background: none repeat scroll 0 0 white;
    margin: 0 auto;
    width: 90%;
}

面板内容
类css更改为

.panel-content {
    background: none repeat scroll 0 0 white;
    margin: 0 auto;
    width: 90%;
}

面板内容
类css更改为

.panel-content {
    background: none repeat scroll 0 0 white;
    margin: 0 auto;
    width: 90%;
}