css - 如何在 div 中创建第二个边框

标签 css

我有一个带边框的简单 div:

.box {border: 1px solid black; width: 100%; height: 200px}

<div class="box"></div>

我想添加第二条垂直线,将 div 切成两半,在框的左边缘内 30px:

  30px     remaining width
____________________________
|      |                    |
|      |                    |
|      |                    |
|______|____________________|

有没有办法用 CSS3 做到这一点?我在想一些与伪元素有关的事情,但无法解决我想要的效果。

谢谢

最佳答案

DEMO你可以使用 css pseudo element

.box {border: 1px solid black; width: 100%; height: 200px ;position:relative;}
.box:before{
    position:absolute;
    content:'';
    width:30px;
    height:100%;
    border-right:1px solid black;
    left:0;
    top:0;
}

你可以使用 box-shadowDemo

.box {
border: 1px solid black; 
width: 100%; 
height: 200px ;
position:relative; 
box-shadow:inset 30px 0 0 white, inset 31px 0 0 black
}

关于css - 如何在 div 中创建第二个边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25834377/

相关文章:

javascript - 在jquery中同时滚动两个div

css - 5.2 升级IllegalArgumentException : Unable to highlight file

css - 如何并排设置3个div,以便中间div可以随着表单调整大小而拉伸(stretch)

javascript - CSS3 : Lines of text sliding into page at different times

javascript - 我怎样才能让一个按钮有一个 :active state for 1 second?

jquery - 使用 contenteditable 元素和 iframe 创建编辑器

javascript - 子菜单需要是浏览器窗口的全宽

html - 背景大小 : cover causing background image to partially be hidden

html - Firefox 没有为单选按钮加载 css

javascript - 控制台功能未定义错误?