Height and width of image won't change in CSS - html

Trying to alter an image to display alongside another div containing text and have been at it for hours to no avail. The image is supposed to show in line with the other div but refuses to do so:
<div id="leftimg">
<img src ="SLL/student.jpg"/>
</div>
First attempt:
#leftimg {
max-width: 50%;
height: inherit;
left: 0px;
right: 0px;
}
Second attempt:
#leftimg {
max-width: 100%;
height: auto;
left: 0px;
right: 0px;
}
Third attempt:
#leftimg {
width: 500px;
height: 500px;
}

It looks like you're selecting the div element in your CSS, instead of the image. If you'd like to apply those rules to the image inside the div you'll need to follow the div's ID with img like this:
#leftimg img{
max-width: 50%;
height: inherit;
left: 0px;
right: 0px;
. . .
}
Here's a full example:
#leftimg img{
max-width: 50%;
height: inherit;
left: 0px;
right: 0px;
/* Added to make the text wrap around the image
feel free to ignore if that's not how you want
it to work */
float:left;
padding:10px;
}
/* Added to clear the float used above - if you leave
out my stuff above, then leave this out too */
#leftimg:after{
content:'';
clear:both;
}
<div>
<div id="leftimg">
<img src="https://pixabay.com/static/uploads/photo/2015/09/22/15/02/studying-951818_640.jpg"/>
</div>
<h3>Student Letting</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt turpis in magna imperdiet dapibus. Nullam eu neque vel augue rutrum euismod. Sed egestas purus blandit leo rhoncus, sit amet egestas sapien lobortis. Aliquam placerat nec diam id tincidunt. Phasellus in mollis arcu. Aliquam venenatis, est ac pharetra semper, magna libero euismod sem, ac molestie leo ex sed nunc. In ullamcorper orci in dapibus venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam posuere venenatis finibus. Vestibulum orci metus, auctor eu nisi in, suscipit viverra erat. Vivamus purus magna, porta auctor urna eu, venenatis mollis leo.</p>
<p>Duis justo magna, hendrerit ut tortor eu, ornare viverra mi. Ut ultrices gravida arcu, nec tincidunt nulla vehicula in. Pellentesque varius nulla ligula, quis convallis felis blandit at. Nam sit amet lobortis dui, et imperdiet orci. Donec malesuada enim nec tellus auctor accumsan. Nam vehicula felis nec dolor facilisis, vel dapibus dui scelerisque. Donec quis nunc venenatis, laoreet est ac, condimentum arcu. Quisque ut luctus felis. Nulla commodo auctor risus a ullamcorper. Curabitur bibendum tincidunt ante a porta. Ut ut orci ut nulla tempor ornare.</p>
</div>
But if you want to have multiple images inserted into a page with this style you really should use a class instead of an ID, like this:
.leftimg img{ /* Notice how we use the class selector instead */
max-width: 50%;
height: inherit;
left: 0px;
right: 0px;
/* Added to make the text wrap around the image
feel free to ignore if that's not how you want
it to work */
float:left;
padding:10px;
}
/* Added to clear the float used above - if you leave
out my stuff above, then leave this out too */
.leftimg:after{ /* And again here we use the class selector instead */
content:'';
clear:both;
}
<div>
<div class="leftimg"> <!-- Notice id is changed to class -->
<img src="https://pixabay.com/static/uploads/photo/2015/09/22/15/02/studying-951818_640.jpg"/>
</div>
<h3>Student Letting</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tincidunt turpis in magna imperdiet dapibus. Nullam eu neque vel augue rutrum euismod. Sed egestas purus blandit leo rhoncus, sit amet egestas sapien lobortis. Aliquam placerat nec diam id tincidunt. Phasellus in mollis arcu. Aliquam venenatis, est ac pharetra semper, magna libero euismod sem, ac molestie leo ex sed nunc. In ullamcorper orci in dapibus venenatis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam posuere venenatis finibus. Vestibulum orci metus, auctor eu nisi in, suscipit viverra erat. Vivamus purus magna, porta auctor urna eu, venenatis mollis leo.</p>
<p>Duis justo magna, hendrerit ut tortor eu, ornare viverra mi. Ut ultrices gravida arcu, nec tincidunt nulla vehicula in. Pellentesque varius nulla ligula, quis convallis felis blandit at. Nam sit amet lobortis dui, et imperdiet orci. Donec malesuada enim nec tellus auctor accumsan. Nam vehicula felis nec dolor facilisis, vel dapibus dui scelerisque. Donec quis nunc venenatis, laoreet est ac, condimentum arcu. Quisque ut luctus felis. Nulla commodo auctor risus a ullamcorper. Curabitur bibendum tincidunt ante a porta. Ut ut orci ut nulla tempor ornare.</p>
</div>
Doing it with a CSS class would let you have several images on the same page using the same styling, without having to repeat your code. If you're only going to have one image it may be more beneficial to leave it as an ID though. It just depends on how you're going to be using this.

