This question already has answers here:
What CSS selector can be used to select the first div within another div
(4 answers)
Why doesn't nth-of-type/nth-child work on nested elements?
(1 answer)
Closed 2 years ago.
Hi can you please help with some css,
I have this code
<div>
<div>
<input class="test"/>
</div>
</div>
<div>
<div>
<input class="test"/>
</div>
</div>
<div>
<div>
<input class="test"/>
</div>
</div>
I want to change some properties only in my first input, can somebody help me solve this ?
Thanks
In your case, you can use these css rules:
div:nth-child(1) div input.test {
color: green;
}
or
div:first-of-type div input.test {
color: green;
}
Related
This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Closed last month.
Good day all,
I have an a tag with class "WORKSHEET_block" and which is contained in 3 other div.
The css to style is (which does not work):
.WORKSHEET_block < .fc-daygrid-event-harness < .fc-daygrid-day-events < .fc-daygrid-day-frame {
background-color: green !important;
}
<div class="fc-daygrid-day-frame">
<div class="fc-daygrid-day-events">
<div class="fc-daygrid-event-harness">
<a class="WORKSHEET_block">My Value</a>
</div>
</div>
</div>
I know if it was the other way around from parent to child we would use ">" from the parent to the child.
Is there anywhere I can select the parent from the child?
.fc-daygrid-day-frame:has(.WORKSHEET_block) {
background-color: green;
}
<div class="fc-daygrid-day-frame">
<div class="fc-daygrid-day-events">
<div class="fc-daygrid-event-harness">
<a class="WORKSHEET_block">This is the child using the class</a>
</div>
</div>
</div>
<div class="fc-daygrid-day-frame">
<div class="fc-daygrid-day-events">
<div class="fc-daygrid-event-harness">
<a>this child does not have any class</a>
</div>
</div>
</div>
Using :has relative selector. I have inserted an extra HTML code it doesn't have a WORKSHEET_block class, so the style is not applying to it
This question already has answers here:
Is there a CSS selector for text nodes?
(3 answers)
Closed 3 years ago.
I want to select everything after the div with class="good" and make them disappear.
<div class="amazing">
<div class="good"></div>
"bad text"
<a class="bad"></a>
"worse text"
<a class="worse"></a>
</div>
I tried this but it didn't get rid of the texts.
.amazing a:nth-last-child(n+4) {
display: none !important;
}
Try this:
<div class="amazing">
<div class="good">This is good</div>
<a class="bad">bad text</a>
<a class="worse">worse text</a>
</div>
and
.amazing a {
display: none !important;
}
If I understand it well, you wish to hide all texts after the div of .good
/*Select All But The First One*/
.amazing div:nth-child(n+2) {
display: none !important;
}
<div class="amazing">
<div class="good">"good text"</div>
<div class="bad">"bad text"</div>
<div class="worse">"worse text"</div>
</div>
This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Is there a "previous sibling" selector?
(30 answers)
Closed 5 years ago.
I have question about CSS selectors. I have below structure - I can only modiffy CSS - I don't have access to modify html or JS.
<div class="wrapper">
<div>
<div>
<div class="open">
</div>
</div>
</div>
<div>
<div class="top">
</div>
</div>
</div>
Class open will be toggled. Can I make selector when:
div in 4 line has open - div with class top => .top {top:50px}
div in 4 line not has open - div with class top => .top{top:0px;}
This is possible?
Try this:
.wrapper div:not(.open){
...
}
You will need to adjust it to the get the correct DIV, because this will affect all of them inside .wrapper
In your case it looks like you need something like:
.wrapper > div > div > div:not(...){...}
However, that is a bad practice.
You can read some more here:
https://developer.mozilla.org/en-US/docs/Web/CSS/:not
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:
Using only CSS, show div on hover over another element
(14 answers)
Closed 5 years ago.
i Have used bootstrap and css , here is my code
<div class = "row" id="parent"=>
<div class="col-md-8" id="ClildDiv1">
//Some Content
</div>
<div class="col-md-4" id="ChildDiv2" style="display:none">
//Some Content
<div>
</div>
Now i want on hover on
<div class="row Parent>
All its Child should be visible in this case
<div class="col-md-4 ChildDiv2">
Any Help Would Be Appreciated And i want to achieve that only by CSS styling
You want one of the sibling selectors. General sibling ~ or next sibling +
.ClildDiv1:hover ~ .ChildDiv2 {
display: block;
}
See fiddle here
Or, the parent hover for any child div would be
.Parent:hover > div {
display: block;
}