使用以下方法创建这样的边框:之前和:在CSS中的伪元素之后?

Sho*_*box 8 css border css3 pseudo-element

目的

我希望能够创造像一个边界这个在CSS中,可能使用伪元素,然后一个背景图像.

码

HTML

<div id="footer"></div>
Run Code Online (Sandbox Code Playgroud)

CSS

#footer {
    background: #4b4b4b;
    color: #868686;
    padding: 0;
    position: relative;
    height: 100px;
    width: 900px;
}

#footer:before {
    content: "";
    display: block;
    width: 220px;
    background-color: #e1e1e1;
    height: 8px;
}
Run Code Online (Sandbox Code Playgroud)

Yog*_*ogu 21

看下面的代码片段,这是你想要的吗?

body {
    background: silver;
    padding: 0 10px;
}

#content:after {
    height: 10px;
    display: block;
    width: 100px;
    background: #808080;
    border-right: 1px white;
    content: '';
}

#footer:before {
    display: block;
    content: '';
    background: silver;
    height: 10px;
    margin-top: -20px;
    margin-left: 101px;
}

#content {
    background: white;
}


#footer {
    padding-top: 10px;
    background: #404040;
}

p {
    padding: 100px;
    text-align: center;
}

#footer p {
    color: white;
}
Run Code Online (Sandbox Code Playgroud)
<body>
    <div id="content"><p>#content</p></div>
    <div id="footer"><p>#footer</p></div>
</body>
Run Code Online (Sandbox Code Playgroud)

的jsfiddle


Vir*_*shi 5

#footer:after
{
   content: "";
    width: 40px;
    height: 3px;
    background-color: #529600;
    left: 0;
    position: relative;
    display: block;
    top: 10px;
}
Run Code Online (Sandbox Code Playgroud)

  • 您能详细说明一下您的答案吗?仅发布代码通常是不够的。 (4认同)