This question already has answers here:
How to animate underline from left to right?
(3 answers)
Closed 6 months ago.
I am trying to make an underline animation that comes from the middle and extends to the sides
I copied the code from an example i found online which was working but not on my case
I have added the code on jsfiddle below
you are looking in the beginning of the css for .htext:after and .htext:after:hover
https://jsfiddle.net/wvm2sfp0/1/
body {
background: rgb(14, 13, 13);
color: white;
width: 100%;
}
header {
width: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background: linear-gradient(to top, rgba(0, 0, 0, 0), rgb(0, 0, 0, 0.8));
}
a {
text-decoration: none;
color: inherit;
}
p {
color: white;
}
.div1 {
background-image: url(../images/Group\ 10.png);
}
.htext {
margin-right: 3%;
font-size: 0.75vw;
transition: text-decoration 0.3s;
}
.htext:after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 0;
left: 0;
background-color: #54B3A1;
transform-origin: center;
transition: transform 0.25s ease-out;
margin-bottom: -20px;
}
.htext:after:hover {
transform: scaleX(1);
transform-origin: center;
}
.logo1 {
margin-right: 10%;
height: 7%;
width: 8%;
}
.logo2 {
margin-right: 1.5%;
}
<div class="div1">
<header>
<img src="images/viennalogo.png" class="logo1">
<a href="#" class="htext">
<p>HOME</p>
</a>
<a href="#" class="htext">
<p>BRANDS WE WORK WITH</p>
</a>
<a href="#" class="htext">
<p>BRAND GALLERY</p>
</a>
<a href="#" class="htext">
<p>NEWS</p>
</a>
<a href="#" class="htext">
<p>ABOUT US</p>
</a>
<a href="#" class="htext">
<p>CONTACT</p>
</a>
<img src="images/Facebook.png">
<img src="images/Instagram.png">
<img src="images/Twitter.png">
</header>
</div>
well for an underline expansion, I wouldn't go with scaleX (for a lot of reasons)...
Instead, try this (I hope it's what you're looking for:
.htext {
margin-right: 3%;
font-size: 0.75vw;
transition: text-decoration 0.3s;
display: inline-block;
padding: 15px 20px;
position: relative;
}
.htext:after {
background: none repeat scroll 0 0 transparent;
bottom: 0;
content: "";
display: block;
height: 2px;
left: 50%;
position: absolute;
background: #54B3A1;
transition: width 0.3s ease 0s, left 0.3s ease 0s;
width: 0;
}
.htext:hover:after {
width: 100%;
left: 0;
}
For this to work, make sure your .htext class has a relative position, and that your .htext:after is absolute to that.
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
I was making a website for e-invitations. Have made everything but stuck at one place.
The menu of desktop view is working fine but when opened on the mobile its not working. I click on the menu button nothing happens. Please find below the screenshot.
HTML
<body>
<div id="container" class="container intro-effect-push animsition" style="animation-duration: 1500ms; opacity: 1;">
<nav id="main_menu" class="menugray">
<div id="menu-button" class="menu-opened">
</div>
<ul class="open" style="display: none;">
<li><a class="fade-page" href="index2.html"><span data-hover="HOME">HOME</span></a></li>
<li> <a class="fade-page" href="knowus.html"><span data-hover="BRIDE & GROOM">BRIDE & GROOM</span></a>
</li>
<li><span data-hover="EVENTS">EVENTS</span></li>
<li><span data-hover="RSPV">RSPV</span></li>
<li><span data-hover="PHOTOS">PHOTOS</span></li>
</ul>
</nav>
CSS
#main_menu li a span::before {
position: absolute;
top: -100%;
color:#e76b71;
content: attr(data-hover);
-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
#main_menu:after,
#main_menu > ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#menu-button {
position: absolute;
padding-left: 1.25em;
font-size:30px;
top:8px;
right:8px;
display: none;
cursor:pointer;
}
#menu-button:before {
content: "";
position: absolute;
top: 0.25em;
left: 0;
width: 1em;
height: 0.125em;
border-top: 0.375em double #333;
border-bottom: 0.135em solid #333;
}
Screenshots
If I change the code to
<ul class="open" style="display: block;">
initially it was display:none
After changing the display is:
This question might be asked several time. But request someone to help me. I would be very thankful for this.
Don't worry i found a solution for you..
See flowing code:
<div id="container" class="container intro-effect-push animsition" style="animation-duration: 1500ms; opacity: 1;">
<nav id="main_menu" class="menugray">
<label for="open-nav" class="menu-opened" id="menu-button"></label>
<input id="open-nav" class="menu-opened" type="checkbox">
<ul class="open" style="display: none;">
<li><a class="fade-page" href="index2.html"><span data-hover="HOME">HOME</span></a></li>
<li> <a class="fade-page" href="knowus.html"><span data-hover="BRIDE & GROOM">BRIDE & GROOM</span></a>
</li>
<li><span data-hover="EVENTS">EVENTS</span></li>
<li><span data-hover="RSPV">RSPV</span></li>
<li><span data-hover="PHOTOS">PHOTOS</span></li>
</ul>
</nav>
</div>
And the css is:
#main_menu li a span::before {
position: absolute;
top: -100%;
color: #e76b71;
content: attr(data-hover);
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
#main_menu:after,
#main_menu > ul:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
#menu-button {
position: absolute;
padding-left: 1.25em;
font-size: 30px;
top: 8px;
right: 8px;
cursor: pointer;
}
#menu-button:before {
content: "";
position: absolute;
top: 0.25em;
left: 0;
width: 1em;
height: 0.125em;
border-top: 0.375em double #333;
border-bottom: 0.135em solid #333;
}
#open-nav:checked + .open {
display: block !important;
}
#open-nav {
display: none;
}
Codepen link for your preview: https://codepen.io/ziruhel/pen/gXOBVK
I have a topnav menu that works fine, I just want to keep the underline that appears on the hover event to stay there if that menu item is active. I have tried many solutions I found on the forum, but somehow none did not work. Any help is appreciated.
and here are the html and css snippets:
body {
margin: auto;
}
.topnavbar {
background-color: rgba(20, 180, 255, 1);
/*rgba(0,255,150,0.6); #3EDC99*/
-webkit-box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
-moz-box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
}
.nav {
padding: 5px 5px 5px 5px;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
background-color: rgba(245, 245, 245, 1)/*#3498db; */
}
.nav {
width: 550px;
margin: 0 auto 0 auto;
text-align: center;
}
/* Navigation */
.nav {
font-family: Verdana, Georgia, Arial, sans-serif;
font-size: 14px;
}
.nav-items {
padding: 0;
list-style: none;
}
/* color of menu links
span {
color:yellow;
}
*/
.nav-item {
display: inline-block;
margin-right: 25px;
}
.nav-item:last-child {
margin-right: 0;
}
.nav-link,
.nav-link:link,
.nav-link:visited,
.nav-link:active,
.submenu-link,
.submenu-link:link,
.submenu-link:visited,
.submenu-link:active {
display: block;
position: relative;
font-size: 14px;
letter-spacing: 1px;
cursor: pointer;
text-decoration: none;
outline: none;
color: blue;
}
.nav-link::before {
content: "";
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 3px;
background: rgba(0, 0, 0, 0.2);
opacity: 0;
-webkit-transform: translate(0, 10px);
transform: translate(0, 10px);
transition: opacity 0.3s ease, transform 0.3s ease;
}
.nav-link:hover::before,
.nav-link:hover::before {
opacity: 1;
-webkit-transform: translate(0, 5px);
transform: translate(0, 5px);
}
.dropdown {
position: relative;
}
.dropdown .nav-link {
padding-right: 15px;
height: 17px;
line-height: 17px;
}
.dropdown .nav-link::after {
content: "";
position: absolute;
top: 6px;
right: 0;
border: 5px solid transparent;
border-top-color: blue;
/*small triangle showing drop down menu*/
}
.submenu {
position: absolute;
top: 100%;
left: 50%;
z-index: 100;
width: 200px;
margin-left: -100px;
background: blue;
border-radius: 3px;
line-height: 1.46667;
margin-top: -5px;
box-shadow: 0 0 8px rgba(0, 0, 0, .3);
opacity: 0;
-webkit-transform: translate(0, 0) scale(.85);
transform: translate(0, 0)scale(.85);
transition: transform 0.1s ease-out, opacity 0.1s ease-out;
pointer-events: none;
}
.submenu::after,
.submenu::before {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -10px;
border: 10px solid transparent;
height: 0;
}
.submenu::after {
border-bottom-color: blue;
}
.submenu::before {
margin-left: -13px;
border: 13px solid transparent;
border-bottom-color: rgba(0, 0, 0, .1);
-webkit-filter: blur(1px);
filter: blur(1px);
}
.submenu-items {
list-style: none;
padding: 10px 0;
}
.submenu-item {
display: block;
text-align: left;
}
.submenu-link,
.submenu-link:link,
.submenu-link:visited,
.submenu-link:active {
color: #3498db;
padding: 10px 20px;
}
.submenu-link:hover {
text-decoration: underline;
}
.submenu-seperator {
height: 0;
margin: 12px 10px;
border-top: 1px solid #eee;
}
.show-submenu .submenu {
opacity: 1;
-webkit-transform: translate(0, 25px) scale(1);
transform: translate(0, 25px) scale(1);
pointer-events: auto;
}
.submenu-link {
color: red;
}
<link rel="stylesheet" type="text/css" href="{% static 'css/_topnavbar.css' %}">
<!--Top Navigation-->
<nav role="navigation" class="nav" id="topnav">
<ul class="nav-items">
<li class="nav-item">
<span>Home</span>
</li>
<li class="nav-item ">
<span>Media</span>
<nav class="submenu">
<ul class="submenu-items">
<li class="submenu-item">Product #1</li>
<li class="submenu-item">Product #2</li>
<li class="submenu-item">Product #3</li>
</ul>
</nav>
</li>
<li class="nav-item">
<span>Search</span>
</li>
<li class="nav-item">
<span>Report</span>
</li>
<li class="nav-item dropdown">
<span>More</span>
<nav class="submenu">
<ul class="submenu-items">
<li class="submenu-item">About</li>
<li class="submenu-item">Contact</li>
<li class="submenu-item">
<hr class="submenu-seperator" />
</li>
<li class="submenu-item">Support</li>
<li class="submenu-item">FAQs</li>
</ul>
</nav>
</li>
</ul>
</nav>
<script type='text/javascript' src="{% static 'js/_topnavbar.js' %}"></script>
I use js to open the drop down menu items, but I don't think it was necessary to make the post more extended than it is now.
You can create a new class e.g. .is-active. On the home page you can add this class to the home link in your navigation, like this:
<li class="nav-item">
<span>Home</span>
</li>
In your CSS you style the is-active class the same way as the :hover.
On each new page of your site, in the HTML, change the location of the .is-active class to the appropriate page. If your website is much bigger or more complicated, you can do this programmatically instead.
Basic example:
body {
margin: auto;
}
.topnavbar {
background-color: rgba(20, 180, 255, 1);
/*rgba(0,255,150,0.6); #3EDC99*/
-webkit-box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
-moz-box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
box-shadow: 0px 3px 5px rgba(100, 100, 100, 0.49);
}
.nav {
padding: 5px 5px 5px 5px;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
background-color: rgba(245, 245, 245, 1)/*#3498db; */
}
.nav {
width: 550px;
margin: 0 auto 0 auto;
text-align: center;
}
/* Navigation */
.nav {
font-family: Verdana, Georgia, Arial, sans-serif;
font-size: 14px;
}
.nav-items {
padding: 0;
list-style: none;
}
/* color of menu links
span {
color:yellow;
}
*/
.nav-item {
display: inline-block;
margin-right: 25px;
}
.nav-item:last-child {
margin-right: 0;
}
.nav-link,
.nav-link:link,
.nav-link:visited,
.nav-link:active,
.submenu-link,
.submenu-link:link,
.submenu-link:visited,
.submenu-link:active {
display: block;
position: relative;
font-size: 14px;
letter-spacing: 1px;
cursor: pointer;
text-decoration: none;
outline: none;
color: blue;
}
.nav-link::before {
content: "";
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 3px;
background: rgba(0, 0, 0, 0.2);
opacity: 0;
-webkit-transform: translate(0, 10px);
transform: translate(0, 10px);
transition: opacity 0.3s ease, transform 0.3s ease;
}
.nav-link:hover::before,
.nav-link:focus::before {
opacity: 1;
-webkit-transform: translate(0, 5px);
transform: translate(0, 5px);
}
.dropdown {
position: relative;
}
.dropdown .nav-link {
padding-right: 15px;
height: 17px;
line-height: 17px;
}
.dropdown .nav-link::after {
content: "";
position: absolute;
top: 6px;
right: 0;
border: 5px solid transparent;
border-top-color: blue;
/*small triangle showing drop down menu*/
}
.submenu {
position: absolute;
top: 100%;
left: 50%;
z-index: 100;
width: 200px;
margin-left: -100px;
background: blue;
border-radius: 3px;
line-height: 1.46667;
margin-top: -5px;
box-shadow: 0 0 8px rgba(0, 0, 0, .3);
opacity: 0;
-webkit-transform: translate(0, 0) scale(.85);
transform: translate(0, 0)scale(.85);
transition: transform 0.1s ease-out, opacity 0.1s ease-out;
pointer-events: none;
}
.submenu::after,
.submenu::before {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -10px;
border: 10px solid transparent;
height: 0;
}
.submenu::after {
border-bottom-color: blue;
}
.submenu::before {
margin-left: -13px;
border: 13px solid transparent;
border-bottom-color: rgba(0, 0, 0, .1);
-webkit-filter: blur(1px);
filter: blur(1px);
}
.submenu-items {
list-style: none;
padding: 10px 0;
}
.submenu-item {
display: block;
text-align: left;
}
.submenu-link,
.submenu-link:link,
.submenu-link:visited,
.submenu-link:active {
color: #3498db;
padding: 10px 20px;
}
.submenu-link:hover {
text-decoration: underline;
}
.submenu-seperator {
height: 0;
margin: 12px 10px;
border-top: 1px solid #eee;
}
.show-submenu .submenu {
opacity: 1;
-webkit-transform: translate(0, 25px) scale(1);
transform: translate(0, 25px) scale(1);
pointer-events: auto;
}
.submenu-link {
color: red;
}
.nav-link.is-active::before {
opacity: 1;
-webkit-transform: translate(0, 5px);
transform: translate(0, 5px);
}
<link rel="stylesheet" type="text/css" href="{% static 'css/_topnavbar.css' %}">
<!--Top Navigation-->
<nav role="navigation" class="nav" id="topnav">
<ul class="nav-items">
<li class="nav-item">
<span>Home</span>
</li>
<li class="nav-item ">
<span>Media</span>
<nav class="submenu">
<ul class="submenu-items">
<li class="submenu-item">Product #1</li>
<li class="submenu-item">Product #2</li>
<li class="submenu-item">Product #3</li>
</ul>
</nav>
</li>
<li class="nav-item">
<span>Search</span>
</li>
<li class="nav-item">
<span>Report</span>
</li>
<li class="nav-item dropdown">
<span>More</span>
<nav class="submenu">
<ul class="submenu-items">
<li class="submenu-item">About</li>
<li class="submenu-item">Contact</li>
<li class="submenu-item">
<hr class="submenu-seperator" />
</li>
<li class="submenu-item">Support</li>
<li class="submenu-item">FAQs</li>
</ul>
</nav>
</li>
</ul>
</nav>
<script type='text/javascript' src="{% static 'js/_topnavbar.js' %}"></script>
For as far as I'm concerned, what you are trying to achieve is possible with JS or adding a class to the element. But since you want only CSS, I don't think that's possible.
For if you changed your mind, this is how to do it with adding a class: How to give a different color to the current selected list item than other items in html?
For JavaScript/jQuery, I guess you could just add this:
<script>
$('.nav-items li a').click(function(event){
event.preventDefault();
$('.nav-items li a').removeClass('active')
$(this).addClass('active');
});
</script>
EDIT: This is more like what you need:
<script>
var page = window.location.pathname;
var elements = document.getElementsByClassname("nav-link");
if (page == "/index/"){
elements[0].style.textDecoration="underline";
}
</script>
I am trying to overflow my tooltip over the slider section (y axis).
Under the slider I have another slider with 9 elements (every one have a tooltip)
I want the slider below to be width 1170px with 5 elements. The remaining items should be hidden.
My English is poor so I mad short video 24s https://vimeo.com/216830963
And here is the code
section#slider {
width: 100%;
overflow: hidden;
padding-top: 110px;
padding-bottom: 0px;
height: 482px;
}
.wrap {
position: relative;
margin: 3em 0;
}
/* Frame */
.frame {
height: 130px;
line-height: 130px;
overflow-x: hidden;
/*overflow: hidden !important;*/
}
.frame ul {
list-style: none;
margin: 0;
padding: 0;
height: 100%;
font-size: 50px;
}
.frame ul li {
float: left;
width: 227px;
height: 100%;
margin: 0 2px 0 0;
padding: 0;
background: #f1f1f1;
color: #00b5f6;
text-align: center;
cursor: pointer;
/*border-right: 1px solid #00b5f6;*/
}
.frame ul li:hover {
color: #fff;
background: #00b5f6;
}
/* Scrollbar */
.scrollbar {
margin: 0 0 1em 0;
height: 2px;
background: #ccc;
line-height: 0;
}
.scrollbar .handle {
width: 100px;
height: 100%;
background: #292a33;
cursor: pointer;
}
.scrollbar .handle .mousearea {
position: absolute;
top: -9px;
left: 0;
width: 100%;
height: 20px;
}
/* setup tooltips */
.tooltip {
position: relative;
overflow: visible;
}
.tooltip:before,
.tooltip:after {
position: absolute;
display: inline-block;
opacity: 0;
pointer-events: none;
width: 225px;
overflow: visible;
}
.tooltip:after {
border-right: 6px solid transparent;
border-top: 6px solid #00b5f6;
border-left: 6px solid transparent;
content: '';
height: 0;
top: -5px;
left: 20px;
width: 0;
}
.tooltip:before {
background: #00b5f6;
border-radius: 2px;
color: #fff;
content: attr(data-title);
font-size: 14px;
padding: 6px 10px;
top: -145px;
left: 0px;
white-space: nowrap;
height: 130px;
max-width: 207px !important;
}
/* the animations */
/* expand */
.tooltip.expand:before {
transform: scale3d(.2, .2, 1);
transition: all .2s ease-in-out 0.5s;
}
.tooltip.expand:after {
transform: translate3d(0, 6px, 0);
transition: all .2s ease-in-out 0.5s;
}
.tooltip.expand:hover:before,
.tooltip.expand:hover:after {
opacity: 1;
transform: scale3d(1, 1, 1);
}
<section id="slider">
<img src="http://localhost/wh1/wp-content/uploads/2016/02/si.png">
</section>
<div style="width:1170px; height:180px; margin-left:auto; margin-right:auto;">
<div style="max-width: 100%;">
<div class="wrap" style="margin:15px 0 15px 0; ">
<div class="scrollbar">
<div class="handle">
<div class="mousearea"></div>
</div>
</div>
<div class="frame" id="basic">
<ul class="clearfix">
<li class="tooltip expand" data-title="Text tooltip">1</li>
<li class="tooltip expand" data-title="Text tooltip">2</li>
<li class="tooltip expand" data-title="Text tooltip">3</li>
<li class="tooltip expand" data-title="Text tooltip">4</li>
<li class="tooltip expand" data-title="Text tooltip">5</li>
<li class="tooltip expand" data-title="Text tooltip">6</li>
<li class="tooltip expand" data-title="Text tooltip">7</li>
<li class="tooltip expand" data-title="Text tooltip">8</li>
<li class="tooltip expand" data-title="Text tooltip">9</li>
</ul>
</div>
</div>
</div>
</div>
I don't know how to fix it. Please help if You can
Thanks
Because you want to have that tool tip showing on the top of the scroll frame, you need to include a new wrapper from that image slider on the top. I mean like this:
And the wrapper must be overflow-x: hidden;
With this approach you can make the tool tip visible and that overflow from the scrolling area hidden
Give #basic or .frame a specific width and then apply css Overflow property