This question already has answers here:
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?
(8 answers)
CSS - First child without certain class
(4 answers)
CSS selector for first element with class
(23 answers)
Closed 3 years ago.
With CSS is it possible to target the first child that hasn't got a class
<div class="parent">
<p class="hidden">Paragraph 1</p>
<p class="hidden">Paragraph 2</p>
<p>Paragraph 3</p>
<p>Paragraph 4</p>
</div>
So something like this ...
.parent p:not(.hidden):first-child {
color:#ff0000
}
The desired effect would be that paragraph 3 would now be red
Related
This question already has answers here:
Is there a CSS parent selector?
(33 answers)
How to affect other elements when one element is hovered
(9 answers)
Closed 1 year ago.
I want to select a non-descendant element with css on hover. To be more precise, when I hover on the image with id="tapas", I want to change the visibility of the text with id="cuerpo".
<div id="tapa">
<div class="imgagenes">
<img src="img/tapas.jpg" id="tapas">
<img src="img/tapitas.jpg" id="tapitas">
</div>
<div class="text">
<p id="cuerpo">
There is text here
</p>
</div>
</div>
Some time before I had the text in the same div, with id="imgagenes", but I don't want that right now. Therefore, I had this command on css:
#tapas:hover ~ p {
visibility: visible;
}
This question already has answers here:
What does the "+" (plus sign) CSS selector mean?
(9 answers)
What does the "~" (tilde/squiggle/twiddle) CSS selector mean?
(3 answers)
Closed 2 years ago.
I need to add a selector in css to bold the paragraph adjacent to the goals_container id.
Html code looks like:
<body>
<main>
<div id="goals_container">
</div>
<p> This is what I want to access </p>
</main>
</body>
You need the + (adjacent sibling) selector:
#goals_container + p {
background: tomato;
}
<body>
<main>
<div id="goals_container">
</div>
<p> This is what I want to access </p>
</main>
</body>
This question already has answers here:
CSS: How to say .class:last-of-type [classes, not elements!] [duplicate]
(2 answers)
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?
(8 answers)
Closed 3 years ago.
Without knowing a structure of html, I would like to select the last element .foo inside .main. In other words the closest element of class .foo to closing tag of .main.
<div class="main">
<div class="foo a">
a
</div>
<div class="foo b">
b
<div class="foo c">
c - select only this (last .foo among all descendants)
</div>
<div class="d">
d
</div>
</div>
</div>
Of course I can .main > .foo > .foo but I want a generic solution.
This question already has answers here:
CSS selector for first element with class
(23 answers)
Closed 5 years ago.
I've wrote this in HTML:
<div> hello</div>
<div class="name"><p>hello</p></div>
<div class="name"><p>hello</p></div>
and this in CSS:
div.name:first-child{
color: red;
}
I would like to change text color of second 'hello' to red. But it doesn't work. What I am doing wrong?
it's the second child, not the first, use nth-child:
div.name:nth-child(2){
color: red;
}
<div> hello</div>
<div class="name"><p>hello</p></div>
<div class="name"><p>hello</p></div>
This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Closed 7 years ago.
I would like to know how to style an element according to his son.
.content p {
text-indent: 20;
}
<div class="content">
<p>1</p>
<p>2</p>
<p>
<iframe></iframe>
</p>
<!--I have to modify this paragraph-->
<p>4</p>
</div>
What do I need to do, is to modify the paragraph that has the iframe (text-indent: 0).
The best is to write something like
<p class="custom">...</p>
Then add style with
p.custom{
/* Your styles here */
}