[英]Extend a centered element to one side
I have a header that is centered but I'd like the bottom border to extend all the way to the left of the screen but preserve the max-width of the header. 我有一个标题居中的标题,但我希望底部边框一直延伸到屏幕的左侧,但保留标题的最大宽度。
Example 1: 范例1:
Screen width is 1400px 屏幕宽度为1400像素
Header width is 1200px (starting at left: 100px, ending at left:1300px) 标头宽度为1200像素(从左侧开始:100像素,从左侧开始:1300像素)
Border width is 1300px (starting at left:0, ending at left:1300px) 边框宽度为1300像素(从左侧的0开始,从左侧的1300像素结束)
Example 2: 范例2:
Screen width is 100px 屏幕宽度为100像素
Header width is 100px 标头宽度为100像素
Border width is 100px 边框宽度为100像素
Code: 码:
<header>
...
</header>
header {
max-width: 1200px;
margin: 0 auto;
border-bottom: 1px solid black;
}
Border will not work, try something like: 边框不起作用,请尝试以下操作:
header {
max-width: 1200px;
margin: 0 auto;
position: relative;
}
header::after {
content: '';
display: block;
position: absolute;
right: 0;
bottom: 0;
height: 1px;
background-color: black;
width: 100vw;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.