How To Fixed / Lock Position Of Background Image & Divs Containing Images
Solution 1:
You need to set the #bg
property of width
and height
the same as the background-image
size.
body, html {
height: 100%;
}
#bg {
background-image: url(http://basicblue.biz/treasure/treasuremap_01.jpg);
height: 1080px;
width: 1080px;
background-position: center;
background-repeat: no-repeat;
background-size: 1080px1080px;
position: relative;
}
#menu {
display: block;
width: 100px;
}
input:checked + .hidable {
display: none;
}
input:not(:checked) + .showable {
display: none;
}
#mark01 {
position: absolute;
top: 240px;
right: 490px;
}
#mark02 {
position: absolute;
top: 480px;
left: 460px;
}
#mark03 {
position: absolute;
bottom: 260px;
right: 490px;
}
<!DOCTYPE html><html><head><metaname="viewport"content="width=device-width, initial-scale=1"><linkrel="stylesheet"href="styles.css"><title>Treasure Map</title></head><body><divid="bg"><divid="menu"><inputtype="checkbox" /> Marker 1
<divclass="showable"><imgid="mark01"src="http://basicblue.biz/treasure/xmark_01.png"alt="X Mark Red"></div><inputtype="checkbox" /> Marker 2
<divclass="showable"><imgid="mark02"src="http://basicblue.biz/treasure/xmark_02.png"alt="X Mark Green"></div><inputtype="checkbox" /> Marker 3
<divclass="showable"><imgid="mark03"src="http://basicblue.biz/treasure/xmark_03.png"alt="X Mark Magenta"></div></div></div></body></html>
Solution 2:
I'm only loading the background image in the HTML in the case that you're pulling the image dynamically via PHP. Otherwise, you can create separate classes with background images in the CSS file.
fixed and cover didn't use to play well together, and you would have to put the height property in an outer container, but I tested this code on Chrome, Firefox, Safari, and Opera, and it works fine.
Solution 3:
I wanted to make a section of a website have a div featuring a background image that had both background-attachment: fixed and background-size: cover, regardless of the image's size. This is a working example of multiple fixed, full-screen background image divs.
Solution 4:
div { width: 100% height: 90vh background-repeat: no-repeat background-position: center center background-size: cover background-attachment: fixed } . End every of the sentence in an hyfin
Solution 5:
Thanks but it won't send I'm trying to find a way out to send in a simple language programming. You can also write this code in the background shorthand then you'd simply add the background image to the div and adjust the height property as necessary.
Apostrophe in between the backgroundimage and and hyfin to end it to get the picture
Post a Comment for "How To Fixed / Lock Position Of Background Image & Divs Containing Images"