Change pseudo element when another class present - css

I'm trying to change the after pseudo element when the .active class is added, but this doesn't seem to be working correctly.
I'm currently using scss in my project with Vue. I've already tried the following:
li {
position: relative;
&::after {
opacity: 0;
bottom: -10px;
left: 0;
position: absolute;
content: "";
width: 0%;
height: 3px;
background: $light-blue;
}
}
// When this class is present, adjust the pseudo element to different width
.active {
color: $light-blue;
display: flex;
flex-direction: column;
position: relative;
li::after {
opacity: 1;
width: 60%;
}
}
I've also tried the following as well
.active {
color: $light-blue;
display: flex;
flex-direction: column;
position: relative;
&::after {
opacity: 1;
width: 60%;
}
}
What would be the correct way to adjust the pseudo element from the li element through another class?

In SCSS:
li {
position: relative;
&::after {
opacity: 0;
bottom: -10px;
left: 0;
position: absolute;
content: "";
width: 0%;
height: 3px;
background: $light-blue;
}
&.active {
color: $light-blue;
display: flex;
flex-direction: column;
position: relative;
&::after {
opacity: 1;
width: 60%;
}
}
}
Compiled to the following code in CSS:
li {
position: relative;
}
li::after {
opacity: 0;
bottom: -10px;
left: 0;
position: absolute;
content: "";
width: 0%;
height: 3px;
background: $light-blue;
}
li.active {
color: $light-blue;
display: flex;
flex-direction: column;
position: relative;
}
li.active::after {
opacity: 1;
width: 60%;
}

Related

change color of menu depending on background

I'm using mix-blend-mode to change the color of my hamburger menu but it isn't working. The menu stays the some color regardless of what the background is. Here's the CSS and HTML
:root {
--black-color: #3F3D3C;
--white-color: #FAF9F6;
--taupe-color: #D8C7B8;
--grey-color: #CCC5C2;
}
.menu {
position: fixed;
top: 0;
right: 0;
z-index: 1;
aspect-ratio: 1 / 1;
width: 5%;
max-width: 25px;
margin-right: 1rem;
margin-top: 1rem;
}
.menu .toggler {
position: absolute;
margin: auto;
z-index: 2;
cursor: pointer;
width: 100%;
height: 100%;
opacity: 0;
}
.menu .icon {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: 0;
left: 0;
z-index: 1;
aspect-ratio: 1 / 1;
width: 100%;
background: transparent;
}
.menu .icon>div {
position: relative;
width: 100%;
height: 0.5px;
background: var(--black-color);
mix-blend-mode: difference;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.5s ease;
}
.menu .icon>div:before {
content: '';
position: absolute;
top: -4px;
width: 100%;
height: 0.5px;
z-index: 1;
background: inherit;
mix-blend-mode: difference;
}
.menu .icon>div:after {
content: '';
position: absolute;
top: 4px;
width: 100%;
height: 0.5px;
z-index: 1;
background: inherit;
mix-blend-mode: difference;
}
.black {
background-color: var(--black-color);
height: 100vh;
width: 100vw;
}
.grey {
background-color: var(--grey-color);
height: 100vh;
width: 100vw;
}
.white {
background-color: var(--white-color);
height: 100vh;
width: 100vw;
}
<div class="menu">
<input type="checkbox" class="toggler" onclick="document.getElementById('overlay').style.opacity='1'">
<div class="icon">
<div></div>
</div>
<div class="overlayHidden" id="overlay">
<nav>
<div id="nav-links"></div>
</nav>
</div>
</div>
<div class="white">content with different background color</div>
<div class="black">content with different background color</div>
<div class="grey">content with different background color</div>
where am I going wrong?
EDIT:
updated the code so you can run snippet

Improving the icons in css

I'm learning css(scss) and i've problem with stylistic my text.
How i can get text in one line and how to center icon from fontawsome to the text?
main {
overflow: hidden;
opacity: 0.6;
.icons {
display: block;
position: relative;
font-size: 3rem;
opacity: 1;
.fire {
color: red;
display: flex;
padding-top: 5%;
padding-left: 3%;
position: absolute;
margin-top: 10%;
p {
padding-left: 5%;
display: flex;
color: blanchedalmond;
}
}
}
}

