Author Topic: CSS discussion  (Read 2432 times)

Spriggan

  • Administrator
  • Level 78
  • *****
  • Posts: 10582
  • Fell Points: 31
  • Yes, I am this awesome
    • View Profile
    • Legacies Lost
CSS discussion
« on: July 10, 2006, 02:14:40 PM »
Hey Skar here's that code I was talking about that lets you tell IE which style sheet you want to use based off of the browser version.  These are called Conditional Comments, more about them here.

<link rel="style sheet" type="text/css" href="styles/unicity.css" />

<!--[if IE 6]>
<link rel="style sheet" type="text/css" href="styles/unicityIE6.css" />
<![endif]-->


That goes in your header, the first style sheet brought it works in IE 7, FF and opera so it loads it first then it check to see if the browser is IE6 and if it does it loads the second Style Sheet.  Since CSS always uses the most recently loaded rule the second style sheet supersedes the first.  If you want to run a IE only (regardless of browser) check you would just use:

<!--[if IE]>
<link rel="style sheet" type="text/css" href="styles/unicityIE6.css" />
<![endif]-->


That code only works in IE, all other browsers ignore it.

Screw it, I'm buying crayons and paper. I can imagineer my own adventures! Wheeee!

Chuck Norris is the reason Waldo is hiding.


Skar

  • Moderator
  • Level 54
  • *****
  • Posts: 3979
  • Fell Points: 7
    • View Profile
Re: CSS discussion
« Reply #1 on: July 10, 2006, 04:48:24 PM »
Cool.  Thanks Sprig.
"Skar is the kind of bird who, when you try to kill him with a stone, uses it, and the other bird, to take vengeance on you in a swirling melee of death."

-Fellfrosch

Spriggan

  • Administrator
  • Level 78
  • *****
  • Posts: 10582
  • Fell Points: 31
  • Yes, I am this awesome
    • View Profile
    • Legacies Lost
Re: CSS discussion
« Reply #2 on: July 10, 2006, 06:34:04 PM »
NP.  Let me show you another cool trick.

To make sure you page is always centered no matter what brower and screen resolution.

CSS code:

Code: [Select]

body{
text-align:center;
}

#page{
text-align:left;
}


then make #page (or what ever you want to call it) the main div wrapper around your page (ie the first thing after the body tag).  Note that this won't work if you have in the wrapper a float or position element.
Screw it, I'm buying crayons and paper. I can imagineer my own adventures! Wheeee!

Chuck Norris is the reason Waldo is hiding.


Spriggan

  • Administrator
  • Level 78
  • *****
  • Posts: 10582
  • Fell Points: 31
  • Yes, I am this awesome
    • View Profile
    • Legacies Lost
Re: CSS discussion
« Reply #3 on: July 10, 2006, 06:43:26 PM »
And one more, this is something that threw me through loops for ever, getting multi-columned pages to always set the columns to the same height without using JS.

CSS:
Code: [Select]

#container {
     width: 100%;
     height:100%;
     overflow:hidden;
}


/*columns*/

#left_column{
     width: 150px;
     float:left;
     left: 0px;
     top: 0px;
           padding-bottom: 32767px;
     margin-bottom: -32767px;


}

#center_column{
     margin-right: 150px;
     margin-left: 150px;
     
padding: 0px 10px 0px 10px;
     
}


#right_column{
     float:right;
     right: 0px;
     top: 0px;
     width:150px;
           padding-bottom: 32767px;
     margin-bottom: -32767px;
}



HTML:

Code: [Select]

<body>
<div id="container">

<div id= "left_column">
Left column content
<!--ends left column-></div>

<div id= "right_column">
Right column content
<!--ends right column-></div>

<div id= "center_column">
center column content
<!--ends center column-></div>

<!--ends container-></div>
</body>


The funky margin numbers and the overflow being set to hidden keep columns all the same size while not showing the extra 3000+px stuff.

The only precaution is to make sure the last column listed in the HTML order (in this case the center one) doesn't have the huge margins or padding.

So these two posts are two things I wish I knew months ago and are some of the more frequently asked questions when it comes to page layout and CSS.
Screw it, I'm buying crayons and paper. I can imagineer my own adventures! Wheeee!

Chuck Norris is the reason Waldo is hiding.