Class and ID (Full Version)

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



Message


BeTheBall -> Class and ID (3/13/2007 12:03:26)

I have a form with an ID of ws. My stylesheet contains the following:

#ws label, #ws input, #ws select {
display: block;
margin-bottom: 10px;
}

#ws label {
text-align: right;
width: 350px;
margin-right: 20px;
float: left;
}

#ws br {
clear: left;
}

I need to insert a couple of checkboxes into my form and need to override some of the above attributes. I placed the checkboxes inside a div and gave it a class name of cbGroup. However, I am finding it very difficult to override the above settings. For example, I want the text of the checkbox labels within the div to be left aligned, not right aligned. So, I added the following:

label.cbGroup {text-align:left;}

That seems to be completely ignored. Any thoughts on how to go about this?

One other major annoyance is something in the above is causing a line break between the checkbox and its label.




Tailslide -> RE: Class and ID (3/13/2007 13:48:42)

Sorry - haven't got the time to work through it at the moment Duane, instead I'll just say that styling forms can be a real pain in the arse.

My approach tends to be to keep it as simple as possible.

I put labels round the label and the input (explicit labelling) and I add a br after the text label rather than floating the text next to the input. I do this just because it's easier for me to be honest - although I don't think it looks too bad.

I give the inputs classes (text, radio, checkboxes, textareas etc) and deal with them separately.

Apart from that - here's some useful links:

http://veerle.duoh.com/index.php/blog/comments/styling_forms_in_css/
http://www.themaninblue.com/experiment/InForm/horizontal.htm
http://www.456bereastreet.com/archive/200410/styling_even_more_form_controls/
http://www.websemantics.co.uk/tutorials/accessible_forms/




BeTheBall -> RE: Class and ID (3/13/2007 14:53:11)

Thanks Helena. I was able to track down the problems. First, it seems that a style assigned to an ID will generally override one that is part of a class. So, I modified my stylesheet to replace the style I had assigned to an id with a class style.

Getting the label to not fall below the checkbox was giving me fits until I realized I was placing the float:left on the wrong element. I was putting it on the label when I needed it on the checkbox. Once I moved it where it needed to be, everything fell into place.

I try to not get too fancy with my forms, but one thing I hate is when a long checkbox label wraps below the checkbox. It just looks bad to me. So, that is what all the fuss was about.




coreybryant -> RE: Class and ID (3/17/2007 18:05:19)

Just in case, this one really helped me out actually last week Form Layout Example




Tailslide -> RE: Class and ID (3/18/2007 2:58:38)

Ah thanks for finding Gary's form example Corey! I lost all my bookmarks a while back and haven't found a quarter of what I lost.




coreybryant -> RE: Class and ID (3/18/2007 9:45:20)

Glad to have helped.. I just had the same problem a few weeks ago and it surely helped me. It kept it very simple




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.109375