html - 将 Div 向上移动 20px - 但保留边框

标签 html css

我有三个<div> s 并想将第二个上移。

目前我正在用 position: relative; top: -20px; 做这件事- 效果很好。

唯一的缺点是:第二个 <div> 之间有一个间隙(20px)第三个<div> (在第二个 div 下)。

所以,我想保留所有三个 div 周围的边框,这样 top: -20px不是第三行的替代品。

我在这里说明了这个:http://jsfiddle.net/w2PGF/1/

我的标记:

<div id="border">
    <div class="firstRow">foo</div>
    <div class="secondRow">bar</div>
    <div class="thirdRow">foobar</div>
</div>​

我的 CSS:

#border {
    border: 5px solid #000;
}
.firstRow {
    background-color: cyan;
    border: 3px solid red;
    height: 50px;
}
.secondRow {
    position: relative;
    top: -20px;
    border: 3px solid yellow;
    background-color: grey;
    height: 50px;
}
.thirdRow {
    background-color: blue;
    border: 3px solid blue;
    height: 50px;
}

提前致谢。

最佳答案

.secondRow { margin-bottom: -20px }

关于html - 将 Div 向上移动 20px - 但保留边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11809099/

相关文章:

javascript - jquery 文件树高亮选中

javascript - 滚动时背景颜色闪烁

javascript - 加载跨域内容时触发事件?

html - 当我为 body 标签使用 100% 宽度时,我如何知道使用了多少像素

html - x-scrollable DIV 中未完全展开的 block 级元素

php - 无法在codeigniter中自定义轮播 Bootstrap css

javascript - Jquery Scroll 从用户在屏幕上的任何地方滚动一个像素

html - Bootstrap - 全屏标题图像后跟背景图像

javascript - Meteor:为模板选择自定义 javascript 和自定义 css

javascript - HTML 嵌入标签覆盖导航栏中的 div 标签