[英]h1 background color won't stretch to image width
Here is my HTML & CSS respectively: 这分别是我的HTML和CSS:
HTML 的HTML
<section class="slider">
<div class="row">
<div class="large-12 column">
<div style="position:relative">
<img src="img/code.jpg" alt="Code Image">
<h1><span>slider title</span></h1>
</div>
</div>
</div>
</section>
CSS 的CSS
h1 {
position: absolute;
width: 100%;
bottom: 0;
left: 0;
right: 0;
}
h1 span {
width: 100%;
color: white;
font-size: 1rem;
letter-spacing: 2px;
background-color: rgba(30, 59, 69, 0.8);
}
And here is a screenshot via Imgur, of what my page looks like currently: 这是通过Imgur截取的屏幕截图,显示了我的页面当前的外观:
I'm trying to set the blue strip behind "slider title" to stretch across the entire width of the image beind. 我正在尝试在“滑块标题”后面设置蓝色条带,以延伸到整个图像宽度。 Am I missing something at all?
我有什么想念的吗? I've tried a few different methods but nothing appears to work :(
我尝试了几种不同的方法,但似乎没有任何效果:(
Spans are by default inline elements, you can either add 'display:block' to the h1 span or make it a div which is by default a block element. 跨距默认是内联元素,您可以将'display:block'添加到h1跨距中,也可以将其设置为div(默认情况下为块元素)。
I would also probably modify the code to make things easier down the road when you want to use an h1 tag someplace else. 当您想在其他地方使用h1标签时,我也可能会修改代码以使事情变得更容易。
HTML: HTML:
<section class="slider">
<div class="row">
<div class="large-12 column">
<div style="position:relative">
<img src="img/code.jpg" alt="Code Image">
<h1 class='slide-title'>slider title</h1>
</div>
</div>
</div>
</section>
CSS: CSS:
.slide-title {
position: absolute;
width: 100%;
bottom: 0;
left: 0;
color: white;
font-size: 1rem;
letter-spacing: 2px;
background-color: rgba(30, 59, 69, 0.8);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.