I'm trying to design a section of HTML/CSS wherein I have a flexbox parent element that is the width and height of the starting viewport with 3 child text boxes.
My goal is to have all 3 elements on the page and visible without needing to scroll.
My goal is to have all 3 text boxes be legible and resize accordingly to the given viewport without getting shoved out.
Looking at the HTML, it seems the content is shoved off the viewport to the right despite trying to keep the width at 100%. Basically, how can I have 3 easily modifiable flexbox that stay legible and within the width and height of the viewport no matter what changes are made to them?
My code:
.intro_header {
display: flex;
width: 100%;
padding: 10% 10% 5% 10%;
background-position: center;
background-repeat: no-repeat;
height: 100vh;
flex-wrap: wrap;
justify-content: space-between;
}
/* Generic flexbox paragraph text div that can be used for one column display regardless of responsiveness */
/*can swap around elements using the order: style */
.oneColumnText {
width: 100%;
text-align: center;
}
<div class="intro_header" style="background-image: foo.jpg">
<div class="oneColumnText">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="oneColumnText">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="oneColumnText">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sodales nulla sed fermentum tempor. Maecenas eget posuere massa. Sed consequat, erat ac tincidunt porttitor, augue sapien feugiat ligula, id ultricies augue tortor id mauris. Duis mattis
felis non libero iaculis, nec varius turpis pharetra. Vivamus convallis nibh ac arcu condimentum porta. Ut tristique in erat quis lobortis. Etiam ut elit in sem placerat dapibus.
</p>
</div>
</div>
https://jsfiddle.net/eg14v3po/1/
Add this to your code:
* { box-sizing: border-box; }
body { margin: 0; }
.intro_header {
display: flex;
padding: 10% 10% 5% 10%;
background-position: center;
background-repeat: no-repeat;
height: 100vh;
flex-wrap: wrap;
justify-content: space-between;
}
.oneColumnText {
width: 100%;
text-align: center;
}
* { box-sizing: border-box; }
body { margin: 0; }
.oneColumnText {
border-bottom: 1px solid lightgray; /* for demo only */
}
<div class="intro_header" style="background-image: foo.jpg">
<div class="oneColumnText">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="oneColumnText">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="oneColumnText">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sodales nulla sed fermentum tempor. Maecenas eget posuere massa. Sed consequat, erat ac tincidunt porttitor, augue sapien feugiat ligula, id ultricies augue tortor id mauris. Duis mattis
felis non libero iaculis, nec varius turpis pharetra. Vivamus convallis nibh ac arcu condimentum porta. Ut tristique in erat quis lobortis. Etiam ut elit in sem placerat dapibus.
</p>
</div>
</div>
With the border-box value of the box-sizing property, the padding you have specified gets factored into the width / height calculations (more details).
With margin: 0 on the body element you are overriding the default margins set by the browser (more details).
Related
This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
CSS Property Border-Color Not Working
(6 answers)
Closed 9 months ago.
I am having some trouble understanding why margin: 1rem is not applying to my footer element. When I modify the size, only the text content in the <p> for the article div and aside element are modified. There is no margin between the footer text and the background color on the top and bottom, only on the left and right. Could anyone tell me what's causing this? Thanks
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style>
body {
background-color: pink;
}
section {
background-color: lightgray;
max-width: 1000px;
box-sizing: border-box;
}
.article {
background-color: lightyellow;
width: 70%;
float: left;
margin: 0;
}
aside {
background-color: lightgreen;
float: right;
float: none;
overflow: hidden;
margin: 0;
}
footer {
clear: both;
background-color: aqua;
display: block;
border: black 10px;
box-sizing: border-box;
}
p {
margin: 1rem;
}
</style>
</head>
<body>
<section>
<div class="article">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ac
eleifend ex, vitae bibendum tortor. Sed rutrum, orci quis venenatis
congue, justo orci volutpat justo, semper vestibulum mauris est mattis
mi. Duis tincidunt enim congue elit egestas, ut ultrices purus
vulputate. Curabitur gravida tellus vel ornare convallis. Nunc
</p>
</div>
<aside>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor
aliquam massa. Pellentesque maximus tortor ac est ultricies, id
sodales ligula vehicula. Fusce dignissim risus ligula, a feugiat augue
</p>
</aside>
<footer>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
malesuada dolor quis ante tempus, eget posuere massa egestas. Integer
feugiat tellus nibh. Vestibulum pellentesque quam eu hendrerit porta.
Suspendisse sagittis eros vitae urna convallis, sit amet venenati
</p>
</footer>
</section>
</body>
</html>
The margin is applied - your problem is just that you have declared a 10px border without declaring a border-style, so essentially it looks like the p-element's margin is overflowing, because there is an invisible border of 10px. Apply a border-style and you will see the margin:
body {
background-color: pink;
}
section {
background-color: lightgray;
max-width: 1000px;
box-sizing: border-box;
}
.article {
background-color: lightyellow;
width: 70%;
float: left;
margin: 0;
}
aside {
background-color: lightgreen;
float: right;
float: none;
overflow: hidden;
margin: 0;
}
footer {
background-color: aqua;
display: block;
border: black solid 10px;
box-sizing: border-box;
}
p {
margin: 1rem;
}
<section>
<div class="article">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ac eleifend ex, vitae bibendum tortor. Sed rutrum, orci quis venenatis congue, justo orci volutpat justo, semper vestibulum mauris est mattis mi. Duis tincidunt enim congue elit egestas, ut ultrices
purus vulputate. Curabitur gravida tellus vel ornare convallis. Nunc
</p>
</div>
<aside>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor aliquam massa. Pellentesque maximus tortor ac est ultricies, id sodales ligula vehicula. Fusce dignissim risus ligula, a feugiat augue
</p>
</aside>
<footer>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam malesuada dolor quis ante tempus, eget posuere massa egestas. Integer feugiat tellus nibh. Vestibulum pellentesque quam eu hendrerit porta. Suspendisse sagittis eros vitae urna convallis,
sit amet venenati
</p>
</footer>
</section>
I believe that is margin collapse.
I can see the intent to set a black border on the parent element footer in the first place. But that probably isn't working, and border: black 10px solid; would do the trick. And the margin collapse would no longer occur in this case.
Please read following page to learn about the margin collapse.
What is Margin Collapse in CSS? And How to Avoid It
And, as the other answers pointed out, perhaps it is padding, not margin, that suits your purpose.
You need to give padding to footer
Changes I made
In BODY tag
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
IN FOOTER
padding: 2%;
You apply box-sizing then i think you like to use padding. I refactor your css a little bit.
body {
background-color: pink;
}
section {
background-color: lightgray;
max-width: 1000px;
box-sizing: border-box;
}
.article {
background-color: lightyellow;
width: 70%;
float: left;
margin: 0;
}
aside {
background-color: lightgreen;
float: right;
float: none;
overflow: hidden;
margin: 0;
}
footer {
background-color: aqua;
box-sizing: border-box;
padding: 10px;
}
p {
margin: 1rem;
}
<section>
<div class="article">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ac
eleifend ex, vitae bibendum tortor. Sed rutrum, orci quis venenatis
congue, justo orci volutpat justo, semper vestibulum mauris est mattis
mi. Duis tincidunt enim congue elit egestas, ut ultrices purus
vulputate. Curabitur gravida tellus vel ornare convallis. Nunc
</p>
</div>
<aside>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec auctor
aliquam massa. Pellentesque maximus tortor ac est ultricies, id
sodales ligula vehicula. Fusce dignissim risus ligula, a feugiat augue
</p>
</aside>
<footer>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
malesuada dolor quis ante tempus, eget posuere massa egestas. Integer
feugiat tellus nibh. Vestibulum pellentesque quam eu hendrerit porta.
Suspendisse sagittis eros vitae urna convallis, sit amet venenati
</p>
</footer>
</section>
How can we get Flexbox to stop equalizing space in sibling elements when both of the elements are using flex-grow: 1. This is difficult to explain upfront, so here is the code quickly followed by example screenshots of the issue, and desired behavior.
.Parent {
display: flex;
flex-direction: column;
background-color: lightcoral;
width: 400px;
min-height: 200px;
}
.Parent>div {
flex: 1;
}
.child1 {
background-color: lightblue;
}
.child2 {
background-color: lightgreen;
}
<div class="Parent">
<div class="child1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sagittis lorem at odio euismod tincidunt. Proin aliquet velit nec augue venenatis laoreet. Etiam nec metus mi. Aliquam sit amet velit non lectus porttitor accumsan sit amet egestas risus.</div>
<div class="child2">Lorem ipsum</div>
</div>
The issue:
Notice the equal space under the content of each div.
Desired:
When there is little content in the children divs, the divs should be of equal height:
When one of the divs has a lot of content, I would expect the div with more content to only be as tall as the content (if it passes the original flex grow allotment).
How can I get this behavior? Seems it should be easy using Flexbox.
flex-basis is the property you're looking for. https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis
The flex-basis CSS property specifies the flex basis which is the initial main size of a flex item. This property determines the size of the content-box unless specified otherwise using box-sizing.
By default, flex will take into account the content in the element when computing flex-grow - to disable that, just specify flex-basis: 0
.Parent {
display: flex;
flex-direction: column;
background-color: lightcoral;
width: 400px;
min-height: 200px;
}
.Parent>div {
flex-grow: 1;
flex-basis: 0;
}
.child1 {
background-color: lightblue;
}
.child2 {
background-color: lightgreen;
}
<div class="Parent">
<div class="child1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sagittis lorem at odio euismod tincidunt. Proin aliquet velit nec augue venenatis laoreet. Etiam nec metus mi. Aliquam sit amet velit non lectus porttitor accumsan sit amet egestas risus. Etiam nec metus mi. Aliquam sit amet velit non lectus porttitor accumsan sit amet egestas risus </div>
<div class="child2">Lorem ipsum</div>
</div>
By setting min-height on .Parent (along with setting the flex-direction to column), you're triggering the browser to fill the space with direct descendants of .Parent. It does so by distributing the space amongst all elements equally (that's the feature of Flexbox).
If you don't want that behavior, remove the min-height from .Parent and set a min-height on .Parent > div elements.
.Parent {
display: flex;
flex-direction: column;
background-color: lightcoral;
width: 400px;
}
.Parent>div {
flex: 1;
min-height: 100px;
}
.Parent > div:nth-child(odd) {
background-color: lightblue;
}
.Parent > div:nth-child(even) {
background-color: lightgreen;
}
<div class="Parent">
<div class="child1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sagittis lorem at odio euismod tincidunt. Proin aliquet velit nec augue venenatis laoreet. Etiam nec metus mi. Aliquam sit amet velit non lectus porttitor accumsan sit amet egestas risus. Nullam sagittis lorem at odio euismod tincidunt. Proin aliquet velit nec augue venenatis laoreet. Etiam nec metus mi. Aliquam sit amet velit non lectus porttitor accumsan sit amet egestas risus.</div>
<div class="child2">Lorem ipsum</div>
<div>Lorem ipsum doler sit amet</div>
<div>When there is little content in the children divs, the divs should be of equal height.</div>
</div>
I am looking to accomplish a few things-
Set a container to fit 100% of viewport height and width;
Center the h1 vertically and horizontally in that container;
Add a paragraph of text beneath the h1 without this paragraph pushing the h1 up or breaking the centering.
Here's a diagram
I've already tried many of the methods discussed here and elsewhere (tables, display: table/table-cell + vertical align, using an inline-block with vertical align, etc) but the problem is that all of them either center both the h1 and the paragraph, or adding the paragraph under the h1 breaks it entirely. As the site is responsive, the h1 will likely become multiple lines of text on smaller screens. Is there a way to keep the h1 at the vertical and horizontal center while still adding content beneath it?
Well, basically just give the p a height of zero. The max-width below is just for illustration, margin: 0 auto then centers that horizontally.
html, body {
height: 100%
}
.container {
display: table;
height: 100%;
width: 100%;
}
.v-center {
display: table-cell;
vertical-align: middle;
text-align: center
}
p {
height: 0;
max-width: 200px;
margin: 0 auto;
}
<div class="container">
<div class="v-center">
<h1>Heading</h1>
<p>
Paragraph paragraph paragraph paragraph paragraph paragraph
paragraph paragraph paragraph paragraph paragraph paragraph...
</p>
</div>
</div>
The use of flexbox is your best bet as it is very concise and has good browser support. Also, it's your best bet for future-thinking as it is forming the foundation of today's modern app layout infrastructure.
The <p> being not pushed down is just done by giving a 0 height so that its effects on its container is not realized.
HTML:
<div class="container">
<h1>
HI
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras neque tortor, auctor ut consectetur non, posuere a justo. Morbi nisi eros, pellentesque eget ullamcorper eu, tristique at tortor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent ornare odio lorem, vel fermentum est lacinia ut. Vivamus tincidunt augue scelerisque justo consectetur tincidunt. Phasellus lectus nibh, ultrices in dictum vel, pretium at nisl. Sed vehicula tortor sed facilisis accumsan. Sed cursus felis quis quam efficitur, id luctus mi aliquet. Morbi mattis gravida convallis. Sed non feugiat dolor, in gravida arcu. Morbi id dolor imperdiet, rhoncus ante convallis, varius lacus.
</p>
</div>
CSS:
.container {
align-items: center;
background: red;
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
width: 100vw;
}
.container p {
height: 0;
}
Fiddle: https://jsfiddle.net/3ms3sggd/
A Great Flexbox Guide: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
You can put the p and h1 in a div, then give to the div margin-top equal to 50% viewport and margin-left/right auto
* {
margin: 0;
padding: 0
}
div {
background-color: #fff;
width: 400px;
height: 100px;
margin-top: 50vh;
margin-left:auto;
margin-right:auto;
text-align: center
}
h1{
margin-bottom: 20px
}
<div>
<h1>
header
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
</p>
</div>
with flex, things can be easy, text underneath can be setted in absolute position and html will scroll if needed:
html {
display:flex;
height:100%;
/* see center */
background:linear-gradient(to left, transparent 50%, rgba(0,0,0,0.2) 50%),linear-gradient(to top, transparent 50%, rgba(0,0,0,0.2) 50%)
}
body {
margin:auto;/* will shrink and center body on both axis */
/* see me ? */
background:rgba(0,0,0,0.2)
}
p {
position:absolute;
left:0;
right:0;
width:80%;/* set a width eventually */
margin:auto;/* if you did set a width, then can be useful */
}
h1 {
/*margin reset ? */
margin:0;
}
<h1>HI !,test me full page too</h1>
<p>Lesquelles habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
Note, what works here is p {position:absolute;} and the fact that HTML will show a scroll bar if p goes beyond bottom. Flex makes it easy to center h1, but other centering technic within the flow will do (inline-block or table/table-cell ) with html {height:100%} as a basis ...
So you can a full site laying under your midle center h1 :
html {
display: flex;
padding: 0;
height: 100%;
box-sizing: border-box;
background: linear-gradient(to left, transparent 50%, rgba(0, 0, 0, 0.2) 50%), linear-gradient(to top, transparent 50%, rgba(0, 0, 0, 0.2) 50%) fixed
}
body {
margin: auto;
text-align: center;
}
.below {
position: absolute;
left: 0;
right: 0;
width: 80%;
margin: auto;
text-align: left;
}
<h1>HTML Ipsum Presents</h1>
<div class="below">
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis
elit sit amet quam. Vivamus pretium ornare est.</p>
</blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
display: block;
width: 300px;
height: 80px;
}
</code></pre>
</div>
I've made an illustration of the situation:
The blue lines illustrate the grid the website is in. Let's assume a 960 grid for now, with a 300px left side (red part), a 20px gap and the remaining 640px for the right side (the black and green parts). I want to know if there's a solution for this problem that doesn't use calc() (due to older browsers) or background-image (because that's not really pretty).
Is there a pretty way to make this work, using just CSS while keeping the content centered within the grid, and the backgrounds flowing all the way to the borders of the screen?
http://codepen.io/anon/pen/avoKwQ
Done by pseudo elements and absolute positioning. Used bootstrap for faster demo. Actually, it is a specific problem and my solution may not fit your project. Especially not work when you require horizontal scrolling. But problem is solved.
&:after {
content: " ";
position: absolute;
top: 0; right: 6px;
width: 99999%;
height: 100%;
background: red;
z-index: -1;
}
Parent of this element ofcourse require position: relative. In example this is done by bootstrap.
Flexbox: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
This one has the added benefit of the columns always being equal height:
* { margin:0; padding:0; box-sizing: border-box; }
.grid {
display: flex;
}
.col-3 {
flex: 1 1 320px;
border-right: 20px solid #fff;
}
.col-2-3 {
flex: 1 1 640px;
}
.col-3 {
display: flex;
justify-content: flex-end;
}
.col-3>div {
padding: 20px;
flex: 0 1 300px;
}
.col-2-3>div {
display: flex;
justify-content: flex-start;
}
.col-2-3>div>div {
flex: 0 1 640px;
padding: 20px;
}
.red { background: #f00; color: #fff; }
.green { background: #0f0;}
.black { background: #000; color: #fff;}
<div class="grid">
<div class="col-3 red">
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris quis rhoncus erat. Morbi id pretium tortor. Sed tristique, leo non fringilla tempor, orci ligula lobortis velit, a efficitur tortor dui eget libero. Ut aliquam tortor sed diam placerat, ut lacinia ipsum lacinia. Cras a neque vehicula arcu rutrum luctus. Aliquam placerat ac ex in tincidunt. Quisque nulla diam, cursus nec orci sit amet, aliquet tempor massa.
</p>
</div>
</div><!-- col -->
<div class="col-2-3 green">
<div class="black">
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris quis rhoncus erat. Morbi id pretium tortor. Sed tristique, leo non fringilla tempor, orci ligula lobortis velit, a efficitur tortor dui eget libero. Ut aliquam tortor sed diam placerat, ut lacinia ipsum lacinia. Cras a neque vehicula arcu rutrum luctus. Aliquam placerat ac ex in tincidunt. Quisque nulla diam, cursus nec orci sit amet, aliquet tempor massa.
</p>
</div>
</div><!-- .black -->
<div class="green">
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris quis rhoncus erat. Morbi id pretium tortor. Sed tristique, leo non fringilla tempor, orci ligula lobortis velit, a efficitur tortor dui eget libero. Ut aliquam tortor sed diam placerat, ut lacinia ipsum lacinia. Cras a neque vehicula arcu rutrum luctus. Aliquam placerat ac ex in tincidunt. Quisque nulla diam, cursus nec orci sit amet, aliquet tempor massa.
</p>
</div>
</div><!-- .green -->
</div><!-- .col -->
</div><!-- .grid -->
I have a simple webpage with the center content with a red background. I'd like that background color to reach all the way to the bottom of the page, regardless of whether there is that much content in it or not.
I've tried various combinations of methods but nothing seems to stretch it correctly. In the Fiddle, I am attempting to use a flexbox but it doesn't appear to be working.
body {
background-color: white;
}
.main {
max-width: 80%;
background-color: red;
margin: 0 auto;
padding: 10px;
display: flex;
align-content: stretch;
flex-direction: row;
}
<section class="main">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce at aliquam dolor. Pellentesque a nibh in magna blandit elementum. Sed sodales porttitor dolor vel bibendum. Ut viverra justo in elit scelerisque, nec accumsan arcu facilisis. Nam ultricies
leo vitae felis sollicitudin lobortis. Cras nec nibh venenatis, bibendum neque at, suscipit lacus. Vestibulum interdum sodales cursus. Pellentesque feugiat eu velit venenatis egestas. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam
faucibus risus quis est pellentesque ultrices.
</p>
</section>
<section class="main">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
</section>
body
{
background-color:white;
}
.main
{
max-width:80%;
background-color:red;
margin: 0 auto;
padding: 10px;
display:flex;
align-content:stretch;
flex-direction:row;
}
I've tried various combinations of methods but nothing seems to stretch it correctly
I assume that you don't want a flex ONLY solution, because you can actually achieve this without the flex, so if that's the point, than set the parent elements height to 100%
Demo
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
html,
body {
background-color: white;
height: 100%;
}
.main {
max-width: 80%;
background-color: red;
margin: 0 auto;
padding: 10px;
height: 100%;
}
<section class="main">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce at aliquam dolor. Pellentesque a nibh in magna blandit elementum. Sed sodales porttitor dolor vel bibendum. Ut viverra justo in elit scelerisque, nec accumsan arcu facilisis. Nam ultricies
leo vitae felis sollicitudin lobortis. Cras nec nibh venenatis, bibendum neque at, suscipit lacus. Vestibulum interdum sodales cursus. Pellentesque feugiat eu velit venenatis egestas. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam
faucibus risus quis est pellentesque ultrices.
</p>
</section>
Also, you would see, am using the snippet below
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
will do nothing but count the borders, padding of the element inside instead of default box model which counts these outside the element, thus it won't result in vertical scroll as you were using padding and I used height: 100%; so as I explained, padding will be counted outside of the element, and will thus result in scroll.
box-sizing is a good option, its a CSS3 property.
I have one more option.
body, html {
min-height:100%;
height: 100%;
margin:0;
}
.innerBox {
min-height:100%;
width: 80%;
background: red;
margin: 0 auto;
}
<div class="innerBox">
Testing
</div>
What about using a new div for wrapping your content ?
Like this http://jsfiddle.net/MNQjk/2/
.block
{
max-width:80%;
background-color: red;
height: 1000px;
margin: 0 auto;
}