Give the image element an id and set the width/heigth of it:
HMTL:
<img id="img" src ="SLL/student.jpg"/>
And in your CSS File
#img{
width: 500px;
height: 500px;
}
Or set a background to the div
#leftimg {
background-image: url("SLL/student.jpg");
}

You can do it like this:
#leftimg img {
width: 500px;
height: 500px;
}

Try this
#leftimg img {
width: 500px;
height: 400px
}
If you want to change dimensions of your image, change to image itself, not the to image wrapper

try
img{
width:100%;
display: table-cell; /* to give the img full height */
}

Related

Show scrollbar in an absolutely-positioned modal window

I've been trying to style an absolutely-positioned, reactive modal window that can pop up with a potentially large amount of content.
However, I can't seem to get the content part of the modal window to become vertically scroll-able. I've played around with all sorts of div layouts and overflow CSS settings, but can't figure out a way to get the result I need.
Specifically, I need ONLY the "modal-content" div of the modal window to be vertically scroll-able, and for the scrollbar NOT to extend up into the "modal-head" div. The modal-content div should also take up all available vertical space, while modal-head only takes up however much space is necessary for the title and button.
JSFiddle:
https://jsfiddle.net/xe7p5uzv/12/
HTML:
<div class="modal">
<div class="modal-head">
<h1>Modal Title</h1>
<button>Exit Modal Window</button>
</div>
<div class="modal-content">
Modal content here. Dapibus sagittis adipiscing at facilisis augue amet eleifend ipsum netus facilisi ullamcorper ligula tristique facilisi. Lacinia vestibulum a suspendisse a lorem mi vel erat condimentum consectetur enim elementum vehicula a porttitor lacus adipiscing sit potenti elementum adipiscing iaculis a vulputate at. Orci ullamcorper purus id sociis nibh mi sodales parturient enim a iaculis ridiculus a elementum consectetur primis scelerisque fusce vestibulum. Dictum dictumst tristique enim scelerisque libero consequat ornare nisl et ligula dignissim lorem vehicula nunc parturient. Praesent consequat nisi consectetur tempus et cras vestibulum a quisque nulla ullamcorper a suspendisse augue a suspendisse. Himenaeos mi ultricies mollis a vestibulum leo elit montes ad lobortis a malesuada leo eleifend. <br/><br/>
Suspendisse pretium scelerisque parturient nulla pharetra facilisi suspendisse orci sodales venenatis ipsum proin aenean nunc curabitur posuere curabitur netus dolor sociosqu lobortis pharetra adipiscing conubia. Mus sapien est leo cubilia parturient nunc lectus duis erat cubilia scelerisque praesent vulputate nam sodales eros congue condimentum ad a. Parturient consequat hac ad nisi natoque interdum eu convallis mi dignissim eu elementum tempor euismod congue sem ut adipiscing quis vestibulum a vitae ullamcorper tincidunt turpis parturient tellus suspendisse. Duis et mus nascetur parturient conubia in suscipit a dui malesuada nisi scelerisque sem mus vestibulum morbi. Commodo a elit porttitor a metus a mattis scelerisque porttitor ut tempus eros accumsan quis condimentum. Per consectetur etiam habitant enim ad massa ut condimentum urna iaculis conubia nisi et orci fames adipiscing lacinia in gravida dapibus dui. <br/>
</div>
</div>
<div>
Regular page content here. Malesuada ac nam curabitur ullamcorper dictumst varius neque a curae est a sed odio in eu ullamcorper aliquet faucibus dis turpis eros in laoreet malesuada sit non vitae. Dis orci iaculis mauris penatibus a fringilla in dis diam habitasse pharetra scelerisque vehicula netus. Eu non nascetur enim litora sem ad suscipit vel enim ad non consequat adipiscing ultrices senectus a a sodales tellus pretium. A fermentum ullamcorper a proin vestibulum suspendisse sed a purus a vestibulum a nostra condimentum consectetur. Fames at at nam a ultrices parturient adipiscing mus pretium consequat ornare ultrices ullamcorper condimentum vestibulum vestibulum a augue vestibulum sem urna laoreet fringilla inceptos.
</div>
CSS:
html {
font-size: 24px;
}
body {
margin: 0px;
padding: 12px;
}
.modal-bg {
z-index: 2;
width: 100vw;
height: 100vh;
background: rgba(0,0,0,0.8);
}
.modal {
z-index: 3;
position: absolute;
top: 48px;
right: 48px;
bottom: 48px;
left: 48px;
border: 4px solid red;
background-color: white;
overflow: hidden;
display: flex;
flex-wrap: wrap;
}
.modal-head {
background-color: grey;
width: 100%;
padding: 12px;
display: flex;
justify-content: space-between;
}
.modal-content {
width: 100%;
padding: 12px;
overflow-y: scroll;
}
Any ideas on how to accomplish this?
html {
font-size: 24px;
}
body {
margin: 0px;
padding: 12px;
}
h1{font-size: 14px}
.modal-bg {
z-index: 2;
width: 100vw;
height: 100vh;
background: rgba(0,0,0,0.8);
}
.modal {
z-index: 3;
position: absolute;
top: 48px;
right: 48px;
bottom: 48px;
left: 48px;
border: 4px solid red;
background-color: white;
display: flex;
flex-wrap: wrap;
overflow: hidden
}
.modal-head {
background-color: grey;
width: 100%;
padding: 12px;
display: flex;
justify-content: space-between;
}
.modal-content {
width: 100%;
padding: 12px;
overflow-y: scroll;
height: 100px
}
<div class="modal">
<div class="modal-head">
<h1>Modal Title</h1>
<button>Exit Modal Window</button>
</div>
<div class="modal-content">
Modal content here. Dapibus sagittis adipiscing at facilisis augue amet eleifend ipsum netus facilisi ullamcorper ligula tristique facilisi. Lacinia vestibulum a suspendisse a lorem mi vel erat condimentum consectetur enim elementum vehicula a porttitor lacus adipiscing sit potenti elementum adipiscing iaculis a vulputate at. Orci ullamcorper purus id sociis nibh mi sodales parturient enim a iaculis ridiculus a elementum consectetur primis scelerisque fusce vestibulum. Dictum dictumst tristique enim scelerisque libero consequat ornare nisl et ligula dignissim lorem vehicula nunc parturient. Praesent consequat nisi consectetur tempus et cras vestibulum a quisque nulla ullamcorper a suspendisse augue a suspendisse. Himenaeos mi ultricies mollis a vestibulum leo elit montes ad lobortis a malesuada leo eleifend. <br/><br/>
Suspendisse pretium scelerisque parturient nulla pharetra facilisi suspendisse orci sodales venenatis ipsum proin aenean nunc curabitur posuere curabitur netus dolor sociosqu lobortis pharetra adipiscing conubia. Mus sapien est leo cubilia parturient nunc lectus duis erat cubilia scelerisque praesent vulputate nam sodales eros congue condimentum ad a. Parturient consequat hac ad nisi natoque interdum eu convallis mi dignissim eu elementum tempor euismod congue sem ut adipiscing quis vestibulum a vitae ullamcorper tincidunt turpis parturient tellus suspendisse. Duis et mus nascetur parturient conubia in suscipit a dui malesuada nisi scelerisque sem mus vestibulum morbi. Commodo a elit porttitor a metus a mattis scelerisque porttitor ut tempus eros accumsan quis condimentum. Per consectetur etiam habitant enim ad massa ut condimentum urna iaculis conubia nisi et orci fames adipiscing lacinia in gravida dapibus dui. <br/>
</div>
</div>

