css - 如何设置没有间隔的div?

标签 css html css-position

我想设置一个像这样的 div 结构(顶部有一个 div,下面有两个 div)但我不想使用任何表格。此外,div 之间不能有任何间距,如果可能的话,我希望折叠边框。

 _________
|         |
|_________|
|    |    |
|____|____| 

这似乎行不通。

<div></div>
<br/>
<div></div><div></div>

有人知道怎么做吗?

谢谢。

最佳答案

这是一个例子 DEMO .

div 是 block 级元素。这意味着默认情况下没有任何东西可以坐在它的两侧。您可以使用 float 来更改此行为。或者您可以更改 display 属性。 display: inline-block 效果很好,但在旧版浏览器中不受支持。下面是一个使用 float 的示例。

HTML:

<div class="container">
    <div class="top">top</div>
    <div class="left">left</div>
    <div class="right">right</div>
</div>

CSS:

.container {
    width: 150px;
}
.top {
 border: solid 1px blue;
}
.left {
 border: solid 1px red;   
    width: 73px;
    float:left;
}
.right {
 border: solid 1px green; 
    width: 73px;
    float:right;
}

Documentation for display.
Documentation for float.

关于css - 如何设置没有间隔的div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18147844/

相关文章:

jquery - 使用 jQuery 检测容器溢出?

html - 在屏幕尺寸变化时调整 fontawesome 图标的大小

html - 运行关键帧然后无限次反转它

css - 我在 div 元素位置有问题

Python 找不到 CSS 文件

javascript - 当触发多个点击事件时,Chrome 中的显示/隐藏无法正常工作

javascript - location.href 使目标在悬停在链接上时出现在状态栏中

html - 禁用编辑后,红色拼写检查波浪线仍保留在 chrome 中

html - 为什么位置 :absolute div show up? 不会,即使它位于相对 div 的位置

jquery - 滚动时将表格标题固定到窗口顶部,跳转/跳过一行。 jQuery