html - 在 DIV 内的 DIV 元素之间创建半个边框

标签 html css

我正在尝试在 CSS 的帮助下使用 ::after 在 DIV 元素中包含的 DIV 元素之间创建半边框。不幸的是,这只会在包含 DIV 元素的外部呈现边框。我将不胜感激。

这是我的代码:

HTML:

<div class="menu">
    <div class="subDiv1">Foo</div>
    <div class="subDiv2">Bar</div>
    <div class="subDiv3">Baz</div>
</div>

CSS:

.menu {
    position: relative;
    display: inline-block;
    float: left;
    padding: 0 10px;
    margin-left:auto;
    margin-right:auto;
    width: 75%;
    height: 150px;
    position: relative;
    margin-top: 2%;
    border-width: 1px;
    border-style: thin solid;
    border-color: #008040;
    overflow: hidden;
    box-shadow: 0 0 10px 1px #7e8083;

}
.subDiv1 {
    width: 33%;
    height: 150px;
    background-color: #fff;
    float: left;
    color:  #7e8083;
}
.subDiv1::after {
    content:""; 
    background: black; 
    position: absolute; 
    bottom: 25%; 
    right: 0; 
    height: 50%; 
    width: 1px;
}

.subDiv2 {
    width: 33%;
    height: 150px;
    background-color: #fff;
    float: left;
    color:  #7e8083;
}
.subDiv2::after {
    content:""; 
    background: black; 
    position: absolute; 
    bottom: 25%; 
    right: 0; 
    height: 50%; 
    width: 1px;
} 

.subDiv3 {
    width: 33%;
    height: 150px;
    background-color: #fff;
    float: left;
    color:  #7e8083;
}

https://jsfiddle.net/2yGQD/1727/

最佳答案

添加position:relative于你的分割

.subDiv1 {
position:relative;
width: 20%;
height: 150px;
background-color: #fff;
float: left;
color:  #7e8083;
}

关于html - 在 DIV 内的 DIV 元素之间创建半个边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53539961/

相关文章:

html - 带有本地 HTML 文件的 UIWebView 不显示图像

html - 如何在Bootstrap 3中水平对齐标签并选择标签?

css - DIV 中的中心无序列表

javascript - 一键隐藏和显示多个div

HTML/CSS : Create a div that always fills the entire page. .. 然后里面有一个可调整大小的 div?

javascript - 自定义光标在 Windows 操作系统上像素化

javascript - 尝试动态创建删除按钮并在javascript中调用删除功能

javascript - Bootstrap v2.3.2 电子商务结帐页面中的奇怪对齐

css - 子菜单不适用于 IE 7

html - 如何阻止我的主体在 HTML/CSS 中与我的导航栏和横幅重叠