472,958 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

#Intro or .Intro?

Hello,

When styling a DIV as follows:

<div id="intro" class="Intro">Some intro text</div>

Should I use a class:
..Intro {...}

Or:
#Intro {...}

As far as I know if this div is unique I should use #Intro, if their
styles are not unique I should use .Intro.

But I read somewhere that I should use always .Intro and not
#Intro ...

Just checking.

Thanks,
Miguel
Jun 27 '08 #1
6 4377
On 2 Jun, 13:36, shapper <mdmo...@gmail.comwrote:
<div id="intro" class="Intro">Some intro text</div>

Should I use a class:
.Intro {...}

Or:
#Intro {...}
Select on the class. (Fairly) commonly discussed issue in this ng.

This doesn't affect the HTML though, it's quite reasonable to use both
in the document markup.
Jun 27 '08 #2
On 06/02/08 05:36 am, shapper wrote:
>
<div id="intro" class="Intro">Some intro text</div>

Should I use a class:
.Intro {...}

Or:
#Intro {...}
The advantage of #Intro:
- It can be linked as fragment <a href="#Intro">.
- Javascript can find it with DOM

Disadvantage:
- Must be unique

In general I prefer using a class unless one of the advantages for an ID
are compelling.

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Jun 27 '08 #3
Jim Moe wrote:
On 06/02/08 05:36 am, shapper wrote:
><div id="intro" class="Intro">Some intro text</div>

Should I use a class:
.Intro {...}

Or:
#Intro {...}
If you have id="intro" as above, #Intro won't match it. IDs and class
names are case-sensitive.
The advantage of #Intro:
- It can be linked as fragment <a href="#Intro">.
- Javascript can find it with DOM
- Its specificity in the CSS cascade is higher than that of .Intro.
Jun 27 '08 #4
Andy Dingley wrote:
On 2 Jun, 13:36, shapper <mdmo...@gmail.comwrote:
><div id="intro" class="Intro">Some intro text</div>

Should I use a class:
.Intro {...}

Or:
#Intro {...}

Select on the class. (Fairly) commonly discussed issue in this ng.

This doesn't affect the HTML though, it's quite reasonable to use both
in the document markup.

Is that really the consensus here?

I don't see any hard and fast rules for naming conventions (aside
from only one ID per page).

I like to name these things to increase readability. If I assign an
ID to something, I know that it is a section of the page. Classes I
reserve for presentation issues. Others are more comfortable with
everything as a class.

I'm happiest with stylesheets that have almost no classes, with nearly
everything styled as a descendant of a section.

Jeff
Jun 27 '08 #5
shapper schreef:
Hello,

When styling a DIV as follows:

<div id="intro" class="Intro">Some intro text</div>

Should I use a class:
..Intro {...}

Or:
#Intro {...}

As far as I know if this div is unique I should use #Intro, if their
styles are not unique I should use .Intro.

But I read somewhere that I should use always .Intro and not
#Intro ...

Just checking.

Thanks,
Miguel
I would say .intro to say: this is of that type (it is an introduction)
And use #intro to say: this is that element (it is the introduction).

So for styling... it the depends a bit on how you look at it. It might
be unique in this case but you merely say it is of type intro. Therefore
I would prefer the class .intro in this case.

Sometimes I use both and then I use #intro for the positioning and
..intro for the styling. But that might be unneccesary overhead.
Jun 27 '08 #6
In article <2u******************************@giganews.com>,
Jim Moe <jm***************@sohnen-moe.comwrote:
On 06/02/08 05:36 am, shapper wrote:

<div id="intro" class="Intro">Some intro text</div>

Should I use a class:
.Intro {...}

Or:
#Intro {...}
The advantage of #Intro:
- It can be linked as fragment <a href="#Intro">.
- Javascript can find it with DOM

Disadvantage:
- Must be unique
Yes, good. I would add an extra advantage to using an id when the author
is consciously meaning to only have one reference per page. It helps the
author keep better track of what he is doing, it is information for him.

--
dorayme
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kamus of Kadizhar | last post by:
I'm looking for a good intro to python book. I'm very familiar with programming, but know nothing of OOP or systems (OS type) programming. All of my programming experience is in number crunching...
13
by: Alf P. Steinbach | last post by:
The third part of my attempted Correct C++ tutorial is now available, although for now only in Word format (use free Open Office if no Word), and also, it's not yet been extensively reviewed -- ...
2
by: Chad | last post by:
I'm in an intro to VB.net class. I'm haveing trouble with this assignment, if anyone could help me please let me know. thanks! Coding Assignment 7-Chapter 8 OOP-CSCI-171 Intro to VB.NET ...
3
by: Guy Middleton | last post by:
A friend want to learn C, and is already an experienced programmer -- she knows VB and Java, and some application-specific HLLs (e.g. ToolBook). Could somebody recommend an intro C text I could...
7
by: TechBookReport | last post by:
TechBookReport have just published a review of 'C Programming In Easy Steps', if you're a C beginner looking for an intro book (or an ex-C developer looking for a quick refresh), ready why this is...
3
by: SStory | last post by:
I just saw an intro video on Whidbey Alpha from http://www.learnvisualstudio.net/shortcut/0806c.htm. I am sort of aggravated with Microsoft in that no one can ever become proficient with your...
1
by: Tara | last post by:
intro about Asp ..help -------------------------------------------------------------------------------- HI All , i am not into development ...i am into testing actually ... So just for...
1
by: annabel59 | last post by:
I made a Flash intro for my website but when I open it in IE7 it gives error : expected object. It works fine in Mozilla. This is the code of the index.html file : <html> <head>...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.