position sticky is not working after setting float left of other elements

header position sticky is not working after adding float:left on the other element. The position sticky is working if I remove the float:left from main>div. I searched it on google but I didn't find any solution for this. Here is the code
<!doctype html>
<html lang="en">
<head>
<style>
.header {
height: 100px;
position: sticky;
top: 0;
width: 100%;
background-color: pink;
}
main>div {
float: left;
/*If I don't use it, the sticky header works*/
height: 1500px
}
.first {
background: linear-gradient(to top, red, yellow);
width: 300px;
top: 0;
}
.second {
background: linear-gradient(to top, khaki, gray);
width: calc(100% - 600px);
}
.third {
background: linear-gradient(to top, tomato, green);
width: 300px;
}
</style>
</head>
<body>
<header class="header">
sticky header
</header>
<main>
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
</main>
</body>
</html>
Check the same code on Jsfiddle https://jsfiddle.net/habibulislam6862/53yv1rzw/2/
if you start a "float" you also have to clear it
try adding below line after
<div style="clear:both;"></div>
So final code will be as below; Feel free to externalize style into a class
<header class="header">
sticky header
</header>
<main>
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
</main>
<div style="clear:both;"></div>
you can also use a sudo element (like "after" in css) to do the same https://www.w3schools.com/cssref/sel_after.asp
If this is for a layout, you might want to include the -x-sticky for browser compatibility and have your column in percentages to make them responsive.
Example, run code snippet below:
body{
box-sizing: border-box;
padding: 0;
margin: 0;
}
header {
height: 60px;
width: 100%;
background-color: pink;
position: -webkit-sticky;
position: -ms-sticky;
position: -moz-sticky;
position: -o-sticky;
position: sticky;
top: 0px;
z-index: 1;
}
main {
display: flex;
width: 100%;
height: 1500px;
}
.first {
background: linear-gradient(to top, red, yellow);
min-width: 20%;
}
.second {
background: linear-gradient(to top, khaki, gray);
flex-grow: 1;
}
.third {
background: linear-gradient(to top, tomato, green);
min-width: 20%;
}
<header>
sticky header
</header>
<main>
<div class="first"></div>
<div class="second"><p>Lorem ipsum dolor sit amet consectetur adipiscing elit, vitae tincidunt nascetur donec porttitor aenean et nunc, ut dictum inceptos facilisis commodo cum. Duis magnis parturient sollicitudin diam augue placerat imperdiet neque, euismod cum nostra erat lacus et conubia, facilisi pellentesque molestie risus mus dapibus vel. Malesuada vestibulum habitasse class sodales viverra mauris fermentum tortor massa bibendum augue libero, euismod montes sed dis magna vel leo praesent mattis platea eleifend. Neque commodo maecenas odio curae cubilia potenti habitant congue porttitor, integer libero mattis nisl sed mauris donec litora magnis, nulla dignissim platea hac dui varius tellus tincidunt.</p> <p>Dignissim proin arcu magna vitae id nam volutpat natoque semper sem, aliquet erat aliquam sociosqu scelerisque eget urna mollis sagittis. Posuere arcu sociosqu mi ad lacinia vitae ac nascetur tempor pharetra aptent fringilla, turpis sodales himenaeos malesuada mattis nisl diam sapien quisque cum. Enim dictum etiam mollis egestas et magna blandit dignissim, ullamcorper parturient odio suspendisse curabitur habitasse dui facilisi, laoreet ridiculus est ad vehicula curae nullam.</p> <p>Facilisis odio mauris consequat mattis faucibus aliquam eu semper condimentum, imperdiet natoque magna leo malesuada lacinia posuere placerat tellus, suscipit dapibus pharetra porta eros diam feugiat dictum. Suscipit euismod fermentum interdum bibendum nullam porttitor, pharetra dis mollis vivamus leo elementum commodo, facilisi rhoncus aptent ligula maecenas. Sodales pellentesque purus parturient mollis mauris tellus id vehicula, velit ac quam sociosqu molestie sollicitudin neque eleifend, mus porttitor aenean penatibus libero fringilla sagittis.</p> <p>Phasellus ornare eros per nam sollicitudin taciti himenaeos, senectus auctor fusce varius magna hendrerit. Urna proin lacus conubia tortor venenatis mauris nec facilisi, fringilla arcu non accumsan pellentesque neque ut dictum euismod, curae tempor eu felis habitasse mi dui. Viverra vehicula ultrices etiam maecenas fusce pulvinar dis sem litora, luctus molestie suscipit tristique imperdiet gravida pretium augue, vel velit nibh hac mus nam consequat eros.</p> <p>Metus feugiat nisl felis fames condimentum facilisi posuere tempus ultricies scelerisque porttitor aptent, justo tempor magnis ultrices phasellus cras nascetur interdum augue aenean iaculis. Lacinia diam lectus lacus facilisis nisl accumsan magna curae nullam placerat bibendum dictum, vehicula dui integer non viverra iaculis interdum vitae at suscipit egestas. Ac aptent fermentum netus eros vulputate phasellus iaculis, cum inceptos velit suspendisse morbi viverra, ante fringilla faucibus donec placerat nullam. Aliquam diam integer vivamus ligula nam cras cursus tristique libero, mattis nisi vestibulum litora enim suspendisse inceptos fames facilisi, erat penatibus ridiculus taciti duis bibendum tortor ornare.</p> <p>Lectus dui sagittis et nascetur nec hendrerit convallis, dapibus curabitur fermentum varius scelerisque nullam platea, metus elementum mattis id semper dignissim. Ridiculus habitasse at sociosqu gravida dui metus velit aptent praesent, dapibus purus egestas et diam nisi pulvinar porttitor, ullamcorper hac integer cubilia sagittis lobortis justo tristique. Penatibus diam convallis velit sapien, ornare nascetur morbi laoreet vulputate, vitae lectus potenti.</p> <p>Egestas nostra mus montes suscipit morbi mattis vestibulum, sapien penatibus laoreet luctus eu feugiat. Integer a fringilla aenean quisque diam nostra, nisl volutpat commodo augue gravida massa, praesent elementum pulvinar curabitur proin.</p></div>
<div class="third"></div>
</main>

