CSS边框上方和下方但不是全宽

dav*_*rey 4 css styling text-styling blockquote

我正在尝试为我正在处理的网站上的块引用定义全局样式.

目标是设置块引号的样式,使它们看起来与下图相似.我想避免修改DOM结构.

使用伪类我想在元素的上方和下方显示水平平行边框,但这些线应该只是元素本身的一半宽并且水平居中.

blockquote的样机

这是迄今为止我已经得到的,但线条没有正确居中.

blockquote {
    margin: 0 auto;
    position: relative;
    text-align: center;
    display: table;
    font-size: 15px;
}

blockquote:before {
    content: '\A';
    height: 1px;
    width: 40%;
    position: absolute;
    background: #000;
    top: -8px;
}

blockquote:after {
    content: '\A';
    height: 1px;
    width: 40%;
    position: absolute;
    background: #000;
    bottom: -8px;
}
Run Code Online (Sandbox Code Playgroud)
<blockquote>
  Neque porro quisquam e porro quisquest qui dolorem ipsum quia dolor sit<br />
 est qui dolorem ipsum quia dolor sit amet rem ipsum quia 
</blockquote>
Run Code Online (Sandbox Code Playgroud)

dfs*_*fsq 10

如果宽度是固定的,您可以使用负边距 - 左到中心元素.在你的情况下margin-left: -20%;:

blockquote { 
    margin: 0 auto;
    position: relative;
    text-align: center;
    display: table;
    font-size: 15px;
}
blockquote:before, blockquote:after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;         /* <-- put left edge in the middle */
    margin-left: -20%; /* <-- shift to the left by half of the width */
    width: 40%;
    height: 1px;
    background: #000;
}
blockquote:after {
    top: inherit;
    bottom: 0;
}
Run Code Online (Sandbox Code Playgroud)
<blockquote>
  Neque porro quisquam e porro quisquest qui dolorem ipsum quia dolor sit<br>
 est qui dolorem ipsum quia dolor sit amet rem ipsum quia 
</blockquote>
Run Code Online (Sandbox Code Playgroud)