473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CSS Compliance and Convention...

In a stylesheet, what is the difference in writing:

div.class
{
styles:styles;
}

VS.

.class
{
styles:styles;
}


Is it just compliant to use the div.class, or span.class, or div#id, etc. when marking up your CSS? I want to a good argument for my teammates as to what convention we should use in our CSS.

Thanks,
kabrenica
Oct 1 '08 #1
6 1156
sashi
1,754 Expert 1GB
Hi Kabrenica,

In a very simple way let me put it as "HTML is used to structure content. CSS is used for formatting structured content".

Kindly refer to links below to get a better understanding of what is CSS all about and how CSS can be married to HTML. Happy coding.

http://www.w3schools.com/css/
http://www.html.net/tutorials/css/
Oct 1 '08 #2
Hi Kabrenica,

In a very simple way let me put it as "HTML is used to structure content. CSS is used for formatting structured content".

Kindly refer to links below to get a better understanding of what is CSS all about and how CSS can be married to HTML. Happy coding.

http://www.w3schools.com/css/
http://www.html.net/tutorials/css/

Thanks for these great links!

But I was wondering more about the necessity of stating the selector that you plan to use the class with.

For instance, let's say the html is:

<div class="header">Header Text</div>

AND the CSS is:

.header
{
font-size:12px;
color:#333;
}

OR I see it written as:

div.header
{
font-size:12px;
color:#333;
}

Both css declarations work, but which one is more compliant? What's the difference between explicitly stating the selector that is going to use the class declared and not stating it? This is of course assuming that the header class will also be reference with a div tag.

Does that make more sense?
Oct 1 '08 #3
drhowarddrfine
7,435 Expert 4TB
There is no difference and it's a matter of personal preference.
Oct 1 '08 #4
There is no difference and it's a matter of personal preference.
Ah, ok, thanks a bunch!
Oct 1 '08 #5
David Laakso
397 Expert 256MB
Both css declarations work, but which one is more compliant? What's the difference between explicitly stating the selector that is going to use the class declared and not stating it?

Both are valid and both are compliant.
There is a difference between them.

The difference is:
div.whatever {...}
has higher specificity than
.whatever {...}

The same is true if it were an id:
div#whatever {...}
has higher specificity than
#whatever {...}
Oct 1 '08 #6
Both are valid and both are compliant.
There is a difference between them.

The difference is:
div.whatever {...}
has higher specificity than
.whatever {...}

The same is true if it were an id:
div#whatever {...}
has higher specificity than
#whatever {...}

YES, that exactly the answer I was looking for!! Thanks for your great knowledge transfer..
-K
Oct 1 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
2
by: John Doe | last post by:
I have a webpage which shows and hides divs as a method of navigation. It works great in the ever evil IE. It works not so great (read not at all) in any standards compliant browser. I haven't...
100
by: Roose | last post by:
Just to make a tangential point here, in case anyone new to C doesn't understand what all these flame wars are about. Shorthand title: "My boss would fire me if I wrote 100% ANSI C code" We...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.