How to choose specific content i want to pass to the mixin?

I have a #mixin call skewed in SASS.
#mixin skewed {
position: relative;
&::before {
content: '';
display: block;
width: 100%;
height: 50px;
position: absolute;
transform: skewY(-2deg);
#content;
}
&::after {
content: '';
display: block;
width: 100%;
height: 50px;
position: absolute;
transform: skewY(-2deg);
#content;
}
}
From above, you can see that there has #content inside "before" and "after".
The below is the "footer" class, how to pass the content to "before" but not "after".
footer {
padding: 2em 0 0;
height: 100px;
background-color: $color-shade;
margin-top: 3.5em;
#include skewed {
background-color: red;
top: -25px;
}
}
You can add a default variable and a conditional.
DEMO
#mixin skewed($doesAfterHaveContent: false) {
position: relative;
&::before {
content: '';
display: block;
width: 100%;
height: 50px;
position: absolute;
transform: skewY(-2deg);
#content;
}
&::after {
content: '';
display: block;
width: 100%;
height: 50px;
position: absolute;
transform: skewY(-2deg);
#if ($doesAfterHaveContent) { #content; }
}
}
.footer {
#include skewed {
color: red;
}
}
.hey {
#include skewed(true) {
color: red;
}
}

How to create these shapes using CSS3

I am creating a responsive website. I want to create below shape in CSS3. using ul li.
you could use a pseudo element, and have overflow:hidden set on the parent container.
html {
margin: 0;
padding: 0;
background: #222;
}
.wrap {
position: relative;
width: 100%;
height: 200px;
background: #222;
overflow: hidden;
}
.wrap div {
display: inline-block;
position: relative;
height: 100%;
width: 22%;
margin-left: 2%;
background: lightblue;
transition: all 0.6s;
line-height:200px;
text-align:center;
}
.wrap:before {
content: "";
position: absolute;
bottom: -25%;
left: 0;
height: 50%;
width: 100%;
border-radius: 50%;
background: #222;
z-index: 8;
}
div.withImage {
background: url(http://placekitten.com/g/300/300);
background-size: 100% 100%;
}
.wrap div:hover:before {
opacity: 1;
}
.wrap div:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: blue;
opacity: 0;
transition: all 0.6s;
}
<div class="wrap">
<div>ONE</div>
<div>TWO</div>
<div>THREE</div>
<div class="withImage">FOUR</div>
</div>
NOTE
This has been done using Divs. I have left it as an exercise for the OP to alter this code for ul li.
This can also be altered to include Dynamically added elements: JSFIDDLE

Hide absolute positioned div on hover

I have this html:
<div class="caption">
<h2>Sun Flower</h2>
<p class="meta-info-font">I took this photo at some bla bla bla.. and some other stuff.</p>
</div>
Why doesn't this work:
.caption {
position: absolute;
top: 40%;
left: 0;
right: 0;
background-color: rgba(20,19,19,0.94);
display: none;
}
.caption:hover {
display: block;
}
.caption {
position: absolute;
top: 40%;
left: 0;
right: 0;
background-color: rgba(20,19,19,0.94);
display: block; /* HERE */
}
.caption:hover {
display: none; /* HERE */
}
Simply your div was hidden by default.
try with
.caption {
position: absolute;
top: 40%;
left: 0;
right: 0;
background-color: rgba(20,19,19,0.94);
display: block;
}
.caption:hover {
display: none;
}
Try changing this:
.caption {
position: absolute;
top: 40%;
left: 0;
right: 0;
background-color: rgba(20,19,19,0.94);
display: block;
}
.caption:hover {
display: none;
}
Your div must be display:block, so when you hover on it, it can be display:none
I tried checking the CSS in chrome and FireFox and it does not seem to be cross browser compatible. Why don't you write up some javascript yo hide it on hover..
Fiddle

Resources