| | |||||
| ||||||||
| Webmaster Tutorials Instructional webmaster-related how-to's and tutorials. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Member Join Date: Mar 2008
Posts: 118
![]() ![]() | CSS for dummies in 10 lines So I see every day people is asking for CSS fixes in their layouts, most of the time I correct them for fun, and I've noticed the main reason people is getting complicated with CSS is because... they're complicating it for no reason. So this is a mini tutorial that will help you (I hope) to achieve the dreaded CSS thingy in just... 10 lines of CSS. And to make it more fun, I'll use some techniques that will help you to achieve things that most people is afraid of: same height columns! So, you can see the sample at http://mozlo.com/css_tutorial/ The sample has a header, a 3 columns body and a footer. If you want more or less columns, simply add/delete the column as you want it (and be sure to change the width for each column). In 99% of cases, you won't want anything more complicated like this. Are you seeing it? Cool. The html code for the page (without all the lipsum stuff) is as simple as this: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><head> <title>Page Title</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="container"> <div id="header"><h1>This is the Header</h1></div> <!--*************************************START LEFT COLUMN ***********************************************--> <div id="leftcol"><h2>The left column</h2><p>And the text for the left column</p></div> <!--*************************************END LEFT COLUMN ***********************************************--> <!--*************************************START CENTER COLUMN ***********************************************--> <div id="midcol"><h2>The middle column</h2><p>And some text for the center column</p> </div> <!--*************************************END CENTER COLUMN ***********************************************--> <!--*************************************START RIGHT COLUMN ***********************************************--> <div id="rightcol"><h2>The right column</h2><p>And then again, some text for the right column</p> </div> <!--*************************************END RIGHT COLUMN ***********************************************--> <hr style="display:block; height:0.1em; clear:both; visibility:hidden;" /> <div id="footer">Footer</div> </div> <!--*************************************END MAIN CONTAINER ***********************************************--> </body> </html> ????: NamePros.com http://www.namepros.com/webmaster-tutorials/546457-css-for-dummies-in-10-lines.html Then you have the header (with h1 tag) the cols (named in a way you'll recognize what they are at first sight) and a footer. You'll also see some "strange" code, and styled HR, but don't worry, I'll go to it later. Once you have your html, you need to start define elements. I'll make it sweet and simple: using px instead of ems or percentage, this one uses a container with 960px width, side columns are half of what the main column width is. Here goes the CSS code: Code: * {margin:0px; padding:0px;}
body{background:#def5f9; font-family:verdana, helvetica, sans-serif; font-size:0.8em}
#container{position:relative; width:900px; background:#f9f9f9; border:1px solid #900; margin:auto auto; padding: 10px 5px; overflow:hidden; text-align:center; z-index:1;}
#header{width:890px; background:#333; margin:auto auto; padding:16px; margin:-16px; margin-bottom:10px;}
#header h1{color:#fff; text-align:left;}
#leftcol{width:240px; float:left; background:#f6d4d4; padding: 10px 5px; margin:0px 5px; padding-bottom:4000px; margin-bottom:-4000px; }
#midcol{width:360px; float:left; background:#a3f9d8; padding: 10px 5px; margin:0px 5px; padding-bottom:4000px; margin-bottom:-4000px; text-align:left;}
#midcol p{margin-bottom:10px;}
#rightcol{ width:240px; float:left; background:#fa0; padding: 10px 5px; overflow:hidden; margin:0px 5px; padding-bottom:4000px; margin-bottom:-4000px;}
#footer{position:relative; width:890px; background:#333; margin:auto auto; padding:16px; margin:-16px; margin-bottom:10px; height:100px; clear:both; z-index:20; margin-bottom:-20px; margin-top:30px; color:#fff;} Code: * {margin:0px; padding:0px;}
body{background:#def5f9; font-family:verdana, helvetica, sans-serif; font-size:0.8em} Code: #container{position:relative; width:900px; background:#f9f9f9; border:1px solid #900; margin:auto auto; padding: 10px 5px; overflow:hidden; text-align:center; z-index:1;} Code: #header{width:890px; background:#333; margin:auto auto; padding:16px; margin:-16px; margin-bottom:10px;}
#header h1{color:#fff; text-align:left;} LET'S GO WITH THE COLUMNS!!!! Code: #leftcol{width:240px; float:left; background:#f6d4d4; padding: 10px 5px; margin:0px 5px; padding-bottom:4000px; margin-bottom:-4000px; }
#midcol{width:360px; float:left; background:#a3f9d8; padding: 10px 5px; margin:0px 5px; padding-bottom:4000px; margin-bottom:-4000px; text-align:left;}
#rightcol{ width:240px; float:left; background:#fa0; padding: 10px 5px; margin:0px 5px; padding-bottom:4000px; margin-bottom:-4000px;} Everything else is just styling (width, bg, color, whatever)and finally, the footer: Code: #footer{position:relative; width:890px; background:#333; margin:auto auto; padding:16px; margin:-16px; margin-bottom:10px; height:100px; clear:both; z-index:20; margin-bottom:-20px; margin-top:30px; color:#fff;} Finally, the misterious HR thing: I use that to add a little space when going wild with positive/negative values and clearing all floats. Dirty, but lovely. ????: NamePros.com http://www.namepros.com/showthread.php?t=546457 And that's it! The "impossible to make" in just 10 lines of CSS code. Now you can add divs inside the existing divs or whatever, try new things, experiment and learn! Hope this helps, if any mod feels like correcting my Engrish, I'd appreciate it |
| |
| | #2 (permalink) |
| New Member Join Date: Jan 2008
Posts: 24
![]() | Cool CSS tutorial. thanx gaucho1976.
__________________ http://www.bidourlinks.com |
| |
| | #6 (permalink) |
| Senior Member Join Date: Sep 2008 Location: IMEZI.COM
Posts: 1,597
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | thanks for the guidelines
__________________ WTS Amazon Minisite : Whois & IP check - Best Choice Printer - Cooking Recipe - Weight Loss Programme |
| |
| | #13 (permalink) |
| NamePros Member Join Date: Aug 2009 Location: famouspoem.blogspot.com
Posts: 29
![]() | It is a quite interesting tutorial I guess, I got interest on reading as well as much easier to understand. Thanks for giving your time and helping as with an awesome tutorial on css. |
| |