Space inside Bootstrap button on hover - css

I have this weird case because my bug displays differently at my website and at JSFiddle. That's why I also put a printscreen to show you how it looks on my website.
Here is the JSFiddle: https://jsfiddle.net/Pysilla/cm8s1d7t/
<section id="fashion" class="img-responsive">
<div class="container">
<div class="row">
<div class="item element col-md-5">
<div class="page-header">
<h2>Fashion<span> photos</span></h2>
</div>
<p>Betiam finibus ac tellus sed ullamcorper. Suspendisse vestibulum mollis feugiat. Fusce vel turpis vitae nulla ullamcorper gravida non vel dolor. Ut rhoncus, metus vitae ultrices varius, ex mauris sodales leo, quis imperdiet turpis ipsum et ante. Phasellus hendrerit rutrum tincidunt. Sed sed viverra ligula, non ullamcorper mauris. Quisque dignissim sollicitudin nulla quis tincidunt. Cras at elementum massa. Cras eget mi hendrerit, congue nunc in, tristique massa. Vivamus at vestibulum ex.</p>
<div class="text-center">
<span>See more</span>
</div>
</div>
</div>
</div>
</section>
(When you change size of screen you could see little stripe on the left inside of the button)
I hope you could see the difference.

You just need to account for the 2px border on .btn-primary. You can use translate(calc(-100% - 2px)); on the hidden state of the pseudo element.
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css" rel="stylesheet"/>
<style>
.btn-primary{
margin-top:1em;
background-color:#3CD3DC;
background-image:none;
border:2px solid #3CD3DC;
display:inline-block;
transition:all 0.3s;
overflow:hidden;
box-shadow:none !important;
position:relative;
}
.btn-primary:hover{
background-color:transparent;
border:2px solid #3CD3DC;
}
.btn-primary:before{
content:"";
position:absolute;
background-color:#1fa5ad;
width:100%;
height:100%;
top:0;
left:0;
transform:translateX(calc(-100% - 2px));
transition: 0.8s;
}
.btn-primary:hover:before{
transform:translateX(0%);
left:0;
}
.btn-primary span{
position:relative;
}
</style>
<section id="fashion" class="img-responsive">
<div class="container">
<div class="row">
<div class="item element col-md-5">
<div class="page-header">
<h2>Fashion<span> photos</span></h2>
</div>
<p>Betiam finibus ac tellus sed ullamcorper. Suspendisse vestibulum mollis feugiat. Fusce vel turpis vitae nulla ullamcorper gravida non vel dolor. Ut rhoncus, metus vitae ultrices varius, ex mauris sodales leo, quis imperdiet turpis ipsum et ante. Phasellus hendrerit rutrum tincidunt. Sed sed viverra ligula, non ullamcorper mauris. Quisque dignissim sollicitudin nulla quis tincidunt. Cras at elementum massa. Cras eget mi hendrerit, congue nunc in, tristique massa. Vivamus at vestibulum ex.</p>
<div class="text-center">
<span>See more</span>
</div>
</div>
</div>
</div>
</section>

Another alternative is to set the button's :before element visibility to "hidden" by default and then "visible" on mouse over.
.btn-primary:before{
content:"";
position:absolute;
background-color:#1fa5ad;
width:100%;
height:100%;
top:0;
left:0;
transform:translateX(-100%);
transition: 0.8s;
visibility: hidden;
}
.btn-primary:hover:before{
transform:translateX(0%);
left:0;
visibility: visible;
}
https://jsfiddle.net/cm8s1d7t/1/

Related

How can I fade out one element and fade in another without the "snapping"?

