Sunday 8 July 2012

Centre aligning a block element


Centre aligning a block element

Say you wanted to have a fixed width layout website, and the content floated in the middle of the screen.

You can use the following CSS command:


#content
{
width: 700px;
margin: 0 auto
}


You would then enclose <div id="content"> around every item in the body of the HTML document and it'll be given an automatic margin on both its left and right, ensuring that it's always placed in the centre of the screen. Simple... well not quite - we've still got the pre-IE 6 versions on PC to worry about, as these browsers won't centre align the element with this CSS command. You'll have to change the CSS rules:


body
{
text-align: center
}

#content
{
text-align: left;
width: 700px;
margin: 0 auto
}


This will then centre align the main content, but it'll also centre align the text! To offset the second, probably undesired, effect we inserted text-align: left into the content div.



BUDDY CHECK OUT THESE ALSO : ALL LEARNING THING , HTML , CSS , WEB FORMS ,DREAM WEAVERDTD , JAVAJAVA SCRIPT , SQL , MY SQL  , PL-SQL , PHOTOSHOP , C + + , C  , WEB PAGES , MAYAPDF FILES , EVERYTHING AVAILABLE , AJAX  , HYBERNATE , WSDL  , WAP , RUBY ON RAILS , SCALA , HTTP , HTML 5 , PROTOTYPE , Wi-MAX , FLASH , WML , RUBY , PERL ,UNIX , DLL , RSS , RADIUS , UNIX SOCKET , PYTHON , JSP , SOAP , MVC , DOT NET , PHP , ADO , ASP , J QUERY , TCP/IP , VISUAL BASIC , UML , VISUAL STUDIO , GPRS....


1 comment:

  1. Please visit http://enginegearclutch.blogspot.in/ ,here u can find all about CSS and mechanical things

    ReplyDelete