This question already has answers here:
Lighten parent's (unknown) background-color in child
(3 answers)
How to override a LESS mixin variable based on a parent's variable
(1 answer)
Closed 7 years ago.
Hi I'm new to using Less and trying to make the best of the features it offers. What I would like to do is the following:
say I have a few anchor elements in html
Blue link
Red link
Green link
and I have the following css
.gen-link-prop {
text-decoration: none;
padding: 10px 40px;
color: #fff;
display: inline-block;
margin: 0 5px;
}
#blue-link-color: #9999ff;
#red-link-color: #ff9999;
#green-link-color: #99ff99;
.blue-link {
.gen-link-prop;
background-color: #blue-link-color;
}
.red-link {
.gen-link-prop;
background-color: #red-link-color;
}
.green-link {
.gen-link-prop;
background-color: #green-link-color;
}
.blue-link:hover, .red-link:hover, .green-link:hover {
background-color: darken(#<-- reference to base color here--<, 20%);
}
I want to be able to apply an operation to a property value that is already applied to the element. Is this even possible? Or is it something simple that I missed somewhere. Help is greatly appreciated
Related
This question already has answers here:
How wide is the default `<body>` margin?
(4 answers)
Closed 1 year ago.
I started studying CSS and I'm using an online IDE called replit to do some tests.
Today I've tried to create a simple rectangle shape and I realized that it couldn't reach the page borders, so I'm here to ask how to make this rectangle to reach it (https://2.thiagoalonso05.repl.co).
I created an empty div and put its class as greybar, after that, I went to CSS. Here's my code:
body {
background-color: #181818;
}
.greybar {
display: block;
height: 48px;
background-color: #202020;
}
Here's an image showing where I want the grey bar to reach (the red part):
Just remove the default margin and padding.
* {
margin:0;
padding:0;
}
body {
background-color: #181818;
}
.greybar {
display: block;
height: 48px;
background-color: #202020;
}
<div class="greybar"></div>
This question already has answers here:
Change CSS After x Characters
(3 answers)
Closed 3 years ago.
I wanted to create a wordpress website and in its live CSS edit part I selected the website name "Standard" and then I tried to change the first letters using :nth-child and :nth-letter pseudo classes. But I can't. Can I edit the site name with CSS styles. The way I chose to select the word was using these classes: header .logo .site-title and I put the pseudo-classes like this:
header .logo .site-title:nth-child(1):nth-letter(-n+2) {
color: pink;
}
And so the way I tried has'nt worked. Can you help me to solve the problem and people who are searching about this?
.site-title {
color: pink;
}
Try to use this CSS
.site-title:after {
color: black;
color: blue;
content: attr(data-descr);
left: 0;
position: absolute;
}
And HTML
<div class="site-title" data-descr="S T">SITE TITLE</div>
This question already has answers here:
What do commas mean in CSS selectors? [duplicate]
(4 answers)
Closed 7 years ago.
What does this type of CSS definition mean? Note the first two classes are separated without comma but the last two are separated with comma.
.Container .layout, .groupContainer
{
width: 100%;
}
The comma separates selectors allowing one group of CSS styles to apply to multiple different groups. In your posted CSS:
.Container .layout,
.groupContainer {
width: 100%;
}
width: 100% will be applied to elements of class layout within elements of class Container, and to elements with the groupContainer class.
References:
CSS: 'Groups of Selectors'.
It is shortcut of
.groupContainer
{
width: 100%;
}
.Container .layout
{
width: 100%;
}
You should use it to group your CSS
As explained above, it helps group single CSS declarations across multiple selectors, and can help save file size (which could come in very handy as your CSS file gets larger!) and make things a bit clearer to read.
For example, you could have multiple selectors with the same declarations:
.div1 {
color: red;
}
.div2 {
color: red;
}
.div3 {
color: white;
}
.div4 {
color: white;
}
And you can shorten this by using:
.div1,.div2 {
color: red;
}
.div3,div4 {
color: white;
}
The comma is used for grouping, when the same rule applies for several selectors. Each selector is completely independent of the others.
The space is used for select any .layout that are inside .container, even if there are other elements between them.
For your question, the answer is:
you grouping .layout which is inside the .container class and .groupContainer for both the width value is 100%.
This question already has an answer here:
Concatenating nested classes using SASS [duplicate]
(1 answer)
Closed 8 years ago.
I have the following:
div {
.demo {
color: #000;
}
}
Which Outputs:
div .demo { color: #000; }
However, I need it to output without the space between the element and the class:
div.demo { color: #000; }
Is there any way to do this using SASS Nesting?
Use & to combine a selector with its parent:
div {
&.demo {
color: #000;
}
}
You can use the ampersand in front of .demo to achieve this.
div {
&.demo {
color: #000;
}
}
The ampersand character is a placeholder for whatever the parent element is.
This question already has answers here:
Can a CSS class inherit one or more other classes?
(29 answers)
Closed 9 years ago.
This might be a noob question, but I'm trying to search by terms like "CSS add more propertiers to existent class"; "Add CSS properties to class"; etc and I can't find what I'm looking for.
Imagine I have this:
.ui-bar { color: red }
Now I want to extend this property, but continue with the same color red.
.ui-bar-margin { margin-top: 10px; }
How can I accomplish this? If you want, you can point me links or terms to search for.
Thanks!
You just do it like this... Here's a lot of examples.
.ui-bar {
color: red;
margin-top: 10px;
background: white;
width: 300px;
display: block;
text-align: left;
}