Set scrollbar on element to avoid global scrollbar

I have a single page application, and don't want to have a global scrollbar on the page. Instead of that, I want to have a scrollbar on a specific element, like this:
In other words, I want element 3 to take all the available place, and if its too big, display a scrollbar on this element.
The solution I found is to set a max-height on element 3, computed in javascript as follows : window.height - element1.height - element2.height - element4.height.
The problem is that this becomes complex when the page contains a lot of elements.
Is there a way to do this in pure CSS?
Flexbox can do this easily. Need to tell the overall layout to stick to a certain height, achieved here with height: 100vh on the body. Then setting with the flex-shrink: 1 on the div you want to scroll will allow it to collapse and scroll.
body {
display: flex;
flex-direction: column;
margin: 0;
height: 100vh;
}
.element {
flex-shrink: 0;
}
.element1 {
background: red;
height: 10vh;
}
.element2 {
background: blue;
height: 10vh;
}
.element3 {
background: yellow;
flex-shrink: 1; /* this one must shrink to allow an overflow to occur */
overflow-y: scroll; /* scroll on overflow */
}
.element4 {
background: green;
height: 20vh;
}
<body>
<div class="element element1">ELEMENT 1</div>
<div class="element element2">ELEMENT 2</div>
<div class="element element3">
ELEMENT 3
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris porttitor quis ipsum ac vestibulum. Integer porttitor ornare dui id accumsan. Ut viverra diam ac nibh luctus, sit amet lobortis diam lobortis. Donec aliquam dolor nec eleifend ultricies. Donec commodo, lacus et bibendum scelerisque, dui libero condimentum ante, iaculis consectetur nisl velit ut ligula. Maecenas nec mattis eros. Donec cursus augue eu erat pulvinar, a tempus justo rhoncus.</p>
<p>Aliquam id vestibulum elit, sit amet facilisis ex. Nulla pellentesque laoreet augue at fringilla. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec imperdiet rhoncus augue quis condimentum. Donec sed neque mi. Maecenas eget sagittis dui. Morbi a finibus leo. Nam id laoreet dui. Pellentesque lectus lorem, ullamcorper vitae convallis vel, finibus ut lacus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam venenatis elit vel metus cursus malesuada nec vel velit. Donec ac placerat ipsum, aliquet gravida tortor. Nulla lobortis commodo pharetra. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;</p>
<p>Pellentesque sed neque vitae risus iaculis commodo. Integer vel posuere tortor. Mauris finibus ornare velit ut bibendum. Nunc a fermentum leo, sit amet sagittis libero. Sed rutrum neque eu turpis scelerisque malesuada. Sed accumsan, massa vitae pharetra eleifend, arcu dui dapibus enim, sed pellentesque quam sem eget augue. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</div>
<div class="element element4">ELEMENT 4</div>
</body>

