CSS - Css Formating (stylesheet Optimization, Avoiding Code Repitition)
Hey everyone, I'm working on developing a small CMS, as a project to help push myself into actually completing something and would jsut love some insight into how to clean up some of my CSS.
At the moment im not satisfied how im formating the CSS stylesheet. For example Im working with nested divs, in this case for one component of the site, and I find I'm repeating certain perameters that could be avoided, but I'm unsure how to do that. Example Code: PHP Code: echo '<div id="article">'; echo '<div id="article_header">'; echo $row['news_title']; echo '</div>'; echo '<div id="article_content">'; echo $row['news_content']; echo '</div>'; echo '<div id="article_footer">'; echo 'Add Comment'; echo '</div>'; echo '</div>'; CSS: Code: #article { margin-bottom: 8px; border: 1px #1D1D1D solid; padding: 5px 5px 5px 5px; background-color: #4C4C4C; } #article_header { padding: 5px 5px 5px 5px; background-color: #1D1D1D; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #999999; } #article_content { padding: 5px 5px 5px 5px; background-color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #999999; } #article_footer { padding: 5px 5px 5px 5px; background-color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #999999; text-align: right; } To summarize my question, is there a better way of formating my CSS and how would I do so? Similar TutorialsQuote: Dan Cederholm of SimpleBits: It's important to note that the cascading effect of CSS still applies, and alternate style sheets work just like any other style sheet, in that only common rules are overridden when the alternate styles are active. So if we had layout, positioning, and other site-wide rules in default.css that weren't repeated in the alternate style sheets, those default rules would still work. I'm making a site that has a default stylesheet with a fixed layout and an alternative one with a fluid layout. The problem I'm having is the alternative sheet not inheriting css from the default stylesheet even though the rules are not overridden. At the moment, my alternative stylesheet is an exact copy of the original (everything included) with only 3 width values changed to percentages. Theoretically, I should be able to only include these three rules alone in the alt sheet, as rules are carried over from the default sheet unless overridden. However, when I do try to reduce the alt sheet to just: Code: #container { width: auto; } #main { width: 65%; } #navbar { width: 30%; } all unincluded formatting is lost. Am I doing something wrong? Cheers, Sam. Hey guys, please help me out with this, I missed the last day of css in my class and I'm confused, and right now I'm working on my final project. I'm kinda confused, I want to do a few things from an external stylesheet but I think I have the code wrong. PLEASE HELP! href {onmousemover:color:red} P {text-align:justified;font-size:12pt} h1 {style=font-size:24pt} h2 {style=font-size:18pt} PLEASE HELP ME OUT! is this right? It doesn't work, but I know my external stylesheet stuff works cause I did the all uppercase thing and that worked, sooo help!!! I have a very strange problem. My firefox is ignoring the changes I made to the style sheet. I have this in my webpage and the style.css file location is right (one directory up). <link href="../style.css" rel="stylesheet" type="text/css"> Because it's ignoring my new changes, I deleted everything in my style.css file, and the page still displays as though the file exists. However, if I delete the above line, then the page will display without any style. IE is loading with the changes I made though. I have also checked my stylesheet with the W3C css validation and it has no error. So, any body know why this is happening? hi.. i need to change the height of drop down box, if i change that using style means getting in firefox but not in IE.. IE taking some default height... need to avoid tht.. help me out guys.. its very urgent... pls... Hi to all, & this is my question: say I have a css class such as: .classA1 { color: RED; font-weight: bold; font-size: 11px } Now I want to define other classes, that vary only in the font color, while everything else remains unchanged, for example: .classA2 = { color: GREEN; rest same as A1 } .classA3 = { color: BLUE; rest same as A1 } .classA4 = { color: YELLOW; rest same as A1 } How do I go about it, so I avoid having to repeat every time the same attributes? I know there is a way of defining a main class & then the variations (like for elements - a - a:hover - a:visited etc..) but I'm not sure how you do this... Thanks a lot for your help, Luca How do i optimize a stylesheet so it is as small as possible and clear to read as possible and of course is it important to validate a stylesheet? cause i see people insisiting on web page validation but too much on css validation? Alright.. so I made a site, and have been trying to optimize it in FF, IE6, IE7, NS, and Opera. It works fine in all except NS. Well, the only thing not working in NS is the background-image: Code: .navbar {background-image:url('images/navbar.jpg'); text-align:center; margin:auto; width:635px; font-size:16px; font-family:Times New Roman; } Is there a hack for NS that I haven't been able to find? Or am I just missing something. Thanks. Hi Guys I have a series of <li></li> within a <td> The problem is that the lists are far away from the left side of the table hence causing all the information to spread over to the next line. Is there tweak for this to make the <li> info be closer to the left... Thanks Didi I have a left nav that I'm trying to squeeze as much text in as possible in 155 px. In IE FF/MOZ this is working fine by using various combinations of letter and word spacing. Opera 7 just seems to ignore most of it. Code: #section_nav div a{ font-size:.9em; color:#fff; font-weight:600; text-decoration:none; display:block; width:100%; height:100%; letter-spacing:-.5px; } *html #section_nav div a{ word-spacing:-1px; letter-spacing: -1px; } if I take out the *html it works in opera but then looks bad in FF is there any hack to show only to opera? or is there something to hide from FF/MOZ See the current solution here ... What I would like to do is dump the table, so that the images and captions wrap at screen width. I have been experimenting with CSS and <span>s but as yet haven't managed a similar formating. And ideas/solutions/pointers would be greatly appreciated Chris Jones URL Everytime I think I am getting the hang of CSS -- for simple pesonal homepages, etc -- they still always seem to get the worse on me. I am trying to generate a moderately simple page with title, prelude, menu (as per a table) with menu, content and comment box, followed by a quick sumary, etc. I seem to be having troubles getting the three -- menu, content & comment boxes -- to size correctly. I have a surounding box (by a div) for them, but they do not seem to entirely follow/use it as their parent... If I set them to top:0, it is the top of the window frame, but otherwise they seem to position within their more local parent div. Ultimately, I am striving to get into this CSS way of 'life', but it is very difficult as I am working mainly alone. I do have books but perhaps I am not seeing the info entirely correct... Perhaps some of you chaps/gurus can help me here. I have recently gathered that "html" is or should be used in the CSS file too...? Looking for help. My current (broken) home page can be accessed via: "dgringo.homeip.net/~dgringo/index.shtml" Here is the code and the CSS file: <head> <title>...</title> <script language="JavaScript" type="text/javascript" src="main.js"></script> <link rel="stylesheet" href="entry.css" type="text/css" /> </head> <body> <h1>Me (iMac's) Web-space</h1> <div id="prelude"> <!--#include virtual="includes/header.incl" --> </div> <table id="main"> <tr> <td id="menu"> <!--#include virtual="includes/menu.incl" --> </td> <td id="content"> <!--#include virtual="includes/body.incl" --> </td> <td id="topics"> <p> <!--#include virtual="includes/topic1.incl" --> </p> <p> <!--#include virtual="includes/topic2.incl" --> </p> </td> </tr> </table> <div id="footer"> <!--#include virtual="includes/footer.incl" --> </div> <div class="adendeum"> Last updated <!--#echo var="LAST_MODIFIED" --><br /> </div> </body> </html> ------------- The CSS file now follows: a:link {text-decoration:none;color: black;} a:visited {text-decoration:none;color: black;} a {color: black;} a:hover {text-decoration:underline;color: silver;} body { color: #000000; background: #669999; } h1 { text-align: center; } #prelude { width: 80%; background-color: #CCCC99; margin-left: auto; margin-right: auto; padding-top: 3px; padding-bottom: 3px; padding-left: 10px; padding-right: 10px; text-align: center; } #main { display: block; width: 100%; border: silver dotted; height: 16em; } #main td { border: dashed; } #menu { position: absolute; width: 20%; left: 2%; } #content { position: absolute; left: 23%; width: 50%; } #topics { position: absolute; left: 74%; width: 20%; } p:first-line { color: gray; background-color: green; } #footer { text-align: center; width: 80%; background-color: #CCCC99; margin-left: auto; margin-right: auto; padding-top: 3px; padding-left: 10px; padding-bottom: 3px; padding-right: 10px; } .adendeum { font-weight: lighter; color: gray; text-align: center; } I have three different css Stylesheets. Now I want to give access to my users to change their required styles using dropdownlist. And next time when the user is login in the same last selected style sheet should be displayed to him. How can i do this please help me its urgent ? I was wondering does anyone know where I can obtain the Internet Explorer 6 stylesheet for Windows XP? The UI components in IE6 look different in Windows XP than IE6 for Windows 2000. I would like to obtain the stylesheet if it is available somewhere. Thanks for your help. Val Hello. I'm trying to avoid using the <div style="clear:both"> fix for keeping elements from floating outside of their containers in IE7. Here's the code that's working with that fix. I'd like to have a way to adjust the CSS so I can take that out. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="css/global.css" rel="stylesheet" type="text/css" /> <link href="css/.css" rel="stylesheet" type="text/css" /> <title>A Beautiful Smile</title> </head> <body> <div id="wrapper"> <div id="banner"> <ul id="navigation"> <li><a href="">Home</a></li> <li><a href="">Help</a></li> <li><a href="">Contacts</a></li> </ul> <img id="logo" src="images/global/logo.jpg" alt="Company Logo" /> <div style="clear:both"></div><!--Prevents img changesmile.jpg from going outside banner in IE7 --> <img id="changesmile" src="images/global/changesmile.jpg" alt="Learn how we can change your smile." /> </div> <div id="footer"> </div> </div> </body> </html> CSS Code: /* http://meyerweb.com/eric/tools/css/reset/ */ /* v1.0 | 20080212 */ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, textarea dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; vertical-align: baseline; background: transparent; } body { line-height: 1; } /* End CSS Reset, Begin Styling */ #wrapper{ margin: 10px auto; width: 735px;} #banner{ width: 100%; height: 279px; margin: 0px auto; background: URL('../images/global/banner.jpg') no-repeat;} #navigation{ width: 200px; margin: 50px 0px 0px 330px; float: left; } #navigation li{ display: inline; list-style-type: none; float: left; margin-left: 20px;} #navigation li a{ color: #CCCCCC; font-family: "Tahoma", "Verdana", sans-serif; font-size: .70em; text-decoration: none;} #navigation li a:hover{text-decoration: underline;} #logo{ display: block; width: 180px; height: 82px; float: right; margin: 0px; } #changesmile{ display: block; width: 228px; height: 75px; float: right; clear: both; margin: 100px 60px 0px 0px; } I appreciate your help! Can you only exclude elements from a Print stylesheet? I'd like to print only a table of data and nothing else on the web page in a print style sheet. Hiya, theres a website I'm creating a print stylesheet for which includes the company logo in the header, with a footer of contact details. problem is, the website is all static pages and 100 odd pages, so as I'm having to deal with the static state of the site for now, is there a way I can have in the Print stylesheet or in the CSS where the logo can be inserted in a header and a footer created with text? hope this makes sense? Hi people, I am completely new to programming and have only spent this weekend learning it! I have managed to create a decent website already, however i am stuck at a point. On my main page, i have attached a CSS stylesheet with all the formatting for my page. My problem however is that when i try to format one section (<div id="gallery">) the formatting messes with the rest of the page. Is there a way that i can assign a style sheet to only that <div id="gallery"> without it applying to the entire html page. Any help is greatly appreciated! Thanks Chris Hello All, I was hoping that you could look at a site for me, and help me figure out what is causing the rendering issues in IE6/7. I have a separate CSS stylesheet for anything that is IE7 or lower; however, I am not sure if it is actually loading at all. I don't really have access to IE6/7 in a live environment, to check everything about the site, so if anyone has any suggestions for tools that will allow me to work with a live view of IE6/7 that would be a great help as well. The site link is: http://www.saracanada.com/ Thanks in advance everyone. Hey all, a few probs here. My new webpage coded with stylesheets: http://www.stocksbridgepentaqua.co.uk/test/index.php It looks good in IE and bad in FireFox (mozilla) its not a major problem because the ppl im targetting are using IE. Next, on this page: http://www.stocksbridgepentaqua.co..../index.php?id=9 I want a scroll bar in the actual window instead of it making the box massive. And another thing, how do I make a space between the bottom of the website and the bottom of the browser? Thanks. Jack. Hey, I've run into a problem where I though i knew how to do it an easy way but it only worked for about 5 minutes. Here is what I have. All of my pages have the same navigation from an external PHP file. The style is saved in the main.css stylesheet. When you select a link it gets a background image. I thought that I could save my self having to edit every page for IE by doing this in the main.css stylesheet Code: * html>#navwhatever{ /*set to gif iamge instead of PNG image*/ background-image:url('image/splash_legion.gif'); } This doesn't work. It still uses the PNG images. I'd realy like not to have to edit every page to fix my site for IE, any suggestions would be great. Thanks for reading |