I am attempting to fade out one element using "ng-show" and fade in another at the same time. This is working all fine and dandy, but unfortunately when the element which is fading out is hidden, there appears to be some "snapping" when display: none is set.
I've attempted setting position: absolute on my ng-hide-add-active & ng-hide-remove-active but this simply screws up the layout.
HTML:
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div id="form-container">
<div class="page-header text-center">
<h1 id="wf-logo">Hello</h1>
<hr />
<div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Stuff Box</h3>
</div>
<div class="sk-folding-cube animate" ng-show="!doneLoading">
<div class="sk-cube1 sk-cube"></div>
<div class="sk-cube2 sk-cube"></div>
<div class="sk-cube4 sk-cube"></div>
<div class="sk-cube3 sk-cube"></div>
</div>
<div id="content-well" class="well animate" ng-show="doneLoading">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis lacinia urna vitae lectus faucibus porta. Nulla eu consequat nisl. Quisque fringilla sapien id vulputate sollicitudin. Curabitur et facilisis justo. Donec malesuada augue vitae diam maximus luctus. Nulla fermentum consectetur ipsum ut tempor. Curabitur pretium eros eget nisi bibendum fermentum. Cras fermentum egestas nunc ut vulputate. Nulla aliquam tortor ut nulla consequat faucibus. Fusce imperdiet, felis nec semper vestibulum, magna dui ultricies tortor, eget mattis mauris arcu et ipsum. Suspendisse imperdiet nec mauris eget placerat.</p>
<p>Nulla purus augue, congue sed sollicitudin ut, volutpat sed ex. Donec lobortis sem eu risus consequat tincidunt. Nullam egestas lectus et semper gravida. Suspendisse facilisis erat a eros scelerisque euismod. Sed elementum eros ac nibh viverra condimentum eu vel mi. Ut sit amet nulla sit amet velit dignissim cursus quis ut mi. In a ultrices dolor. Proin sollicitudin sit amet lorem in fringilla. Mauris ac egestas est. Donec quis fermentum est, nec interdum nisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin id massa pellentesque, fringilla orci id, ultrices nisl. Nam non viverra felis, ac sodales justo.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
/* Styles */
#content-well {
margin-bottom: 0px;
}
/* Animations */
.animate.ng-hide-add,
.animate.ng-hide-remove {
-webkit-transition:all linear 0.5s;
-moz-transition:all linear 0.5s;
-o-transition:all linear 0.5s;
transition:all linear 0.5s;
}
.animate.ng-hide-add.ng-hide-add-active,
.animate.ng-hide-remove {
opacity:0;
}
.animate.ng-hide-add,
.animate.ng-hide-remove.ng-hide-remove-active {
opacity:1;
}
/* Folding cube spinner */
.sk-folding-cube {
margin: 40px auto;
width: 40px;
height: 40px;
position: relative;
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
Please see this Plunker:
http://plnkr.co/edit/6vSRIJ8xkmn75S9FyLMJ?p=preview
Is it possible to have the loading spinner & content both remain centered and properly positioned while one fades out and the other fades in? Any assistance would be greatly appreciated. Thank you!
Put position: absolute on one of the two containers.
For example:
.sk-folding-cube {
position: absolute;
The drawback is that you will have to add more CSS both to position the element as you want and to make it look like the panel wraps it.
For example:
.panel {
min-height: 161px;
}
.sk-folding-cube {
position: absolute;
left: 50%;
margin-left: -20px;
margin-top: 40px;
margin-bottom: 40px;
width: 40px;
height: 40px;
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
Demo: http://plnkr.co/edit/5lYJneAkT6TwYkfg3KPJ?p=preview
Another solution is to just skip the fade out animation entirely. Personally, when elements are overlapping, I rarely find it necessary to have one of the elements fade in while the other fade out. Instead, just hide the first and fade in the other. A matter of taste perhaps.
Demo: http://plnkr.co/edit/iudjWchMXzc3wILhQmsY?p=preview

Responsive background with its height based on the adjacent column using bootstrap

How can I have a full image background inside a column but without knowing the height of it? Im using bootstrap and I need the image to be responsive.
Please look at the image for a better understanding
<div class=" col-xs-12 col-sm-5 col-md-5 col-lg-4 bgimage">
</div>
<div class=" col-xs-12 col-sm-7 col-md-7 col-lg-8">
</div>
with .bgimage
{
background-image: url(../img/user.jpg);
background-size: cover;
}
here's a bootstrap example of a column that has background-size:cover
http://jsfiddle.net/maio/7rbjj2fn/3/
.bgimage{
background-image: url(http://oi58.tinypic.com/2u9mo0g.jpg);
background-size: cover;
height:200px
}
.right{
background:yellow;
height:100%;
}
.row{
background:tomato
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class='row'>
<div class=" col-sm-5 col-md-5 col-lg-4 bgimage">
</div>
<div class="right col-sm-7 col-md-7 col-lg-8">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper
Using background-size: cover; will cover the box without losing the ratio.
Using background-size: 100%; will fill the box but will losing the ratio.
EDIT
This is sample how the background works.
.table {
display: table;
width: 100%;
}
.cell {
display: table-cell;
}
.cell.left {
background-image: url(http://oi58.tinypic.com/2u9mo0g.jpg);
background-size: cover;
}
.cell.right {
width: 60%;
padding: 80px 30px;
background: #ccc;
}
<div class="table">
<div class="cell left"></div>
<div class="cell right">
Lorem ipsum dolor sit amet
</div>
</div>

html 5 positionning with or without div

I would like to know if for the demo index page of this site url, I can prevent the text from overflowing or let say use optional scrolling bar when the text goes over the bottom of the blue box? I would like the layout to be similar to this 'production' site (with server stats visits).
Can I do this using html 5? Should I include div so to limit text overflow under a certain screen resolution. Please find the html and style sheet code used (thanks for the author of this design and also Aayushi Jain who has help me with a few style sheet adjustments from another question here on this site).
style sheet
html {
overflow-y: scroll; }
div#wrapper {
width:90%;
margin: 10px auto;
position: relative;}
header#site {
height:80px;
padding:10px;
background-color:#0033FF;
margin:10px 0px;
text-align:center; }
footer {
font-size:0.8em;
clear:both;}
footer .col {
width:30%;
margin:1% 1.1%;
padding:2px;
height:100px;
background-color:#F63;
float:left; }
nav {
background-color:#0033FF;
position: absolute;
left: 0;
bottom: 0;
top: 110px;
width: 29%; }
nav ul {
list-style:none;}
nav ul li a {
display: block;
background-color:#CCC;
margin-right: 20px;
width: 110px;
line-height:1.5em;
text-align: center;
text-decoration: none;
color: #000; }
nav ul li a:hover {
color: #fff;
background-color:#39C; }
article {
background-color:#0066FF;
float:right;
width:69%;
margin-right:10px;
height:50%;
overflow-y:scroll;
}
article header {
background-color:#F90;
padding:15px; }
section#abstract {
font-size:1.09em;
font-style:italic;
margin:10px 0px;
text-align:justify;
padding:5px 80px; }
section#main {
font-size:1em;
padding:20px;
text-align:justify;
float: left;
margin: 0;
padding: 0;
display: inline; }
.ads {
height:50%;
width:30%;
background-color:#0033FF;
margin-bottom:1%;
float:left;}
.ads p:first-child {
padding:15px;
font-size:2em;}
.ads p:last-child {
padding-left:15px;
font-size:1em;color:#CCC;}
the html file
<!DOCTYPE html>
<!-- saved from url=(0064)http://toytic.com/class/examples/e808_html5_Header2NavAside.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Web site</title>
<link href="style.css" rel="stylesheet" />
<style>
</style>
<!-- Tell IE we are using html5 + CSS -->
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
<div id="wrapper">
<header id="site">
<h1>WEBSITE</h1>
</header>
<article>
<header>
<h2>This is the article header</h2>
<time datetime="25-11-2010" pubdate="">25th November 2010</time>
</header>
<section id="abstract">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et orci sed neque tincidunt dictum nec at lacus. Fusce feugiat sagittis ligula ac aliquam. Integer ut sodales justo. Etiam ultrices cursus iaculis. Suspendisse bibendum. </p>
</section>
<section id="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac velit mauris. Nulla cursus pretium dapibus. Fusce at faucibus mi. Etiam ac nisi condimentum quam vulputate euismod. Nunc viverra consectetur tempor. Praesent rutrum diam in leo lacinia sit amet volutpat leo tempus. Donec sodales, velit et viverra imperdiet, velit leo placerat libero, fringilla scelerisque justo sapien sit amet sapien. Donec blandit tellus at mi hendrerit hendrerit. Sed suscipit sagittis sodales. Etiam sagittis, tortor quis sagittis laoreet, erat nibh mollis sem, ut tristique felis augue non metus. </p>
<p>Etiam in gravida mi. Maecenas placerat, justo vel gravida egestas, odio sem dictum justo, eget volutpat massa augue in augue. Sed tempus sem a nulla eleifend aliquet aliquet diam pharetra. Proin sit amet imperdiet est. Cras vitae felis in nulla tristique porttitor ut sit amet neque. Quisque sed nisi quam. Aliquam erat volutpat. Nullam dignissim augue odio. Nam sit amet ipsum arcu, id rutrum felis. Phasellus velit mauris, dictum eget tincidunt eget, condimentum eget risus. Proin nibh nulla, sagittis et feugiat in, luctus quis velit. Aenean lobortis mi ut odio accumsan adipiscing. Nulla quis ipsum magna. Suspendisse auctor mauris eu mi cursus ultrices. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas gravida vulputate leo, consectetur porta sem euismod nec. Donec et dolor lectus, vel cursus massa. Morbi eu dictum arcu. Fusce luctus porttitor neque, sed eleifend orci tristique convallis. </p>
</section>
</article>
<nav>
<ul>
<li>About</li>
<li>Service</li>
<li>Contact</li>
</ul>
</nav>
<footer>
<div class="col">
<h4>Contact</h4>
<adress>
<p>Janet Griffith from Public Relations</p>
<p>Jil Sanders, webmaster</p>
</adress></div>
<div class="col">
<h4>Sites of interest</h4>
<aside>
<p>Site A</p>
<p>Another one</p>
</aside>
</div>
<div class="col">
<h4>Legal stuff</h4>
<p>Copyright</p>
<p>Terms of Service</p>
</div>
</footer>
</div>
</body></html>
thanks
Pascal
If you don't want to see the scroll bar then use overflow: hidden or overflow: auto.
Now if you want the header part to be static then put your section main and abstract in a div and make its height: 500px (or something you want) but make it fix and then use overflow: hidden in the newly mad div if you don't want to show the overflow part or use overflow: auto if you want to show the overflow part but not the scroll bar.

Why does my whole page move when I change margin-top?

Alright, I am making this website, from a tutorial, yes I am still a beginner, no the tutorial did not explain why this things happens.
Basically, this is what happens, I have the CSS like this.
#charset "utf-8";
/* CSS Document */
body { font-family: Arial, Helvetica, sans-serif; }
.container
{
width: 800px;
margin: 0 auto;
}
body, div, h1, h2, h3, h4, h5, h6, p, ul, img {margin:0px; padding:0px; }
#main
{
background: url(images/header.jpg) repeat-x;
}
#main .container
{
background: url(images/shine_04.jpg) no-repeat;
}
#logo
{
background: url(images/logo.png) no-repeat;
height:104px;
width:301px;
}
#logo h1
{
text-indent: -9999px;
margin-top: 40px;
}
And my HTML like this, I only post the body.
<div id="main">
<div class="container">
<div id="header">
<div id="logo">
<h1>Logo</h1>
</div>
<div id="tagline">
<h3>I Love Stuff</h3>
</div>
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</div><!--end header -->
<div id="content">
<h2>Lorem ipsum, Dolor sit</h2>
<h3>Nullam vulputate felis id odio interdum nec malesuada mi pretium. </h3>
<p>Praesent luctus egestas nisl, vitae vehicula eros rhoncus vel.
Phasellus consequat arcu eu neque convallis eu vulputate diam vehicula. In eget venenatis nisl.
Vestibulum id nulla eu sapien pellentesque malesuada pharetra ac lacus.
Curabitur et ultricies quam. Aenean pretium aliquet velit, gravida vulputate urna tempus vel. </p>
<p>Proin tempor erat sit amet nisl porta nec vulputate arcu imperdiet. Praesent luctus egestas nisl, vitae vehicula eros rhoncus vel.
Phasellus consequat arcu eu neque convallis eu vulputate diam vehicula. In eget venenatis nisl.
Vestibulum id nulla eu sapien pellentesque malesuada pharetra ac lacus. Curabitur et ultricies quam. Aenean pretium aliquet velit,
gravida vulputate urna tempus vel. Proin tempor erat sit amet nisl porta nec vulputate arcu imperdiet. </p>
<div id="news">
<h3>Latest Updates</h3>
<h4>Vestibulum id nulla eu sapien pellentesque</h4>
<small>June 1, 2009</small>
<p>Ut vel turpis a orci pulvinar tincidunt. Mauris id purus turpis. Aliquam metus arcu,
facilisis quis pellentesque vitae, dapibus non nulla. Nulla suscipit sagittis sodales.
Etiam laoreet ante in purus laoreet id malesuada dui pretium. Read More</p>
<h4>Vestibulum id nulla eu sapien pellentesque</h4>
<small>June 1, 2009</small>
<p>Ut vel turpis a orci pulvinar tincidunt. Mauris id purus turpis. Aliquam metus arcu,
facilisis quis pellentesque vitae, dapibus non nulla. Nulla suscipit sagittis sodales.
Etiam laoreet ante in purus laoreet id malesuada dui pretium. Read More</p>
</div><!--end news-->
</div><!--end content-->
<div id="sidebar">
<div id="subscribe">
<h3>Subscribe!</h3>
<ul>
<li>Subscribe via RSS</li>
<li>Get Email Updates</li>
<li>Follow us on Twitter</li>
</ul>
</div>
<div id="popular">
<h3>Popular Items</h3>
<ul>
<li>Lorem ipsum dolor site amet</li>
<li>Ulvinar tincidunt, Mauris id</li>
<li>Lorem ipsum dolor site amet</li>
<li>Proin tempor erat sit tene</li>
</ul>
</div>
<div id="contributors">
<h3>Contributors</h3>
<ul>
<li>John Smith, freelance writer</li>
<li>Jack McCoy, designer</li>
<li>Lenny Briscoe, editor</li>
<li>John Smith, martketing</li>
</ul>
Join Our Team
</div>
</div><!--end sidebar-->
</div><!--end main container-->
</div><!--end main-->
<div id="footer">
<div class="container">
<p>Copyright © 2009 MySite <br />
All Rights Reserved</p>
</div><!--end footer container-->
</div><!--end footer-->
In the CSS, I have the #logo h1 selector, as you can see from the parent #logo selector, I have a background, which is exactly the logo, now I want the damn logo to be positioned 40px slightly lower from the top, that's why I put margin-top: 40px; , and I don't understand why, but instead of just the logo moving 40px down, the whole page moves down! T_T, I have already spent almost 1 hour trying to deduce all the logic that my brain can handle behind this, but I just cant!
And my question is just like what I said, why does the whole page move downwards? the logo image is the only element that's supposed to move, but why the whole thing? and what do I do to fix it?
Try substituting margin with padding: padding-top: 40px on the parent container, i.e. #header, since you have specified a background image for #logo and do not have to see it move.
Why paddings over margins? It's simple: margins have the propensity to collapse. W3C has a comprehensive section dedicated to rules that govern margin collapse.
p/s: For the ease of troubleshooting, try posting your issue on JSFiddle. Not only does it help the community to visualize your problem, but it also aids to expedit the process of actually solving your problem.
Try
#logo
{
background: url(images/logo.png) no-repeat;
height:104px;
width:301px;
background-attachment:fixed;
background-position: 0px 40px;
}
try this:
#logo
{
background:url(images/logo.png) no-repeat;
background-position: 0px 40px;
height:144px;
width:301px;
}

Making a footer not rise above the bottom of the screen without extraneous markup

If you only had to worry about Firefox and Webkit browsers, what CSS would you use to make the footer in the following HTML not rise above the bottom or the screen (and go lower if the body content pushed it)? Note: I don't want to add any of markup to the page.
<html>
<body>
<header>...</header>
<article>...</article>
<aside>...</aside>
<footer>...</footer>
</body>
</html>
Here is some copy paste html. How do I need to modify the css to make it work?
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
p {
margin-bottom: 10px;
}
article {
display: inline-block;
height: auto;
width: 69%;
}
aside {
display: inline-block;
height: auto;
width: 30%;
}
footer {
height: 30px;
}
</style>
</head>
<body>
<header>
<h1>Lorem Ipsum</h1>
</header>
<article>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eu viverra mauris. Fusce at erat risus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed tincidunt orci eget justo ornare vel iaculis mauris commodo. Ut id leo ipsum. Donec nunc est, convallis sit amet vehicula eget, laoreet id odio. Proin vitae purus magna. Maecenas lorem lacus, convallis ac imperdiet in, ullamcorper sed leo. Maecenas suscipit justo at arcu placerat eu ultricies orci placerat. Etiam vel erat in metus porttitor tristique vel ultricies ante. Aliquam sed porttitor nunc. Sed venenatis, sapien lacinia laoreet facilisis, lectus turpis iaculis leo, nec rhoncus tellus erat bibendum felis. Integer cursus malesuada sem id vehicula. Duis venenatis pellentesque nisi ut vulputate. Nunc elit sapien, pulvinar blandit suscipit ut, imperdiet ut neque. Cras odio dolor, commodo vitae malesuada sed, tempus sed neque.</p>
<p>Sed nec ornare libero. Vivamus ut risus at ligula dignissim lobortis. Pellentesque dignissim iaculis fringilla. Quisque porta sagittis massa eu euismod. Vivamus nunc lectus, iaculis vitae tincidunt et, placerat at risus. Nunc elementum massa at ligula blandit quis volutpat nulla malesuada. Nunc felis massa, placerat at vehicula non, gravida a nibh. Fusce adipiscing magna et nisl aliquet vehicula posuere tortor tempor. Aliquam erat volutpat. Duis eu enim sit amet lacus hendrerit elementum vitae a purus.</p>
<p>Phasellus porttitor congue tellus, eget rhoncus eros consequat a. Donec faucibus lorem at sapien aliquam tempus. Sed sed vulputate magna. Proin eros felis, eleifend vitae posuere vel, dictum ut purus. Pellentesque id felis sit amet neque consectetur porta. Donec non tellus augue, a sollicitudin libero. Nullam blandit hendrerit lacus. Quisque ac libero sapien. Etiam luctus tellus non sapien fringilla ultrices. Aliquam ut erat ut sapien mattis rhoncus nec eu enim. Aenean elementum dui in ligula fermentum nec egestas dui luctus. Praesent sed purus id tellus lacinia aliquam. Donec luctus, metus ut pulvinar bibendum, sapien dui aliquet est, volutpat cursus enim massa non sapien. Quisque mollis nisl a arcu ullamcorper porta. Nunc dapibus pellentesque dui in varius. Donec et eros ut lacus commodo vehicula.</p>
</article>
<aside>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
</ul>
</aside>
<footer>
<span>Made by me.</span>
</footer>
</body>
</html>
Given the requirements of no extra markup and not caring about IE (does work in IE8), I present this solution (which does require the use of a fixed height header). I did have to use float rather than display: inline-block as my Safari 4.0 did not display it with min-height for this solution:
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
}
body {
height: 100%;
/*below for illustration only*/
background: yellow;
}
#Header {
position: relative;
z-index: 1;
height: 60px;
margin-bottom: -60px;
/*below for illustration only*/
background: red;
opacity: .8;
}
#Article {
float: left;
min-height: 100%;
width: 69.9%;
vertical-align: top;
margin-bottom: -30px;
/*below for illustration only*/
background: blue;
}
#Aside {
float: left;
min-height: 100%;
width: 30%;
vertical-align: top;
margin-bottom: -30px;
/*below for illustration only*/
background: green;
}
#Article:before,
#Aside:before {
content: ' ';
display: block;
height: 60px;
width: 100%;
}
#Article:after,
#Aside:after {
content: ' ';
display: block;
height: 30px;
width: 100%;
}
#Footer {
position: relative;
z-index: 1;
height: 30px;
margin-top: -30px;
clear: left;
/*below for illustration only*/
background: pink;
opacity: .8;
}
</style>
HTML is just:
<body>
<div id="Header">Header</div>
<div id="Article">Article</div>
<div id="Aside">Aside</div>
<div id="Footer">Footer</div>
</body>
I think I figured this out:
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.1.1/build/cssreset/reset-min.css">
<style type="text/css">
html {
background-color: orange;
height: 100%;
}
body {
background-color: yellow;
height: auto;
min-height: 100%;
position: relative;
}
ul {
list-style: none;
}
p {
margin-bottom: 10px;
}
header {
background-color: red;
display: block;
}
article {
background-color: blue;
display: inline-block;
margin-bottom: 30px;
vertical-align: top;
width: 70%;
}
aside {
background-color: green;
display: inline-block;
margin-bottom: 30px;
vertical-align: top;
width: 30%;
}
footer {
background-color: pink;
bottom: 0;
height: 30px;
left: 0;
position: absolute;
width: 100%;
}
</style>
CSS:
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}
HTML:
<html>
<head>
<link rel="stylesheet" href="layout.css" ... />
</head>
<body>
<div class="wrapper">
<div class="header"></div>
<div class="article"></div>
<div class="aside"></div>
<div class="push"></div>
</div>
<div class="footer">
<p>Copyright (c) 2008</p>
</div>
</body>
</html>
I think you're talking about the margin of 10-15 pixels below the footer. Try adding this code to your CSS;
body { margin-bottom:0px; }
The body has a default margin of 10-15 pixels so in order to remove it to flush your design to the top or bottom you have to tell the body to have a margin of zero.
Hope that helps.
*
{
display:block;
}
You are going to have to change the display to inline in your wrapper after that though.
First of all, no matter what you do, you'll need a wrapper div for the entire page. I usually call it #page_container or something. If you think about it, having a div container for the whole page doesn't defeat the essence of css style sheets. On the other hand, if you had a bunch of wrappers scattered around the html page, it could potentially get pretty messy with all that extra markup. So, I always use a page_container on my layouts, even if I don't put any css styling on it, I always have one. Basically, it will just act like a body tag, only allow you to style it.
With that said, there are a couple solutions if your layout was refined to:
<html>
...
<body>
<div id='page_container'>
<div id='header'></div>
<div id='contents'></div>
<div id='footer'></div>
</div>
</body>
</html>
Only Firefox you say? Did I hear that right? I don't think I've ever heard anyone say that before. In that case, its fairly easy. The easiest solution would be:
<html>
<head>
<title>Test page</title>
<style>
body{
background-color:green;
margin:0px;
}
#page_container{
width:700px;
margin-left:auto;
margin-right:auto;
display:table;
height:100%;
}
#header{
background-color:red;
text-align:center;
font-size:25px;
font-weight:600;
height:75px;
display:table-row;
}
#contents{
background-color:yellow;
display:table-row;
}
#footer{
background-color:blue;
height:25px;
display:table-row;
}
</style>
</head>
<body>
<div id='page_container'>
<div id='header'>Title of your page</div>
<div id='contents'>
Foo bar baz<br/>
Foo bar baz<br/>
Foo bar baz<br/>
Foo bar baz<br/>
Foo bar baz<br/>
Foo bar baz<br/>
</div>
<div id='footer'>This is a footer</div>
</div>
</body>
</html>
I've been experimenting with some other css styling, and I think I almost have a layout that could be cross-browser compatible. I'll post it if I'm not too late.
Okay, here is the alternative css that I was talking about. It works in Firefox, Safari, and Chrome. IE7/IE6 don't work, you'd probably have to a little tweaking to get that working. Opera has a small bug with the body margins. Other than that, it uses just basic CSS (unlike the display:table that isn't very compatible).
<html>
<head>
<title>Test page</title>
<style>
body{
margin:0px;
background-color:green;
margin-top:75px;
margin-bottom:25px;
}
#page_container{
max-width:700px;
margin-left:auto;
margin-right:auto;
position:relative;
height:100%;
padding-top:75px;
margin-top:-75px;
}
#header{
background-color:red;
text-align:center;
font-size:25px;
font-weight:600;
height:75px;
z-index:2;
position:absolute;
top:0px;
width:100%;
}
#contents{
background-color:yellow;
width:100%;
min-height:100%;
}
#footer{
background-color:blue;
height:25px;
}
</style>
</head>
<body>
<div id='page_container'>
<div id='header'>Title of your page</div>
<div id='contents'>
Foo bar baz<br/>
Foo bar baz<br/>
Foo bar baz<br/>
Foo bar baz<br/>
Foo bar baz<br/>
Foo bar baz<br/>
</div>
<div id='footer'>This is a footer</div>
</div>
</body>
</html>
Wow, if you just tweaked it a little and made it IE6-7 compatible, you'd be famous. I think this is the first solution I've seen.
Since you mentioned that your solution worked except for IE, all you need to do is use JS to enable the styling of HTML 5 elements:
http://medero.org/finally.html
That would make the styles apply, but it still looks like, at least in IE6 it needs some extra help.
Is this close to what you need for IE?
Working and tested on:
Google Chrome
Safari
Opera
Internet Explorer
Firefox
EDITED CODE (added overflow:auto; to #aside and #Article to fix the overflow)
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html,body{height:100%;width:100%;margin:0;padding:0;background-color:red;}
#Header,#Article,#Aside,#Footer{position:absolute;}
#Header{top:0;left:0;width:100%;height:60px;background-color:blue;}
#Article,#Aside{top:60px;overflow:auto;bottom:30px;}
#Article{left:0;width:70%;background-color:green;}
#Aside{right:0;width:30%;background-color:yellow;}
#Footer{bottom:0;left:0;width:100%;height:30px;background-color:pink;}
</style>
</head>
<body>
<div id="Header">Header</div>
<div id="Article">Article</div>
<div id="Aside">Aside</div>
<div id="Footer">Footer</div>
</body>
</html>
PS:
Background colors are illustrative, thus the css can me more compact by avoiding repeated attributes!
Another answer for those who only need to target the latest versions of browsers utilizing flexbox and viewport units.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
height: 60px;
}
article {
flex: 1;
}
footer {
height: 30px;
}
</style>
</head>
<body>
<header>
<h1>Lorem Ipsum</h1>
</header>
<article>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eu viverra mauris. Fusce at erat risus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed tincidunt orci eget justo ornare vel iaculis mauris commodo. Ut id leo ipsum. Donec nunc est, convallis sit amet vehicula eget, laoreet id odio. Proin vitae purus magna. Maecenas lorem lacus, convallis ac imperdiet in, ullamcorper sed leo. Maecenas suscipit justo at arcu placerat eu ultricies orci placerat. Etiam vel erat in metus porttitor tristique vel ultricies ante. Aliquam sed porttitor nunc. Sed venenatis, sapien lacinia laoreet facilisis, lectus turpis iaculis leo, nec rhoncus tellus erat bibendum felis. Integer cursus malesuada sem id vehicula. Duis venenatis pellentesque nisi ut vulputate. Nunc elit sapien, pulvinar blandit suscipit ut, imperdiet ut neque. Cras odio dolor, commodo vitae malesuada sed, tempus sed neque.</p>
<p>Sed nec ornare libero. Vivamus ut risus at ligula dignissim lobortis. Pellentesque dignissim iaculis fringilla. Quisque porta sagittis massa eu euismod. Vivamus nunc lectus, iaculis vitae tincidunt et, placerat at risus. Nunc elementum massa at ligula blandit quis volutpat nulla malesuada. Nunc felis massa, placerat at vehicula non, gravida a nibh. Fusce adipiscing magna et nisl aliquet vehicula posuere tortor tempor. Aliquam erat volutpat. Duis eu enim sit amet lacus hendrerit elementum vitae a purus.</p>
<p>Phasellus porttitor congue tellus, eget rhoncus eros consequat a. Donec faucibus lorem at sapien aliquam tempus. Sed sed vulputate magna. Proin eros felis, eleifend vitae posuere vel, dictum ut purus. Pellentesque id felis sit amet neque consectetur porta. Donec non tellus augue, a sollicitudin libero. Nullam blandit hendrerit lacus. Quisque ac libero sapien. Etiam luctus tellus non sapien fringilla ultrices. Aliquam ut erat ut sapien mattis rhoncus nec eu enim. Aenean elementum dui in ligula fermentum nec egestas dui luctus. Praesent sed purus id tellus lacinia aliquam. Donec luctus, metus ut pulvinar bibendum, sapien dui aliquet est, volutpat cursus enim massa non sapien. Quisque mollis nisl a arcu ullamcorper porta. Nunc dapibus pellentesque dui in varius. Donec et eros ut lacus commodo vehicula.</p>
</article>
<footer>
<span>Made by me.</span>
</footer>
</body>
</html>

Resources