• Lucid Dreaming - Dream Views




    Results 1 to 3 of 3
    1. #1
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      Please do. I know basic stuff with CSS like colours, fonts, sizes, etc.

      But there are sites nowadays (in fact, it seems to become the standard) that just don't use tables or whatever at all - Just div's, ul's and li's.

      I wouldn't know how to do that. I've been using tables for all my days, and it's not that I'm conservative or something, so I'd like to know how to use div/ul/li's + CSS to style make proper websites (that are much more efficient in terms of bandwith too). Google doesn't get me anything useful either. :/

      Tell me.

    2. #2
      Member Kaniaz's Avatar
      Join Date
      Jan 2004
      Gender
      Location
      England
      Posts
      5,441
      Likes
      9
      Alright. CSS and XHTML (at least that's what they call it theseadays) are not becoming much more of a standard, statistics have shown, but this is not to say that they shouldn't. I'm very much preaching to the converted when I say that using CSS and XHTML will make your life easier, evidently, but it still needs to be said.

      There are relatively few occasions, if any, when you need to use a <table>. They are the scourge of the universe, the underdog that deserves to be right under and frankly a bastard baby of the wars between Netscape/IE. You don&#39;t need them to create a sidebar, a header, or to lay anything out.

      Let&#39;s consider those elements dead and buried.

      0. Being &#39;Valid&#39;
      The first thing in creating any wonderful "standards compliant" website is the DOCTYPE declaration. Without it, IE 7 and all other browsers stay in quirks mode. This is when they render your HTML with whatever particular archaic bugs people have come to rely on they have in their rendering engine, instead of how things "should" be. Frankly, it&#39;s a nightmare until you add this:
      Code:
      &#60;&#33;DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Strict//EN&#34; &#34;http&#58;//www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#34;&#62;
      And this will boot IE7, Firefox and any other sane browser into realizing that you are going to be using "pure" (i.e. strict) XHTML and CSS, and rendering standards complaint as such.

      1. Style And Content
      The point of XHTML/CSS is that you are trying to separate content, the actual text of your website, from presentation. Sites from 1997 or so tend to have HTML that looks a whole lot like this:
      Code:
      &#60;font color=&#34;red&#34; face=&#34;Verdana&#34; size=&#34;10&#34;&#62;&#60;center&#62;&#60;u&#62;Welcome To My Website&#60;/u&#62;&#60;/center&#62;&#60;/font&#62;
      Here, content is buried under all the tags that need to be used to present the actual text. That can be better expressed in XHTML, that is, purely content and tags, as:
      Code:
      &#60;h1&#62;Welcome to my website&#60;/h1&#62;
      With you having your accompanying CSS selector and styling as such:
      Code:
      h1
      {
      font-family&#58;Verdana;
      color&#58;#ff000;
      text-align&#58;center;
      }
      This does the same thing, but will save on bandwidth (if you&#39;re using the same style over and over) and makes your HTML readable. It&#39;s perfectly acceptable to still have <h1>, <div>, [i], <cite> kind of tags, but not deprecated and annoying ones that concern themselves purely with presentation like <center>, <font> and so on.

      2. Cascading
      The &#39;C&#39; in CSS stands for - you guessed it - cascading. You can have separate stylesheets which will &#39;cascade&#39; - the most recently defined style for an object overrides any other definition made before it. The advantage of this may not be entirely obvious until you consider a scenario where you are a big website developer for someone like, say, Microsoft.

      Microsoft has an overriding theme on their site - the same sort of header, font and so on - but has quite a few differences on each page to brand it to whatever they might be selling. Orange for Office, Blue for Windows, Gray for Mac software and so on. So you can have a &#39;main&#39; stylesheet, say main.css which deals with the normal theme and secondary stylesheets: &#39;office&#39;, &#39;windows&#39;, &#39;vista&#39;, &#39;xbox&#39; which don&#39;t have to redefine anything in main.css, saving on bandwidth and making the site more maintainable, but can still customise the theme and change backgrounds etc.

      Thus you get a cleaner site, presentation seperated from content and a much more accessible site. (This is something Microsoft has ironically not done). And yes, the final point:

      3. Accessiblity.
      Frankly, just using CSS and XHTML makes your life a lot easier, and the life of those who might not find it as easy to browse the internet. It&#39;s a nice thing to do, not just for yourself.

      Making a "proper" website is really just as easy as removing all presentation tags, replacing them with containers like:
      Code:
      &#60;div id=&#34;menu&#34;&#62;&#60;/div&#62;
      Code:
      &#60;ul class=&#34;quotes&#34;&#62;&#60;/ul&#62;
      Code:
      &#60;blockquote class=&#34;important&#34;&#62;&#60;/blockquote&#62;
      And then styling them. You can use each one several times with the power of the different selectors.

      Tag global: (very global)
      Code:
      strong { color&#58;red; }
      "All bold text appears red."

      This also works for tags like body.

      Class:
      Code:
      .important { color&#58;red; }
      Any tag that class="important" appears in red.

      ID: (most localised)
      Code:
      #menu { position&#58;absolute; top&#58;10px; }
      The menu appears 10px from the top of the page.

      The only real "crime" you can commit with CSS easily is overusing ids or most specific selectors and cluttering up your HTML when you don&#39;t need to.

      Take for a quick example my site&#39;s front page:

      Code:
      &#60;&#33;DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Strict//EN&#34; &#34;http&#58;//www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#34;&#62;
      &#60;html&#62;
      
      ****&#60;head&#62;
      ********&#60;title&#62;Kaniaz&#60;/title&#62;
      ********&#60;link rel=&#34;shortcut icon&#34; href=&#34;/common/img/favicon.png&#34; type=&#34;image/x-icon&#34;/&#62;
      ********&#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;/common/css/main.css&#34;/&#62;
      ********&#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;/style.css&#34;/&#62;
      ****&#60;/head&#62;
      
      ****&#60;body&#62;
      ********&#60;div&#62;&#60;/div&#62;
      
      ********&#60;ul&#62;
      ************&#60;li&#62;&#60;a href=&#34;/programs&#34; title=&#34;All sorts of wonderful C++, C# and PHP programs for your pleasure&#34;&#62;programs&#60;/a&#62;&#60;/li&#62;
      ************&#60;li&#62;&#60;a href=&#34;/writelog&#34; title=&#34;Never to be explained or understood by the public&#34;&#62;writelog&#60;/a&#62;&#60;/li&#62;
      ************&#60;li&#62;&#60;a href=&#34;/media&#34; title=&#34;Random images and/or crap that needed a home somewhere&#34;&#62;media&#60;/a&#62;&#60;/li&#62;
      ************&#60;li&#62;&#60;a href=&#34;/about&#34; title=&#34;Just what is this site about? Who are you? Who am I?&#34;&#62;about&#60;/a&#62;&#60;/li&#62;
      
      ********&#60;/ul&#62;
      ****&#60;/body&#62;
      
      &#60;/html&#62;
      You can note the use of cascading stylesheets: I have a main stylesheet which sets the background colour, default font and so on and then a secondary stylesheet which deals with specific styling with the front page.

      Everything is content. There no need for id="menu" or id="header" because there&#39;s only one div (header), only one ul (menu) and all the lis (list elements) can be styled the same. When you can, you should always try and do things as simple as possible.

      You can style all the h&#39;s - h1, h2, h3, h4... to your liking, make use of [b] and [i]. There&#39;s no "right" way to do things, but once you understand CSS and it &#39;clicks&#39;, it&#39;s suddenly one of the most powerful ways of getting the browser to show things how you want it to.

    3. #3
      The 'stache TweaK's Avatar
      Join Date
      Jul 2006
      Location
      The Netherlands
      Posts
      1,979
      Likes
      12
      Thanks Niaz, that post&#39;s definately a great help - Although I knew a large part of it, it will now actually make me use these things in practice.

      Especially the seperate content and style thing is super useful - Thanks a lot.*

      * Have my babies. Or maybe I want yours. Or maybe we should exchange them?&#33;

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •