PDA

View Full Version : CS5 Vertical Centering


jwmcq
03-30-2012, 03:41 PM
Greetings. The question of vertical centering of an web page created in Dreamweaver has been addressed before. The most common solution seems to be some use of tables to place content. With all my content wrapped in a
.container div of fixed height and width (980 x 550), applying css 'auto' to left and right margins works correctly, but not when applied to top and bottom margins. Even with different positioning attributes, the content appears to want to camp out at the top of all the browsers. Is there an updated method to vertically center a page?
Many thanks.

html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JWM IU Auer Hall</title>


<link href="../../JWMWEB_CSS.css" rel="stylesheet" type="text/css" />
</head>

<body>


<div class="container">
<div class="sidebar1">
<div class="sidebar1" id="Logobox"></div>
<div class="sidebar1" id="Textbox_1">
<div class="sidebar1" id="Info">
<div class="sidebar1" id="Info_Title">
<p>Auer Hall</p></div>
<div class="sidebar1" id="Info_Subtitle"><p>Jacobs School of Music, Indiana University</p>
<p>Bloomington, Indiana</p>
</div>

<p>Text Body sample, text body sample, text body sample, text body sample </p>

</div>

</div>
<ul class="nav">
<li><a href="../The Firm.html">The Firm</a></li>
<li><a href="../Portfolio.html">Portfolio</a></li>
<li><a href="../Contact_Credits.html">Contact</a></li>
</ul>
</div>

<!-- end .sidebar1 -->

<div class="content">

<div class="content" id="Photobox">
<!--START SIMPLEVIEWER EMBED.-->
<script type="text/javascript" src="svcore/js/simpleviewer.js"></script>
<script type="text/javascript">
simpleviewer.ready(function () {
simpleviewer.load("sv-container", "100%", "100%", "transparent", true);
});
</script>
<div id="sv-container"></div>
<!-- END SIMPLEVIEWER EMBED -->
</div>
<div class="content" id="Accentbox"></div>
<!-- end .container -->
</div>
</div>



</body>
</html>

css:(commenting still included)

@charset "utf-8";
body {
padding: 0;
color: #1C1A11;
background-color: #380707;
margin-top: auto;
margin-right: auto;
margin-bottom: auto;
margin-left: auto;
font-family: Verdana, Geneva, sans-serif;
font-size: 100%;
line-height: 1.4;
font-weight: bolder;
height: 100%;
width: 100%;
position: static;
}



/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
padding: 0;
margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
/* [disabled]margin-top: 0; */ /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
padding-right: 0px;
padding-left: 0px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
-moz-background-origin: border;
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
border: none;
}

/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
color: #FCF0F6; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
font-size: 12px;
text-align: right;
vertical-align: top;
}
a:visited {
color: #FCF0D2;
font-size: 12px;
text-align: right;
vertical-align: top;



}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
text-decoration: none;
color: #F6F;
}

/* ~~ this fixed width container surrounds all other divs ~~ */
.container {
width: 980px; /* the auto value on the sides, coupled with the width, centers the layout */
overflow: hidden; /* this declaration makes the .container understand where the floated columns within ends and contain them */
background-color: #A58667;
margin-right: auto;
margin-bottom: auto;
margin-left: auto;
padding-top: 0px;
float: inherit;
height: 550px;
left: auto;
top: 0px;
right: auto;
bottom: 0px;
position: relative;
}


and
/* ~~ These are the columns for the layout. ~~

1) Padding is only placed on the top and/or bottom of the divs. The elements within these divs have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.

2) No margin has been given to the columns since they are all floated. If you must add margin, avoid placing it on the side you're floating toward (for example: a right margin on a div set to float right). Many times, padding can be used instead. For divs where this rule must be broken, you should add a "display:inline" declaration to the div's rule to tame a bug where some versions of Internet Explorer double the margin.

3) Since classes can be used multiple times in a document (and an element can also have multiple classes applied), the columns have been assigned class names instead of IDs. For example, two sidebar divs could be stacked if necessary. These can very easily be changed to IDs if that's your preference, as long as you'll only be using them once per document.

4) If you prefer your nav on the right instead of the left, simply float these columns the opposite direction (all right instead of all left) and they'll render in reverse order. There's no need to move the divs around in the HTML source.

*/
.sidebar1 {
float: left;
width: 230px;
;
border-bottom-width: 18px;
border-bottom-style: solid;
border-bottom-color: #BB8F0F;
background-color: #62573D;
clear: both;
border-top-style: none;
border-right-style: none;
border-left-style: none;
margin: 0px;
padding: 0px;
}
.content {
width: 750px;
float: left;
padding-top: 0px;
padding-right: 0;
padding-bottom: 0px;
padding-left: 0;
margin-top: 0px;
background-color: #A58667;
clear: right;

}

