假设我有一个包含两列的表。我可以使用以下方法使该表居中:
margin: auto
但假设我希望第二列出现在中间。我怎么做?是否可以?
编辑:
这是我想要实现的目标:
-------------------------------------------------------
| |
| ---------------------------------- |
| |1 column| 2column | |
| |1 column| 2column | |
| |1 column| 2column | |
| |1 column| 2column | |
| |1 column| 2column | |
| ---------------------------------- |
| |
| |
-------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
第二列位于页面/div 的中心。如果这对表格来说是不可能的,如何用 div 做到这一点?
好吧,你可以,尽管我必须警告你这样的布局存在几个问题。使用之前请务必了解它们。
所需的 HTML 是:
<div id="container">
<div id="inside">
<div id="offside">
</div>
<div id="center">
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这里有两层包装纸。margin: 0 auto我们使用外部容器的常用技术将其居中,而内部容器div的负左边距等于偏离中心的宽度div。
#container {
width: 300px;
margin: 0 auto;
}
#container #inside {
margin-left: -100px;
overflow: hidden;
}
#container #inside div {
float: left;
height: 400px;
}
#container #inside #offside {
width: 100px;
background-color: #ddd;
}
#container #inside #center {
width: 300px;
background-color: #f9f9f9;
}
Run Code Online (Sandbox Code Playgroud)
在这里看看: http: //www.jsfiddle.net/DfArr/1/