Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

html - How to contain background image to div

Just working on a little bit of code for a personal project and for some reason the background image(s) keep overlapping my header and other divs. Dropped in a dummy header to show, but the image should obviously be contained within the div and I can't seem to get it right! Would really appreciate any advice on how to keep this contained within.

Also, on a sidenote I'd like the first image showing before hover, but the containing of the image is even more frustrating right now. I've used the below to make the image fit, so perhaps something to do with that?

background-repeat:no-repeat;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
background-position:center;

https://jsfiddle.net/qs5xy967/1/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add 'z-index' to your CSS. Thats a way to define which div to be on top of the other.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...