Cascading (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


BeTheBall -> Cascading (4/13/2007 15:34:53)

Seems to be the cascading part I just don't get. I have a form with a class of frm. Here is part of my stylesheet that deals with form labels:

.frm label, .frm input, .frm select {
display: inline-block;
margin-bottom: 10px;
}

.frm label {
float:left;
margin-right:5px;
text-align:right;
font-weight:bold;
width:200px;
}

I am trying to overwrite the width and text align values in just one label. So I inserted into that label a class attribute of "wider" and put this in my stylesheet:

.wider {width:400px;text-align:left;}

However, it still inherits the values from the frm class. [:@]

Also, can someone give a quick summary of why some attributes are coded as html element . class name and others are . class name html element? For example, I have a form button in my stylesheet that looks like this:

input.submit {
background: #E0691A url(../images/submit.gif) no-repeat;
border: 0;
padding: 4px 0;
width: 65px;
margin: 0 15px 1px 0;
color: #FFF;
font: bold 1em Arial, Sans-Serif;
}

Other items are like this:

.bar li {
margin: 0;
padding: 7px 12px 5px 12px;
color: #FFEADC;
background: #FF9148;
float: left;
}

What determines where the "." goes?




jaybee -> RE: Cascading (4/13/2007 19:08:56)

It's all a bit head banging isn't it. I have a pile of notes I've made but they're not typed up. I must get round to doing it. Take a look at this but make sure you have a clear head.

http://www.w3.org/TR/REC-CSS2/cascade.html




jaybee -> RE: Cascading (4/13/2007 19:19:36)

This is a bit clearer
http://htmlhelp.com/reference/css/structure.html




markhawker -> RE: Cascading (4/13/2007 19:57:58)

OK, so CSS...

There are 5 main types of selectors:

  • Simple selectors are just an element name e.g. h1{}
  • Class selectors allow different styles for the same element e.g. p.wide{} or p.narrow{}
  • Generic selectors apply to content of more than one element e.g. .wide{} could apply to a p or h1 etc.
  • ID selectors apply to one specific element e.g. #wide with <p id="wide">Foo</p>
  • Pseudo class selectors add special effects to some selectors e.g. a:hover{} or see more at http://www.w3schools.com/css/css_pseudo_classes.asp

CSS interprets those from top to bottom and so a simple selector would be overridden by the latter ones. In your example you are applying your style to EVERY label element, to apply to just one you should use an ID selector such as <label id="foo" ...>Bar</label> .frm label#foo. Technically, you should have form.frm as the CSS class.

Does that clear things up? By not prefixing classes you are applying them to ANY element. I always use class or simple selectors, and use generic selectors a lot less.

It's not that hard really once you take in those selectors I mentioned.




jaybee -> RE: Cascading (4/13/2007 20:36:00)

Duane, now your head has exploded, I suggest you do as Mark obviously does and as I do, keep it simple. Unless you have a real requirement to get jiggy with more complicated pseudo classes and elements, don't.

I once decided to put together a really cool stylesheet that was as tight as I could get it. Six months down the line I needed to make a change to it and I nearly went nuts.




BeTheBall -> RE: Cascading (4/13/2007 22:59:47)

I threw the size and alignment attributes inline and that works. I will work on the stylesheet as I go. I just thought that if I had a class in a form and another class in an element inside the form that the class in the element would take priority in any conflict. Obviously I misunderstood the full meaning of cascading.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.03125