Positioning image partly off of the bottom of the page

I have an image I'm including in my page's footer. It is a small logo (using a placeholder iamge now). I'd like it to be halfway off of the bottom of the page so when you hover your mouse it peeks its head up all cute like. But I'm unable to style it to have it half off the bottom of the page, instead the full image is always visible, and all of the other contents on the webpage appear to be moving up and down when I hover instead. Hard to make out but this is what it looks like to go from having the mouse hovered, to not hovered:
1
2
Right now the styling on it is only:
position: relative; top:75px; left:2%
Is this what you need?
body{
padding: 0;
margin: 0;
}
.content{
width: 100vw;
max-width: 100%;
background: #4527a0;
height: auto;
position: relative;
text-align: center;
}
.inner_content{
max-width: 960px;
text-align: left;
display: inline-block;
height: auto;
color: white;
line-height: 16px;
}
.imagecontent{
position: absolute;
display: block;
z-index: 100;
margin: 0;
padding: 0;
left: 1%;
bottom:0%;
width:120px;
height: 170px;
background: #cddc39;
transform:translateY(85px);
transition:all 380ms;
margin-top: -170px;
}
.imagecontent:hover{
transform:translateY(0px);
}
footer{
width: 100%;
display: inline-block;
vertical-align: top;
background-color: #afb42b;
height: 200px;
position:relative;
overflow: hidden;
}
<div class="content">
<div class="inner_content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nulla magna, ullamcorper eu metus quis, consequat facilisis nisi. Nullam rhoncus purus sed orci fermentum, et dictum dui consectetur. Duis imperdiet ultricies scelerisque. Aliquam erat volutpat. Praesent congue ex vel pulvinar porta. Fusce rutrum ut odio vitae placerat. Fusce lobortis nec tortor et egestas. Phasellus lorem ligula, finibus ut est eget, interdum interdum ipsum. Vestibulum sed facilisis ipsum, sed lacinia neque.
Suspendisse aliquam magna mauris, in tempus leo consequat in. Morbi blandit turpis nec enim vulputate elementum. Cras magna libero, sodales vitae odio quis, pretium tempus quam. Quisque at purus sed felis viverra scelerisque et sollicitudin turpis. Sed vitae arcu eu massa efficitur blandit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc sed erat faucibus, lacinia tortor quis, rhoncus odio. Proin laoreet justo ac magna blandit, id sollicitudin orci pellentesque. Curabitur ac augue eu nulla lobortis tincidunt. Praesent sed sollicitudin orci. In feugiat, ligula posuere commodo maximus, orci nibh elementum ante, ullamcorper consequat diam justo et risus. Aliquam vitae ultrices leo, sed ultrices enim. Morbi quis aliquam est. Morbi in arcu nisl. Curabitur volutpat aliquam eros a tristique.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam nec ex arcu. Donec sit amet sodales dolor, vitae porttitor nibh. Phasellus mauris tellus, bibendum non scelerisque et, ultrices sed nunc. Morbi tempor neque a massa feugiat, non tristique urna feugiat. Sed at metus hendrerit, feugiat augue eu, pretium urna. Suspendisse ut luctus ex. Aliquam dapibus nisl quis mi porta cursus. Nam placerat lacus in eros auctor pharetra. Phasellus at pulvinar eros, viverra ullamcorper erat. Nullam ac quam erat. Vivamus neque dolor, pulvinar sed lacus id, bibendum varius mauris. Donec ornare dolor sagittis, lobortis erat in, ullamcorper sapien. Nam pellentesque consequat ante eu sodales. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam elit metus, dictum quis lectus et, hendrerit hendrerit felis.
Aliquam congue tortor quis enim porttitor, venenatis condimentum enim faucibus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum eget facilisis ipsum, ut imperdiet metus. Praesent ornare lacinia eros, ut semper eros porttitor nec. Aenean condimentum egestas nisi ac placerat. Integer vulputate ultrices egestas. Donec maximus quam arcu, sed lobortis tellus consectetur id. Mauris accumsan libero eu diam interdum condimentum. Mauris cursus ligula in rutrum vestibulum. Donec sed varius eros, ut convallis dolor. Sed arcu sem, iaculis eleifend nunc sed, tincidunt hendrerit elit. Nullam sed imperdiet arcu. Nunc enim ante, pretium non eros id, porttitor vulputate sem. Nullam nec scelerisque sapien, id congue sapien. Ut pulvinar ac felis vitae lobortis. Aenean bibendum vulputate aliquam.
<footer>
<div class="imagecontent"> </div>
</footer>
</div>
</div>