/* ~~ This grouped selector gives the lists in the .content area space ~~ */
.content ul, .content ol {
padding: 0px 0px 0px 0px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */


}

/* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */
ul.nav {
list-style: none; /* this creates the top border for the links - all others are placed using a bottom border on the LI */
margin-bottom:0px; /* this creates the space between the navigation on the content below */
color: #EDCE7B;


}
ul.nav li {
border-left-width: 0px;
border-left-style: solid;
border-top-color: #868058;
border-right-color: #868058;
border-left-color: #868058;
border-top-style: none;
border-right-style: none;


}
ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
width: 125px; /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */
text-decoration: none;
padding-top: 0px;
padding-right: 0px;
padding-bottom:5px;
padding-left: 0px;
background-color: #868058;
margin-bottom:7px;
border-left-width: 20px;
border-left-style: solid;
border-left-color: #868058;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
color: #6D5B3A;
background-color: #F2CE62;
border-left-width: 20px;
border-left-style: solid;
border-left-color: #DEAB12;
}

/* ~~ miscellaneous float/clear classes ~~ */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
float: left;
margin-right: 8px;
}
#Logobox {
padding: 0px;
float: left;
height: 114px;
width: 230px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-image: url(file:///C|/Users/test/Dropbox/JWM%20Site/jpg_graphics/JWM_logo.jpg);
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
margin: 0px;
}



#Textbox_1 {
background-color: #433D2A;
height: 335px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
float: none;
clear: inherit;
padding: 0px;
margin: 0px;
}
#Accentbox {
background-color: #E8C985;
float: right;
clear: right;
padding: 0px;
height: 434px;
width: 16px;
margin-top: 15px;
margin-right: 0px;
}
#Photobox {
background-color: #A58667;
float: right;
clear: both;
position: absolute;
padding: 0px;
margin-top: 15px;
margin-right: 0px;
margin-left: 0px;
display: inline;
background-image: none;
background-repeat: no-repeat;
width: 735px;
height: 535px;
}

}
#awards {
background-image: url(file:///C|/Users/test/Dropbox/JWM%20Site/jpg_graphics/Awards.jpg);
background-repeat: no-repeat;
height: 434px;
width: 735px;
float: none;
clear: both;
display: none;
z-index: 300;
margin-top: 15px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
#Credits {
background-image: url(file:///C|/Users/test/Dropbox/JWM%20Site/jpg_graphics/Credits_2.jpg);
height: 434px;
width: 735px;

}
#contact {
font-size: 10px;
color: #ECCD7B;
background-color: #433D2A;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
margin-right: 0px;
right: 0px;
position: relative;
line-height: 0.2em;
top: 5px;
width: 170px;
padding: 0px;
margin-top: 0px;
left: 25px;
}
#awards {
background-image: url(file:///C|/Users/test/Dropbox/JWM%20Site/jpg_graphics/Awards.jpg);
height: 434px;
width: 735px;
}
#Portfolio {
background-image: url(file:///C|/Users/test/Dropbox/JWM%20Site/jpg_graphics/Portfolio.jpg);
height: 434px;
width: 735px;
}
#Info {
font-size: 11px;
background-color: #433D2A;
width: 177px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
text-align: right;
font-weight: bold;
color: #FC6;
padding: 0px;
line-height: 12px;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
margin: 0px;
border-top-width: 0px;
border-right-width: 0px;
border-bottom-width: 0px;
border-left-width: 0px;
}
#Info_Title {
margin: 0px;
padding: 0px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
background-color: #433D2A;
font-size: 14px;
text-align: right;
font-weight: bold;
width: 177px;
text-decoration: underline;
}
#Info_Subtitle {
line-height: .95em;
background-color: #433D2A;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
text-align: right;
width: 177px;
}

edbr
03-31-2012, 01:52 AM
heres 5 ways with pros and cons commented
http://blog.themeforest.net/tutorials/vertical-centering-with-css/.

welcome to the forum please use code tage for posted tags as it makes it easier to read

jwmcq
04-01-2012, 05:22 AM
edbr-
Many thanks, precisely what the doctor ordered.
jwmcq