I currently have a dynamic header image that resizes to the size of the browser. (exactly like this: http://www.theadventurists.com/ ) But currently it overlaps my other content. What I actually want is the image to take up the screen and scroll down to see the content.
The website I linked, how do they do this without overlapping content? Is there JS involved? The closest I have gotten to replicating it is having the div below have margin-top 100%. But that is a bad fix due to the margin becoming too large when the browser is certain sizes.
<div id="test_bg">
</div>
<div id="page">
<p>This is the content</p>
</div>
#test_bg{
background-color:blue;
position:absolute;
background-size: cover;
background-repeat: no-repeat;
top: 0;
left: 0;
bottom:0;
right:0;
}
#page{
background-color:red;
margin-top:100%;
}
http://jsfiddle.net/9Trb2/9/ blue being the image, red being content.
You're right on with setting margin-top 100% as not the best way to go about it. There were a couple of issues with your JSFiddle - the background URL was pointing to an imgur page and not the actual JPG, so I changed that. Also, you had the css selector page which instead needed to be #page to correctly target the div.
My approach for solving your issue was to change the #test_bg height to 100% and remove absolute positioning. By taking away absolute positioning, #test_bg becomes part of the document flow and the next div will automatically be positioned right below it, which is what you wanted. The other thing you need to do in order to be able to set that div to 100% height is to also set the body and html height to 100% - otherwise you'd see that setting #test_bg to height=100% wouldn't do anything. Here's the JSFiddle.
#test_bg{
background-image:url(http://i.imgur.com/GgfpgA3.jpg);
background-size: cover;
background-repeat: no-repeat;
height: 100%;
}
html,body{
height: 100%;
}
#page{
height:400px;
width:400px;
background-color:red;
}
Related
I am having trouble scaling a repeating image to the height of the document in html.
I can clearly see how large the html element is using the inspector.
I have set the div's height to 100rem, which should scale it to 100% of the height of the root element (which as far as I understand is the html element).
CSS:
#left-buildings{
left: 0;
float:left;
}
.buildings{
height: 100rem;
position: absolute;
width: 5%;
top: 0;
background-image: url(../media/images/city-side-seamless.png);
background-repeat: repeat-y;
background-size: contain;
}
HTML:
<div class="buildings" id="left-buildings"> </div>
<div class="buildings" id="right-buildings"> </div>
The problem is, it does not scale to the correct size.
screenshot showing that the element is not spanning the height of the page
Try changing the height to 100vh.
rem is the relative to font-size of the root element
I would put the images as an img tag inside the divs, and then you can just style them to 100% height.
I managed to get around the problem but setting the height of the buildings to a measurement in pixels that fits length of the page. This prevents the buildings form scaling when one zooms in on the page. Quite conveniently, it also lets the ends "overflow" and doesn't extend the page height when you zoom. Not too sure why that happens, but I'm not complaining XD.
Ok, I'm trying to design a website that has an image at the top that spans the full width of the browser. And below that I want to put different colored div containers that also span the full width. kinda like this:
http://hayden-demo.squarespace.com/
I've tried background-size:cover but I want different backgrounds for each section of the page. The only thing I've found after many hours of searching is width: 100% but it leaves white borders around my image...
Please help, I'm desperate. This is my current CSS:
.mainimg {
background-image: url(_DSC0656.jpg);
background-repeat: no-repeat;
background-position: center center;
-moz-background-size: cover;
background-size: cover;
width:100% !important;
height: 700px;
margin:0 auto;
display:block;
}
The body element has some margins by default. Unless you remove them, any element that you put inside, no matter it's width (unless it's in position absolute I think) will have some borders. They aren't borders, but the gab in between the end of your element and the side of the body. Try this :
body{
margin: 0;
}
If that doesn't work, then please show us an example of your code on JSBin, Codepen or similar (or even a live version if possible).
did you tried to reset the margin and padding of all element to 0, if not then try following code into your css file.
*{
padding:0;
margin:0;
}
I am very new to HTML/CSS. I am building a website for the Sheriff's office I work for, and am having an issue.
The website has a fixed div on the left side of the page, that includes all of the links. The content is on the right, and is designed to scroll, however I want the left div (links) to always remain the same. I designed the site on a laptop, and so far its working fine on that, however when viewing the homepage on a desktop, the left div doesnt stretch all the way to the bottom.
Here is the link: http://www.mlpropmgt.com/sheriff3/index.html
I used percentages, thinking that would make that left div always stretch to the bottom of the screen, however it didnt seem to work.
Any help would be much appreciated!
from what I gather viewing the code in your webpage you did all the right things, and the leftbar is 100% height, however the image you used as a background is not, css does not stretch the image unless you tell it to do it, you can use
.leftbar{ background-size: cover;}
or use an image that is big enough to account for the extra height in a desktop, keep in mind that Imac's hace 1440px window height
Since you have 2 divs do this
<div id="Main_div">
<div id="left_div">div 1</div>
<div id="Right_div">div 2</div>
</div>
css
#Main_div
{
border:1px solid red;
height:100%;
width:100%;
position:fixed;
}
#left_div
{
border:1px solid black;
height:100%;
width:40%;
float:left;
position:fixed;
}
#Right_div
{
border:1px solid blue;
height:100%;
marigh-left:41%;
float:right; // or its not needed
}
let us know
give height of the div as 100% (height:100%;) then set position:fixed;
it will works fine
Hi righ now your left side it has 100% height so is working the div is streching all the way to the bottom. The problem is the background image. The background image is smaller than a desktop window height so that's why it looks like is not streching all the way to the bottom.
Possible solutions:
Change the background image to a bigger one that just have the "background", and put another two images with the sherif star and the sheriff's logo/name with a absolute position so they will look like background images.
You can add the following to your leftbar div. The problem here is that the image is going to strech and at some point you are not going to be able to see the complete logo/name
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
So the story is this:
I'm making a website in which the homepage content is consisted of a menu and the clients logo.
But the way I've design it, the content needs to be in the center of the browser window... So across the board, because everyone has different screen heights, everyone who views the website either has too much white space under the footer, or part of the content is cut off.
This is the website: http://thinkinternational.co/
So my idea to fix it was this:
I created a buffer zone above the body, as you can see in the code below, but the problem I've discovered with having a percentage as a div height is that the parent div needs to have a specific height in the first place. Unfortunately, I'm not omniscient, and I can't predict every size of screen for every person who views this website, so I can't give it a specific height, otherwise I might as well have just left it as is in the first place.
Also, at the same time, I need the background to shift down with the body. Just to shake things up.
Any solutions for this issue ??
<div id="main">
<div id="TopBuffer"></div>
<div id="body" class="clearfix">
Content Here
</div>
</div>
body {
background:#0b0b0b url(images/Slices/BackgroundHome.jpg) no-repeat center -150px fixed;
-moz-background-size: inherit;
-o-background-size: inherit;
-webkit-background-size: inherit;
background-size: inherit;
height: 100%; }
main { color:#000; font-family:Arial,Geneva,sans-serif; margin:15px 0;height: 100%; }
TopBuffer { width:100%; height:25%; }
Like you said, to make a height with percentage work, you will need the parent to have a specific height.
So height:100% on body will work once you put it on html too.
(I would also remove the margin and padding from html)
html{
margin: 0;
padding: 0;
height: 100%;
}
And to make your background stretch all the way down, you will need make changes in this line of the CSS:
body{
background:#0b0b0b url(images/Slices/BackgroundHome.jpg) no-repeat center -150px fixed;
}
change the center -150px to center center, to center top or to center bottom depending on which you prefer so you can show the whole image on larger resolutions.
First center is the horizontal position of background, and second one is vertical position.
As for centering your content vertically this is a nice article:
Vertical Centering With CSS
If you can use javascript then use window.outerHeight to get the browser height and set the buffer according to that using javascript or jquery
thanks for help, ended up with this
html{
position:relative;
min-width:950px;
height:100%;
background:black url(images/GrassBG.png) repeat-y top center;
font:13px "Lucida Grande",Helvetica,Arial,sans-serif;
}
body.main{
width:950px;
margin:0 auto;
position:relative;
}
is there any way when using a div for a background image- to limit the height to only the content displayed?
im putting the background image in a div because i want it centered via position:relative but the image doesnt show up unless i put a height on the div, and thats not what i want because i dont want to be able to just scroll down to the bottom of the image where theres no content
ive tried putting the background image on the body css but if the browser is less than the width of the image, it just throws it over to the left and you can only see half of it- is there no way to make the background position:relative on the body?
sorry if that doesnt make sense ><
thanks
why can you not use Position:relative; on the body?
You can set your div's height to 100% and set it with no-repeat to keep it from propogating throughout the div. Make sure all of its parent elements contain a 100% height though (all the way up to body). It won't force itself, then, to be a certain height. It will just fill the page.
This is all assuming, of course, that you don't care to interact with what's underneath the div in question.
<style>
body,
#parent {
height: 100%;
}
#the_one_with_the_background {
background: url('background.png') no-repeat top center;
height: 100%;
width: blahpx /* You're still going to have to define a width of some sort */
}
</style>
<body>
<div id="parent">
<div id="the_one_with_the_background">
</div>
</div>
</body>