This question already has an answer here:
Selecting the last element among various nested containers
(1 answer)
Closed 4 years ago.
I have nested class like below
I need to access the last mat-nested-tree-node class, i tried like below
.mat-nested-tree-node:last-child ul {
border-left: 1px solid white;
margin-left: -41px;
}
But it is applying styles to all mat-nested-tree-node classes. How can i select only the last child?
This is my editor url https://amarrkydlnk.angular.stackblitz.io
Any help would be appreciated!
If you want to target a child of a div you can do it like .mat-nested-tree-node > .mat-nested-tree-node-child > .mat-nested-tree-node-child-next{} and so on and so on.
Related
This question already has answers here:
What does a space mean in a CSS selector? i.e. What is the difference between .classA.classB and .classA .classB? [duplicate]
(3 answers)
Closed 4 months ago.
I'm trying to add the same styling to multiple classes, including a nested SASS class like so
.class1,
.class2,
.class3,
.class4.class4child,
.class5 {
background: #FFF;
padding: 3.2rem;
border-radius: 0.8rem;
}
I'm hoping class4.class4child will inherit these properties, but this implementation doesn't seem to work. (class1,2,3,5 all work here)
edit: Not a duplicate of this question, as I was not aware of both syntax.
Replace
.class4.class4child,
which only applies to elements that have both classes, with
.class4 .class4child,
which applies to elements with class="class4child" which are descendants to an element with class="class4".
This question already has answers here:
Specifying a list of arbitrary children (no pattern) for nth-child and nth-of-type
(2 answers)
Closed 6 years ago.
How can I sum these css selectors together?
td:nth-child(1), td:nth-child(4), td:nth-child(5) {
font-size: 25px;
}
I thought of something like
td:nth-child(1,4,5) {
font-size: 25px;
}
but this doesnt work. Is there a way to condense this?
If you can't use a an+b formula to target them (which is the case in your particular example), then the code you wrote is the shortest version.
If you wish to simplify the CSS code, you could switch to classes... that however will make your HTML less clean.
This question already has answers here:
How do I select an element only when inside another element?
(3 answers)
Closed 6 years ago.
when i use this:
b, strong { color: black;}
It applies to the whole website.
I want to set the black color only in a div named "div1", how can i do it?
my div's default class name is "sidereportleft", i've applied this code, but still not working:
http://pastebin.com/JA5JXuNe
Given that your div has a class of div1, you could do it easily by:
.div1 b,
.div1 strong {
color: #000;
}
This question already has answers here:
Is there a CSS parent selector?
(33 answers)
Closed 8 years ago.
I was wondering if there is a CSS-only way of styling an element based on it's child?
In my present situation, i've got an ul with a lot of li's in it. None of them have a separate identifying class, but only one of them got an iFrame (youtube video) inside of it. That li item, I want to style.
The CSS would somewhat be like
ul li:child-is[iframe] {
// styling
}
Is this possible?
Not today.
In the next occurrence of CSS, CSS4, you'll be able to precise the subject in a selector using an exclamation mark :
ul !li iframe {
// styling applies to the li element
}
but there's no pure CSS solution today.
This question already has answers here:
Is there a "previous sibling" selector?
(30 answers)
Closed 8 years ago.
I have a li list with 2 items in it, which are "RMS" and "RPM". When you rollover RMS the background changes and the RPM is targeted with the following to make the RPM element change to red. I need the same thing to work for the opposite side as well (rollover RPM and the background changes but RMS isn't targeted). I can't seem to get it to work for some reason.
li:hover + li#RPM {
background-color:red;
}
li:hover + li#RMS {
background-color: #CCC;
}
JSFiddle Demo
The + CSS selector looks for the next sibling as defined. There is no previous element CSS selector. You'll probably have to accomplish this using Javascript or jQuery.