What is syntax for selector in CSS for next element?
This is called the adjacent sibling selector, and it is represented by a plus sign...
h1.hc-reform + p {
clear:both;
}
Note: this is not supported in IE6 or older.
How to get the next element after the .active class
Just use the adjacent sibling selector +
, you don't need the nth-child
selector:
.active + li { color: red;}
<ul> <li class="active">Item</li> <li>Item</li> <li>Item</li></ul>
How do I select the next item after a target element in css?
It will not work, if you use the attribute "name" and then look for "id" in your CSS.
[id]:target { background:pink; }[id]:target + b { background:pink; }
<a id="a">A</a><b>B</b><a href="#a">Turn pink!</a>
Is there a previous sibling selector?
No, there is no "previous sibling" selector.
On a related note, ~
is for general successor sibling (meaning the element comes after this one, but not necessarily immediately after) and is a CSS3 selector. +
is for next sibling and is CSS2.1.
See Adjacent sibling combinator from Selectors Level 3 and 5.7 Adjacent sibling selectors from Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification.
can :next-of-type be synthesized?
So it is possible, but in addition to knowing a complete list of the types of elements in the grid, and a maximum span of elements between elements of the same type, it would be really handy to have a macro-processor to generate the synthesized solution.
The snippet below deals only with two types of elements, and a maximum of 5 elements between elements of the same type, but could obviously be laboriously extended in either dimension.
.container { display: grid; font-size: 30px; grid-template-areas: ". . ." ". . ." ". . ."; } .special ~next-of-type { color: red; } a-.special + a- { color: red; } a-.special + :not( a- ) + a- { color: red; } a-.special + :not( a- ) + :not( a- ) + a- { color: red; } a-.special + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: red; } a-.special + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: red; } a-.special + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: red; } b-.special + b- { color: red; } b-.special + :not( b- ) + b- { color: red; } b-.special + :not( b- ) + :not( b- ) + b- { color: red; } b-.special + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: red; } b-.special + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: red; } b-.special + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: red; }
.ordinary ~next-of-type { color: blue; } a-.ordinary + a- { color: blue; } a-.ordinary + :not( a- ) + a- { color: blue; } a-.ordinary + :not( a- ) + :not( a- ) + a- { color: blue; } a-.ordinary + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: blue; } a-.ordinary + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: blue; } a-.ordinary + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: blue; } b-.ordinary + b- { color: blue; } b-.ordinary + :not( b- ) + b- { color: blue; } b-.ordinary + :not( b- ) + :not( b- ) + b- { color: blue; } b-.ordinary + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: blue; } b-.ordinary + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: blue; } b-.ordinary + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: blue; }
.surprise ~next-of-type { color: orange; } a-.surprise + a- { color: orange; } a-.surprise + :not( a- ) + a- { color: orange; } a-.surprise + :not( a- ) + :not( a- ) + a- { color: orange; } a-.surprise + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: orange; } a-.surprise + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: orange; } a-.surprise + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + :not( a- ) + a- { color: orange; } b-.surprise + b- { color: orange; } b-.surprise + :not( b- ) + b- { color: orange; } b-.surprise + :not( b- ) + :not( b- ) + b- { color: orange; } b-.surprise + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: orange; } b-.surprise + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: orange; } b-.surprise + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + :not( b- ) + b- { color: orange; }
<h1>next-of-type synthesized</h1> <div class=container> <a->1</a-> <a->2</a-> <b- class="special">3</b-> <a->4</a-> <a- class="ordinary">5</a-> <a- class="surprise">6</a-> <b->7</b-> <b->8</b-> <a->9</a-> </div>
Related Topics
How to Remove the Underline For Anchors(Links)
Text-Overflow: Ellipsis Not Working
Link with Target="_Blank" and Rel="Noopener Noreferrer" Still Vulnerable
Jenkins - HTML Publisher Plugin - No CSS Is Displayed When Report Is Viewed in Jenkins Server
Do You Have to Include <Link Rel="Icon" Href="Favicon.Ico" Type="Image/X-Icon" />
How to Allow Only One Radio Button to Be Checked
Expand Div to Max Width When Float:Left Is Set
Add Padding at the Beginning and End of Each Line of Text
HTML Email - Is Colspan Allowed
Nesting <A> Inside <Button> Doesn't Work in Firefox
HTML Select Box Options on Hover
Why Are Button's Discouraged from Navigation
Using Display Inline-Block Columns Move Down
How to Rotate and Postion an Element on the Top Left or Top Right Corner
How to Fill a Div with an Image While Keeping It Proportional
Best Way to Include Css? Why Use @Import
How to Center an Element in the Middle of the Browser Window