[英]Background img not showing up
我正在尝试使背景标题图像具有响应性。 我需要将其设置为视口高度或图像高度的100%,以较小者为准。
一个示例是类似于https://brittanychiang.com/v1/的标题横幅
div大小看起来正确,但是图像似乎没有显示出来吗?
在这里创建了一个jsfiddle: https ://jsfiddle.net/pnnxm1yf/2/
header { height: 100vh; max-height: 850px; } #header-banner { color: #fff; background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)),url(https://unsplash.com/?photo=gzH1qxPLXtA) center center no-repeat; background-size: cover; position: relative; }
<p>Why is my image not showing up?</p> <header> <section id="header-banner"> </section> </header> <p>content after image</p>
增加height: 100%
#header-banner
height: 100%
。 高度为0 atm。
您需要将height属性添加到具有背景图像的同一元素上。
#header-banner {
height: 100vh;
max-height: 850px;
color: #fff;
background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)),url(https://unsplash.com/?photo=gzH1qxPLXtA) center center no-repeat;
background-size: cover;
position: relative;
}
为标头横幅增加高度可以解决此问题。 另外,请正确输入图片网址。
#header-banner {
color: #fff;
/* background: #ffffff url(img_tree.png) center center no-repeat; */
background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)),url(https://unsplash.com/?photo=gzH1qxPLXtA) center center no-repeat;
background-size: cover;
/* background-color: red; */
position: relative;
height: 100%;
width: 100%;
}
您没有正确添加img网址,如果您解决了它,则将正确获得输出
<!DOCTYPE html> <html> <head> <style> #borderimg { border: 10px solid transparent; padding: 15px; -webkit-border-image: url(border.png) 30 round; /* Safari 3.1-5 */ -o-border-image: url(border.png) 30 round; /* Opera 11-12.1 */ border-image: url(border.png) 30 round; } </style> <p id="borderimg">Here, the middle sections of the image are repeated to create the border.</p> </body> </html>
#header-banner {
height: 100%;
color: #fff;
background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url('https://images.unsplash.com/photo-1502582877126-512f3c5b0a64?dpr=1&auto=format&fit=crop&w=1500&h=1001&q=80&cs=tinysrgb&crop=') center center no-repeat;
background-size: cover;
position: relative;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.