How to select multiple ids in CSS?
Use an attribute selector
on the id
attribute:
[id^='test_id_'] { color: red; }
Description:
[attr^=value]
represents an element with an attribute name ofattr
and whose first value is prefixed by "value".
How to access two Ids in one css selector
#buttons input:nth-child(2), #buttons input:nth-child(3){
margin-left:5px;
}
does this work for you ?
or simply:
#Cancel, #add{
margin-left:5px;
}
With ,
seperation you start a complete new CSS Selector and combine them.
Use multiple IDs for divs in CSS
You have to put
#box-left a, #box-middle a, #box-right a {
text-decoration:none;
color:#000000;
}
Each value on the comma separator list is a selector on its own, it is not combined with the next elements:
#foo, .class p, #bar p:first-child a {
something;
}
is equivalent to
#foo {
something;
}
.class p {
something;
}
#bar p:first-child a {
something;
}
Is it possible to have multiple ID selectors in CSS
To answer your question, it works cross browser, and what you wrote is correct. Only "More stuff" will be in red.
But it is not recommended to use ID's for styling.
A nice reference to read more about this can be found here. The entire article is a great read by the way, if you want to learn more about writing good CSS!
The most important part of it, concerning IDs is:
- IDs can never be used more than once in a page.
- Classes can exist only once, or a million times in a page.
- IDs can often have their traits abstracted out into many reusable classes.
- An ID is infinitely more specific than a class.
- This means no amount of chained classes can override an ID.
Selecting multiple CSS ids with only 1 number changing on each
You can use the attribute selector: [attr*=value]
:
[id*=edit-add-to-wishlist] {
color: red;
}
jsFiddle here - it works
It selects all instances where a id
contains edit-add-to-wishlist
[attr*=value]
Represents an element with an attribute name of attr and whose value contains at least one occurrence of string "value" as substring.
MDN documentation on the attribute selector
Css code for multiple Ids
If I understand you correct, the a
-tag is a child of your #btn*
-tags. Than you need to write your code like this:
#btn1, #btn2, #btn3
{
background-color: #003399;
color: #FFF;
}
#btn1 a:hover,
#btn2 a:hover,
#btn3 a:hover
{
color:#3cf;
}
In this case the color
property will be applied to the a
-tag in the#btn*
-tags if the mouse hovers the a
-tag.
It is also possible to apply the color
property to the #btn*
-tag if the mouse hover them:
#btn1:hover,
#btn2:hover,
#btn3:hover
{
color:#3cf;
}
You should read a Little bit more about CSS Selectors. There is a good overview on Wikipedia.
How to apply CSS elements property on multiple ids or class
Your first 4 rules select only the elements with id's #id1, #id2 etc.
Each comma separated part in the selector is a selector independent of other selector segments. So, you cannot use first selector as basis for following selectors.
select#id1 option:disabled,
#id2 option:disabled,
#id3 option:disabled,
#id4 option:disabled,
#id5 option:disabled{
}
In plain css, I don't think you can avoid specifying option:disabled
multiple times (except using class instead of id). You can give your select elements a common class e.g. myselect
, and then write a single rule instead of this, like -
.myselect option:disabled{
}
CSS selector for multiple ids in one line (like [id=abc-1 - abc-10]:checked + label)
so you can do
[id^="abc-"]
which basically selects all elements which have an id attribute starting with abc-
Related Topics
CSS Media Queries and Size of Images
How to Implement Bootstrap 4 and Rails 5
How to Keep Text Opacity 100 When Its Parent Container Is Having Opacity of 50
How to Get Rid of White Spaces Between Spans Without Manipulating The HTML
Use a Remote Stylesheet Inside a Template Tag (With Shadow Dom)
Resource Interpreted as Stylesheet But Transferred with Mime Type Text/HTML
How to Change Colour in CSS, by Giving Condition
CSS Text Replace with Image, Need Hyperlink
Where Should I Use CSS Vendor Prefixes
Ckeditor Add CSS Styling to Preview and Editor
Vertical-Align: Middle with Bootstrap 2
Why <Big> Is Not in HTML 5 Tag List While <Small> Is
Position Fixed Not Working in Safari Version 8.0.2
Nested Flexboxes Works Differently Across Browsers
How to Stop a CSS Keyframe Animation
How to Set This Div to Be The Minimum Possible Width to Display Its Floating Contents