I have been getting to grips with css recently (very slowly), and one area I
have a problem is when to use class selectors or id selectors. Are there any
guidelines when to use each type ? The key difference is, AFAICS, is that id
selectors can only be used once, whereas class selectors can be used
repeatedly ? Is this the main differentiator ?
Regards
Tony B 1 2620
Tony Benham wrote: I have been getting to grips with css recently (very slowly), and one area I have a problem is when to use class selectors or id selectors. Are there any guidelines when to use each type ? The key difference is, AFAICS, is that id selectors can only be used once, whereas class selectors can be used repeatedly ? Is this the main differentiator ?
Well from a technical point of view, yes. But that doesn't mean that if you
only have one you should use id. Think of it this way:
id="foo" => This element is called 'foo'
class="foo" => This element is of type 'foo'
Now just because there may be only one element of type 'foo' on the page, it
doesn't mean that the element's _identity_ is 'foo'. Apart from anything
else, it's a pain to change it all around when you decide to add another
element of that class to a document.
There is also a difference in the way specificity is computed. Selectors
with ids in are more specific than selectors with classes in.
--
Jim Dabell This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stoic |
last post by:
Hi, I'm relatively new to CSS. I'm trying to get all the urls in a group of text bracketed by
<p></p> tags to be underlined and everywhere else to NOT be underlined. As of now my code is
like this...
A {color: #003366; font-size: 14px; text-decoration: none;}
Which solves the second requirement but not the first. I don't want to have to put a style
reference in every <a> statement enclosed by a <p> on my site. There are many, many...
|
by: Jeff Thies |
last post by:
We can do this:
<tr class="data odd">
Can we make a rule that applies when only both classes are present?
I suppose I could do this:
<table class="data">
|
by: Robert |
last post by:
Stephen,
I think I figured out the problem. I was able to get Check Boxes and Option
Buttons to work on my form by TURNING OFF RECORD SELECTORS on the form. Not
sure why this would make a difference. Perhaps Access attributes the hWnd
of the form to the Record Selector if these are turned on.
In any case, I ran some tests on your Customers form and sure enough, a
Check Box or Option Button will work fine until you turn on Record...
|
by: Rhino |
last post by:
What's the simplest way to determine which, if any, of my selectors are not
needed in a given stylesheet?
I have a small number of HTML pages that share two stylesheets; one
stylesheet is for display purposes and one is for printing. I suspect that
some of the selectors in my stylesheet are no longer needed due to deletions
of parts of the HTML pages and would like to remove those selectors from my
stylesheets. But I'd like to avoid a...
|
by: planb |
last post by:
Hi,
I'd like to have a rollover like effect when a input field has the
focus, any idea of how to do this with just CSS (easy enough with
javascript)?
What I'm thinking of is having a tips box show up next to the input
field, but only when the field actually has focus.
I was thinking if there's any way to make the focus apply to a
| |
by: PJ6 |
last post by:
Is there a way of specifying the CSS class of all cells within a table
without having to set the class attribute for each cell individually
(server-side or client-side)?
Paul
|
by: pbd22 |
last post by:
In a manner of speaking.
I just want to know if it is possible to style a page
without using the class attribute? If so, how is this
done?
Thanks.
|
by: John Dann |
last post by:
I'm unclear as to how best to use what I'm terming the top-level CSS
selectors, by which I mean selectors like *, html and body. I'm coming
at this from trying to understand how best to set font sizes but I
seem to have strayed into a broader question.
Some CSS guides seem to suggest that a * declaration is good practice
for any style sheet, primarily I suppose to set zero defaults for
margin and padding for all other relevant selectors...
|
by: Roedy Green |
last post by:
The only browser I have encountered that supports
<colgroup><col class="behold"></colgroup>
to apply a CSS style to a whole column, is Microsoft Internet
Explorer. I have been told it SHOULD NOT do so, since this is not
part of the specification.
How then to you apply styles to entire columns? Surely you don't have
to write
<td class="behold"on every row item.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |