Content in ::after not moving after being positioned abaolutely - html

I am trying to add an open and close triangle to my dropdown menu using CSS ::after concept. Here's my code.
<div class="row-links-platforms-and-flavor">
<div class="website-links">
<ul class="outer-links">
<li><a>Other Links</a>
<div class="links">
<ul class="inner-links">
<li><a class="website-link" href="#"
target="_blank">Link 11</a>
</li>
<li><a class="website-link" href="#"
target="_blank">Link 2</a>
</li>
<li><a class="website-link" href="#"
target="_blank">Link 3</a></li>
</ul>
</div>
</li>
</ul>
</div>
$color-white: #fff;
$color-black: #000;
$color-grey-light: #eaeaea;
$color-grey-dark: #F2F2F2;
$color-services-light: #951D21;
$color-services-dark: #7d1119;
$color-benchmarks-light: #44546a;
$color-benchmarks-dark: #303c4a;
$color-disabled: #e8e8e8bf;
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul {
list-style: none;
a {
text-decoration: none;
}
}
.website-links {
flex: 1 1 15%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
.outer-links {
position: relative;
cursor: pointer;
&:hover .inner-links {
transform: scale(1, 1);
transition: all 150ms ease-in;
}
&::before {
content: '\25BC';
position: absolute;
top: 0;
right: 0;
color: $color-services-light;
left: .5rem;
}
&:hover::before {
content: '\25B2';
position: absolute;
top: 0;
right: 0;
color: $color-services-light;
left: .5rem;
}
}
// 2022
.inner-links {
position: absolute;
border-radius: .5rem;
background-color: $color-grey-light;
z-index: 1000;
width: 20rem;
top: 100%;
right: -50%;
box-shadow: 0 0 1.5rem rgba($color-black, .15);
transform: scale(1, 0);
transform-origin: top;
transition: all 150ms ease-in 200ms;
li {
font-weight: 400;
text-align: center;
&:not(:last-child) {
border-bottom: 1px solid $color-white;
}
&:hover {
background-color: $color-white;
font-weight: 700;
}
a {
display: inline-block;
width: 100%;
padding: 1.5rem;
color: $color-black;
}
}
}
}
The triangle doesn't move to the right. If I don't give any position, the triangle appears properly at the beginning, but, I want it at the end of Other Links. What am I missing?

The problem you face it is , that first you set left: .5rem and after that you set right:0;
If you want to get it to the right , remove left property and add right: -.5rem or wahtever you want it :)
&::before {
content: '\25BC';
position: absolute;
top: 0;
right: -1rem;
color: $color-services-light;
/* remove it left: .5rem; */
}
Hope this explanation could helps you ...
I forgot to add and this change on hover :
&:hover::before {
content: '\25B2';
position: absolute;
top: 0;
right: -1rem;
color: $color-services-light;
/* left: .5rem; */
}
I think, right:-1rem; is what we looking for

Related

How can I center the elements and pseudo-elements of my navbar in CSS?

I am creating a navigation bar for my project, but when I added a white background when pressing the buttons I noticed that they are not lining up correctly. I am trying to align them but have not succeeded. This is how they currently look:
This is my HTML:
<navbar>
<ul class="nav__list">
<li class="nav__item__logo" data-tooltip="NutritionistApp">
<a href="#">
<img src="../../imgs/navbar/NutritionistApp.svg" class="logo-item" alt="Icono NutritionistApp">
</a>
</li>
<li class="nav__item" data-tooltip="Inicio">
<a href="#">
<img src="../../imgs/navbar/Home.svg" class="filter-clr" alt="Icono Inicio">
<div class="btn-ellipse"></div>
</a>
</li>
<!-- Other <li> elements... -->
And all my CSS:
:root{
/* Colores */
--clr-primary: #452372;
--clr-btn-primary: #9D8FAD;
--clr-btn-primary-hover: #FFFFFF;
/* Border radius */
--radius: 0.2rem;
/* Font Size */
font-size: 16px;
}
*,
*::before,
*::after{
box-sizing: border-box;
margin: 0;
padding: 0;
}
body{
/* Font family */
font-family: "Metropolis", sans-serif;
}
.nav__list{
background: var(--clr-primary);
box-shadow: 0px 0px 10px #7b7b7b;
padding: 1rem 0;
width: 6rem;
height: 100vh;
position: fixed;
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
z-index: 99;
}
.nav__item__logo{
list-style: none;
position: relative;
margin-bottom: 1.5rem;
transition: all 150ms ease;
}
.logo-item:hover{
transition: all 150ms ease;
transform: scale(1.05);
}
.nav__item{
list-style: none;
position: relative;
z-index: 99;
}
.nav__item::before{
content: attr(data-tooltip);
position: absolute;
left: 1rem;
top: -0.25rem;
background: var(--clr-primary);
color: white;
padding: 0.8rem;
border-radius: var(--radius);
transition: all 150ms ease;
opacity: 0;
scale: 0;
}
.nav__item::after{
content: "";
position: absolute;
width: 14px;
height: 14px;
border-radius: 2px;
background-color: transparent;
left: 5rem;
top: 0.6rem;
transition: all 150ms ease;
transform: rotate(45deg);
opacity: 0;
scale: 0;
}
.nav__item:hover::after{
opacity: 1;
scale: 1;
left: 5.1rem;
background-color: var(--clr-primary);
}
.nav__item:hover::before{
opacity: 1;
scale: 1;
left: 5.5rem;
}
.nav__item img{
transition: all 200ms ease-in;
}
.filter-clr:hover{
filter: brightness(0) saturate(100%) invert(99%) sepia(0%) saturate(2%) hue-rotate(359deg) brightness(111%) contrast(101%);
}
.btn-ellipse{
position: relative;
}
.btn-ellipse::before{
content: "";
width: 3rem;
height: 3rem;
background: white;
position: absolute;
border-radius: 50%;
left: -0.5rem;
top: -2.5rem;
z-index: -1;
opacity: 0;
transition: all 200ms ease-in;
}
.nav__item a:focus > .btn-ellipse::before{
opacity: 1;
}
.nav__item a:focus > img{
filter: brightness(0) saturate(100%) invert(16%) sepia(73%) saturate(1372%) hue-rotate(242deg) brightness(93%) contrast(101%);
}
I have a strong suspicion that if I change my current SVGs to others all the same size, it will center everything correctly, but I don't like that solution because I have icons with quite a lot of detail and I need each one to look big and clear.
I hope you can help me!

Custom select box

I am trying to style a select drop down box. The custom select box has rounded corners and a dropdown list (a box that drops down with the options) that shows on focus. I used the css below to style the select box. I have also substituted the html select with DIV elements.
Here is the code I have used so far:
document.querySelector('.custom-select-wrapper').addEventListener('click', function() {
this.querySelector('.custom-select').classList.toggle('open');
for (const option of document.querySelectorAll(".custom-option")) {
option.addEventListener('click', function() {
if (!this.classList.contains('selected')) {
this.parentNode.querySelector('.custom-option.selected').classList.remove('selected');
this.classList.add('selected');
this.closest('.custom-select').querySelector('.custom-select__trigger span').textContent = this.textContent;
}
})
}
})
.custom-select-wrapper {
position: relative;
user-select: none;
width: 188px;
z-index: 30000000000;
}
.custom-select {
position: relative;
display: flex;
flex-direction: column;
}
.custom-select__trigger {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
height: 27px;
background: #ffffff;
cursor: pointer;
border: 1px solid #707070;
border-radius: 8px;
}
.custom-options {
position: absolute;
display: block;
top: 100%;
left: 0;
right: 0;
border: 1px solid #707070;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
background: #fff;
transition: all 0.5s;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
}
.custom-select.open .custom-options {
opacity: 1;
visibility: visible;
pointer-events: all;
}
.custom-option {
position: relative;
display: block;
padding: 0 10px 0 10px;
line-height: 25px;
cursor: pointer;
transition: all 0.5s;
}
.arrow {
position: relative;
top: 15px;
right: 15px;
}
.arrow::before,
.arrow::after {
content: "\f0d7";
font-family: "Font Awesome 5 Free";
font-size: 20px;
font-weight: 700;
color: #394a6d;
position: absolute;
bottom: 0px;
}
<div class="custom-select-wrapper">
<div class="custom-select">
<div class="custom-select__trigger">
<span>Option 1</span>
<div class="arrow"></div>
</div>
<div class="custom-options">
<span class="custom-option selected" data-value="tesla">Option 2</span>
<span class="custom-option" data-value="volvo">Option 3</span>
</div>
</div>
</div>
The styles I have applied to the select tag are coming into effect, but the problem is that the dropdown box top border does not blend with the select box itself on focus. Is it only possible to change the SELECT input style on focus from a round border to a square border?
Would someone with some more knowledge in this regard please take a few minutes to suggest a solution?
It depends on what you mean by "blending", but if you want to achieve a more harmonious look, you can do the following:
Set the border-bottom-left-radius and border-bottom-right-radius of the trigger element to 0px when the dropdown is open, so that the select trigger visually continues to the dropdown that is visible
Remove the top border of the dropdown, so that you don't have a doubly-thick border separating the trigger and the dropdown
See proof-of-concept below:
document.querySelector('.custom-select-wrapper').addEventListener('click', function() {
this.querySelector('.custom-select').classList.toggle('open');
for (const option of document.querySelectorAll(".custom-option")) {
option.addEventListener('click', function() {
if (!this.classList.contains('selected')) {
this.parentNode.querySelector('.custom-option.selected').classList.remove('selected');
this.classList.add('selected');
this.closest('.custom-select').querySelector('.custom-select__trigger span').textContent = this.textContent;
}
})
}
})
.custom-select-wrapper {
position: relative;
user-select: none;
width: 188px;
z-index: 30000000000;
}
.custom-select {
position: relative;
display: flex;
flex-direction: column;
}
.custom-select__trigger {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
height: 27px;
background: #ffffff;
cursor: pointer;
border: 1px solid #707070;
border-radius: 8px;
transition: all 0.5s;
}
.custom-options {
position: absolute;
display: block;
top: 100%;
left: 0;
right: 0;
border: 1px solid #707070;
border-top: none;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
background: #fff;
transition: all 0.5s;
opacity: 0;
visibility: hidden;
pointer-events: none;
z-index: 2;
}
.custom-select.open .custom-select__trigger {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.custom-select.open .custom-options {
opacity: 1;
visibility: visible;
pointer-events: all;
}
.custom-option {
position: relative;
display: block;
padding: 0 10px 0 10px;
line-height: 25px;
cursor: pointer;
transition: all 0.5s;
}
.arrow {
position: relative;
top: 15px;
right: 15px;
}
.arrow::before,
.arrow::after {
content: "\f0d7";
font-family: "Font Awesome 5 Free";
font-size: 20px;
font-weight: 700;
color: #394a6d;
position: absolute;
bottom: 0px;
}
<div class="custom-select-wrapper">
<div class="custom-select">
<div class="custom-select__trigger">
<span>Option 1</span>
<div class="arrow"></div>
</div>
<div class="custom-options">
<span class="custom-option selected" data-value="tesla">Option 2</span>
<span class="custom-option" data-value="volvo">Option 3</span>
</div>
</div>
</div>
The above code is a solution strictly from a styling point of view. But as per #CBroe remarks, from a usability point of view (for example using the select via keyboard is impossible), the code is not optimal.
This is why I came up with a solution that uses the jQuery plugin Select2
If anyone is interested here is a link to the code
https://www.codeply.com/p/Z999PpuSOK

how to move the loader from left to right on hover?

I have a simple div in which there is an tag with 4 spans and a text
I am trying to create a loader on hovering my name.
The top line moves from left to right, after passing half way it get stucks in the middle and does not hides.
I am following a short youtube video:
https://www.youtube.com/watch?v=ex7jGbyFgpA&t=156s
The code is also attached. Please help
.name {
// font-size: 6rem;
margin: 0 0 3.5rem;
color: #2196f3;
position: relative;
display: inline-block;
padding: 15px 30px;
text-transform: uppercase;
letter-spacing: 0px;
text-decoration: none;
overflow: hidden;
transition: 0.2s;
font-size: 24px;
}
.hi {
margin: 0;
padding: 0;
display: flex;
align-items: center;
min-height: 100vh;
}
a span {
position: absolute;
display: block;
}
a span:nth-child(1) {
top: 0;
left: -100%;
width: 100%;
height: 2px;
background: linear-gradient(90deg, transparent, #2196f3);
}
a:hover span:nth-child(1) {
left: 100px;
`enter code here` transition: 1s;
}
<div>
<a href='#' className='name'>
<span></span>
<span></span>
<span></span>
<span></span> Hafiz Arsam Rahmaan
</a>
</div>
Delete margin: 0 0 3.5rem;
Change left: -10000%; by left: -100%;
Check the demo below
(Don't forget to change class by className in your react component)
a.name {
position: relative;
display: inline-block;
padding: 15px 30px;
color: #6600FF;
letter-spacing: 4px;
text-decoration: none;
text-transform: uppercase;
font-size: 24px;
overflow: hidden;
transition: 0.2s;
}
a.name span {
position: absolute;
display: block;
}
a.name span:nth-child(1) {
top: 0;
left: -100%;
width: 100%;
height: 2px;
background: linear-gradient(90deg, transparent, #2196f3)
}
a.name:hover span:nth-child(1) {
left: 100%;
transition: 1s;
}
<div>
<a href='#' class='name'>
<span></span>
<span></span>
<span></span>
<span></span>
Hafiz Arsam Rahmaan
</a>
</div>
Demo with react: Stackblitz

I have a code and i need change "a" tag to "li". When i do it css animation stop work

I want to change (a) tag to (li). When i do it css animation stop working. Why? It is not first time when i change (a) tag to (li) but i never have problem like this. Of course you need to do manipulations in css but this time i can not solve this problem. How can i change it?
<div class="panel" id="slice">
<div class="panel__content">
Close me.
</div>
</div>
<div class="menu">
<a class="menu__link" href="#slice" data-hover="Slice">Slice</a>
</div>
.menu {
position: fixed;
width: 100vw;
pointer-events: none;
margin-top: 10vh;
text-align: center;
z-index: 2; }
.menu__link {
display: inline-block;
text-decoration: none;
border: 2px solid #263238;
color: #263238;
pointer-events: auto;
line-height: 40px;
position: relative;
padding: 0 50px;
box-sizing: border-box;
margin: 0;
user-select: none;
overflow: hidden;
border-radius: 50px;
.panel {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
overflow: auto;
z-index: 999;
color: #000;
box-sizing: border-box;
background-color: #ECEFF1; }
.panel__content {
opacity: 0;
will-change: margin-top;
transition: all 700ms;
transition-delay: 600ms;
padding: 100px 200px;
margin-top: -5%; }
.panel:target .panel__content {
opacity: 1;
margin-top: 0; }
.panel#slice {
background-color: #E53935;
transition: all 800ms cubic-bezier(0.190, 1.000, 0.560, 1.000);
transform: translate3d( 0, -100%, 0 ); }
.panel#slice:target {
transform: translate3d( 0, 0, 0 ); }
You'd have to restyle the unordered list for spacing, but maybe instead of outright replacing your menu's <a> elements with <li>, you could include the <a> elements in the resulting list items.
This would preserve all the :target functionality and give you the list (for semantics?).
EDIT: Of course, this won't do at all if your menu just can not consist of anything but <li>.
/* basic style definition */
/* •••••••••••••••••••••••••••••••• */
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: 'Roboto Slab', serif;
}
h1 {
margin: 0;
user-select: none;
text-align: center;
font-weight: 300;
}
p,
{
font-weight: 300;
color: #546E7A;
user-select: none;
text-align: center;
margin: 0;
}
a {
text-align: center;
text-decoration: none;
color: #FFF;
}
/* Navigation menu */
/* •••••••••••••••••••••••••••••••• */
.menu {
position: fixed;
width: 100vw;
pointer-events: none;
margin-top: 10vh;
text-align: center;
z-index: 2;
}
/* Menu link item */
.menu__link {
display: inline-block;
text-decoration: none;
border: 2px solid #263238;
color: #263238;
pointer-events: auto;
line-height: 40px;
position: relative;
padding: 0 50px;
box-sizing: border-box;
margin: 0;
user-select: none;
overflow: hidden;
border-radius: 50px;
&::before {
content: attr(data-hover);
background-color: #263238;
color: #FFF;
position: absolute;
top: 100%;
bottom: 0;
left: 0;
transition: all 300ms cubic-bezier(0.190, 1.000, 0.560, 1.000);
right: 0;
}
&:hover::before {
top: 0;
}
}
/* Panels Style*/
/* •••••••••••••••••••••••••••••••• */
/* Common panel style */
.panel {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
overflow: auto;
z-index: 999;
color: #000;
box-sizing: border-box;
background-color: #ECEFF1;
}
/* panel content (only for animation delay after open) */
.panel__content {
opacity: 0;
will-change: margin-top;
transition: all 700ms;
transition-delay: 600ms;
padding: 100px 200px;
margin-top: -5%;
}
/* Panel content animation after open */
.panel:target .panel__content {
opacity: 1;
margin-top: 0;
}
/* Specific "Home "panel */
/* •••••••••••••••••••••••••••••••• */
.panel#home {
z-index: 1;
background: radial-gradient(ellipse at center, rgba(255, 255, 255, 1) 0%, #CFD8DC 100%);
}
/* Specific panel "Slice" */
/* •••••••••••••••••••••••••••••••• */
.panel#slice {
background-color: #E53935;
transition: all 800ms cubic-bezier(0.190, 1.000, 0.560, 1.000);
transform: translate3d( 0, -100%, 0);
}
.panel#slice:target {
transform: translate3d( 0, 0, 0);
}
/* Specific panel "Fade" effect */
/* •••••••••••••••••••••••••••••••• */
.panel#fade {
background-color: #00C853;
opacity: 0;
transition: all 800ms;
pointer-events: none;
}
.panel#fade:target {
opacity: 1;
pointer-events: auto;
}
<!-- Home Panel -->
<div class="panel" id="home">
<h1>Pure CSS panels</h1>
<p>by Mattia Astorino</p>
</div>
<div class="panel" id="slice">
<div class="panel__content">
<a href="#home">
Close me.
</a>
</div>
</div>
<div class="panel" id="fade">
<div class="panel__content">
Close me.
</div>
</div>
<!-- Navigation -->
<div class="menu">
<ul>
<li>
<a class="menu__link" href="#slice" data-hover="Slice">Slice</a>
</li>
<li>
<a class="menu__link" href="#fade" data-hover="Fade">Fade</a>
</li>
</ul>
</div>

Z-Index is "not working"

I'm learning HTML and CSS and have some problems. Thare are 3 html elements.
First one is navigation bar.
Seconde one is button in that navigation.
Third one is dropdown menu.
Basicly, i wont on hover of 2nd element slide down 3th one.
And i get that. Problem is 3th element when sliding down it appears OVER 1st and 2nd. element. With opacity 0.99 i managed to slid it UNDER element 2. But its still OVER element 1.
How can i put it under all. Is it possible?
Here is example of my code. https://jsfiddle.net/eth66zea/
.su-drop {
position: absolute;
left: 0px;
top: -100px;
height: 100px;
min-width: 200px;
background-color: greenyellow;
transition: all 0.333s;
z-index: -1;
display: inline;
opacity: 0.99
}
.su-header {
position: relative;
height: 70px;
color: white;
background-color: black;
border-bottom: 2px #1f7caf solid;
margin-bottom: 10px;
z-index: 5;
}
.su-header .su-ul {
position: relative;
list-style-type: none;
font-size: 16px;
margin-top: 0px;
margin-bottom: 0px;
margin-left: 10%;
}
.su-header .su-ul .su-li{
position: relative;
float: left;
padding: 10px 10px;
line-height: 50px;
min-width: 100px;
text-align: center;
transition: all 0.6s;
cursor: pointer;
display: inline;
}
.su-header .su-ul .su-li:hover{
background-color: #1f7caf;
}
.su-header .su-li:last-child:hover > .su-drop{
top: 70px;
}
<div class="su-header">
<ul class="su-ul">
<li class="su-li"><i class="fa fa-heartbeat" aria-hidden="true"></i></li>
<li class="su-li">Test1</li>
<li class="su-li">Test2</li>
<li class="su-li">
Dropdown
<div class="su-drop"></div>
</li>
</ul>
</div>
Thx for your help.
Here is one way of doing it that gets around the z-index problem.
Instead of doing the transition on the top offset, you can try doing the transition on the height value.
Position the .su-drop element where you need it (bottom of .su-li) and give it an initial height of 0. On hover, you then set the height to the desired value.
If you want the sliver of color at the top, you would need to add a second element, .su-drop-up, but this may be optional.
If you don't have a height value for .su-drop, then you might need to alter your HTML, it all depends on the details of your layout and design.
.su-drop {
position: absolute;
left: 0px;
bottom: 0px;
height: 0px;
min-width: 200px;
background-color: greenyellow;
transition: all 0.333s;
z-index: -1;
display: inline;
opacity: 0.97
}
.su-drop-up {
position: absolute;
left: 0px;
top: -10px;
height: 10px;
min-width: 200px;
background-color: greenyellow;
transition: all 0.333s;
z-index: -1;
display: inline;
opacity: 0.97
}
.su-header {
position: relative;
height: 70px;
color: white;
background-color: black;
border-bottom: 2px #1f7caf solid;
margin-bottom: 10px;
z-index: 5;
opacity: 1;
}
.su-header .su-ul {
position: relative;
list-style-type: none;
font-size: 16px;
margin-top: 0px;
margin-bottom: 0px;
margin-left: 10%;
opacity: 0.98;
}
.su-header .su-ul .su-li {
position: relative;
float: left;
padding: 10px 10px;
line-height: 50px;
min-width: 100px;
text-align: center;
transition: all 0.6s;
cursor: pointer;
display: inline;
}
.su-header .su-ul .su-li:hover {
background-color: #1f7caf;
}
.su-header .su-li:last-child:hover > .su-drop {
height: 100px;
bottom: -100px;
}
.su-header .su-li:last-child:hover > .su-drop-up {
height: 0px;
}
<div class="su-header">
<ul class="su-ul">
<li class="su-li"><i class="fa fa-heartbeat" aria-hidden="true"></i>
</li>
<li class="su-li">Test1</li>
<li class="su-li">Test2</li>
<li class="su-li">
Dropdown
<div class="su-drop-up"></div>
<div class="su-drop"></div>
</li>
</ul>
</div>
Change your Height Property
.su-drop {
position: absolute;
left: 0px;
top:70px;
height: 0px;
min-width: 200px;
background-color: greenyellow;
transition: all 0.333s;
z-index: -1;
display: inline;
opacity: 0.97
}
.su-header .su-li:last-child:hover > .su-drop{
height:100px;
}
Working Demo https://jsfiddle.net/Rahul_Ravi/eth66zea/3/