gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 11:54:18 26 4
gpt4 key购买 nike

我正在尝试为我正在处理的站点上的 block 引用定义全局样式。

目标是设置 block 引号的样式,使它们看起来类似于下图。我想避免修改 DOM 结构。

使用伪类,我想在元素上方和下方显示水平平行边框,但线条的宽度应仅为元素本身的一半,并水平居中。

Mockup of 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;
}
<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>

最佳答案

如果宽度是固定的,你可以使用负的 margin-left 来居中元素。在你的情况下 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;
}
<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>

关于上方和下方的 CSS 边框但不是全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26852877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com