My body background color disappears when scrolling

I hope someone can help. I've set my body height property to 100% which is fine when all the content is on the screen at one time. However when i need to scroll (when minimizing the window) the body color disappears, leaving just the color i set for the HTML background.
Does anybody know a solution?
html {
background-color: #07ade0;
}
body {
background-color: #7968ae;
width: 900px;
margin-left: auto;
margin-right: auto;
font: 20px verdana, "sans serif", tahoma;
}
If your body is set to height: 100%, then it will be 100% of the window, which is not ideal since the background on longer pages will get cut off, as you mentioned. Take off the height property and you should be set.
You can also set height: 100% on both html, body and then create a container within your body. Then move your html styles to body, and your body styles to the new container.
This is preferred, since it is not generally considered best practice to set a pixel width on your body element.
HTML
<body>
<div id="container">Your well-endowed content goes here.</div>
</body>
CSS
html, body {
height: 100%;
}
body {
background: #07ade0;
}
#container {
background: #7968ae;
width: 900px;
margin-left: auto;
margin-right: auto;
font: 20px verdana, "sans serif", tahoma;
overflow: hidden;
}
See DEMO.
Try changing height to min-height on your body element. This will make the body element to be 100% is the content is too short to fill the whole thing, and grow when the content is larger than the browser.
The accepted answer does not solve the issue when there is no content on the page then the column will not be visible at all.
The solution that finally worked is introduction of a wrapper and adding display: table;
My solution not only covers the column with background color when there IS a content, but also when there is none.
http://jsfiddle.net/h83gtmbc/6/
html, body {
height: 100%;
}
body {
background: #07ade0;
padding: 0;
margin: 0;
}
#wrapper {
height: 100%;
}
#container {
background: #7968ae;
width: 900px;
margin-left: auto;
margin-right: auto;
font: 20px verdana, "sans serif", tahoma;
overflow: hidden;
height: 100%;
display: table;
}
<div id="wrapper">
<div id="container">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec aliquam malesuada lectus in ornare. Nam et turpis magna, eget hendrerit nisi. Sed tincidunt felis pulvinar neque hendrerit eu sollicitudin nulla iaculis. Praesent convallis mattis magna, et tempor sapien euismod molestie. Praesent metus nisl, varius in vulputate vel, vestibulum at eros. In hac habitasse platea dictumst. Vivamus vitae turpis lectus. Praesent at tortor sit amet est lacinia porta. Duis sit amet nunc sem. Nam vel sapien a ligula vulputate sollicitudin sed at eros. Nam non urna felis. Ut quis euismod ligula. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nullam felis lectus, vestibulum et fringilla in, elementum ut libero. Integer rutrum nibh a nulla pulvinar nec fermentum justo dapibus.
Integer ut massa ut diam accumsan pulvinar vitae ut metus. Nullam consectetur porttitor nunc, ac malesuada erat rhoncus a. Morbi laoreet vehicula lacinia. Aliquam pellentesque lacus non tellus fringilla at condimentum est condimentum. Sed consequat venenatis dui id egestas. Aliquam suscipit cursus odio non dictum. Mauris ipsum sapien, luctus quis pretium ac, suscipit sit amet neque. Mauris iaculis rutrum dui in lobortis.
Donec sem enim, tempor non cursus at, aliquam pretium ligula. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis in suscipit neque. Vivamus ac augue pulvinar augue condimentum iaculis. Quisque vel augue dolor. Mauris sollicitudin porttitor tristique. Duis consectetur volutpat egestas. Donec quis tortor justo, ac accumsan ligula. Morbi sit amet magna diam. Mauris lectus ante, cursus nec bibendum ac, mattis ultricies nulla. Aliquam dui odio, elementum quis faucibus ac, tristique vel felis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Pellentesque velit velit, dapibus imperdiet ullamcorper in, dapibus sed libero. Cras dapibus, dui in tincidunt feugiat, lacus tellus suscipit urna, nec fermentum ipsum massa eu quam. Sed nisl quam, dictum eget tempus id, ullamcorper quis libero. Suspendisse rutrum pretium tellus ac semper. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque imperdiet dui quis dui euismod aliquet. Etiam sit amet semper dolor. Donec et mattis tellus. Proin ac mi risus. Aenean sit amet nunc scelerisque neque egestas adipiscing non eu diam.
Quisque feugiat scelerisque commodo. Sed tellus nulla, fermentum a rutrum ut, vulputate et turpis. Proin at libero quis metus pellentesque dapibus. Proin nec pretium orci. Pellentesque bibendum mollis lacus vel faucibus. Integer malesuada, dolor quis iaculis laoreet, velit mi mattis turpis, vestibulum lacinia augue felis ac erat. Etiam tristique turpis sit amet nibh adipiscing vel bibendum metus vulputate. Integer mattis nulla metus, vitae viverra nisl.</div>
</div>
see that when you remove the contents - the column still stretching full-height