I am creating a navbar and when I want to add hover effect over links its not working, I want to add transform property to the after element of links but its not working.
#navbar {
display: flex;
justify-content: space-between;
align-items: center;
}
.link-list {
display: flex;
gap: 2rem;
}
.menu-link {
color: var(--white);
text-decoration: none;
position: relative;
}
.menu-link::after { /*this is for the bottom border line which is 25% in length*/
background: var(--white);
content: "";
width: 50%;
height: 2px;
position: absolute;
left: 25%;
bottom: -4px;
transform: scaleX(0); /*i am adding transform 0 */
transform-origin: center;
transition: transform 500ms ease;
}
.menu-link:hover .menu-link::after{ /* unable to get this effect on hover */
transform: scaleX(1);
}
Link lists
<section class="link-list">
About
Careers
Events
Products
Explore
</section>
The meaning of scale is size * argument.
scaleX(0) will *0 so your element will disappear.
scaleX(1) will *1 so your element won't change.
Use the number bigger than 1 or smaller than 1 to do it.
#navbar {
display: flex;
justify-content: space-between;
align-items: center;
}
.link-list {
display: flex;
gap: 2rem;
}
.menu-link {
color: var(--white);
text-decoration: none;
position: relative;
}
.menu-link::after { /*this is for the bottom border line which is 25% in length*/
background: var(--white);
content: "";
width: 50%;
height: 2px;
position: absolute;
left: 25%;
bottom: -4px;
transform: scaleX(0); /*i am adding transform 0 */
transform-origin: center;
transition: transform 500ms ease;
}
.menu-link:hover .menu-link::after{ /* unable to get this effect on hover */
transform: scaleX(1);
}
"<section class="link-list">
<a href="#" class="menu-link">About</a
><a href="#" class="menu-link">Careers</a
><a href="#" class="menu-link">Events</a
><a href="#" class="menu-link">Products</a
>Explore
</section>"
Related
I have found questions similar to mine but can't find a solution that will work. I have my nav links centered horizontally in my header with my logo in the very center. My links are spread out evenly across the width of the screen. I need to bring my nav links in closer together and closer to my logo. I'm at a loss and don't know what else to try. This is also making my hover effect (underline) stretch out much farther than the width of each word. Thanks in advance for your help.
body {
margin: 0;
line-height: 1.2em;
font-family: Arial, Helvetica, sans-serif;
}
html, body{
height: 100%;
}
.cc_nav {
display: flex;
flex-direction: row;
width: 100%;
margin-top: 0;
padding-top: 10px;
height: 20%;
align-items: center;
justify-content: center;
overflow: hidden;
position: fixed;
top: 0;
background-color: white;
text-align: center;
}
a{
text-decoration: none;
color: rgba(0,0,0,0.8);
font-family: Tenar Sans;
font-size: .8em;
flex: 1;
}
a {
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
overflow: hidden;
}
a:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0;
left: 0;
background-color: rgb(192,192,192);
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s; }
a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
<header>
<div class="cc_nav" id="centered_nav">
HOME
SERVICES
ABOUT
<img src="images/logo_6.png" alt="Claire Crawford" id="logo_Claire" />
PORTFOLIO
BLOG
GET IN TOUCH
</div>
</header>
Using flex: 1 makes items grow proportionately to fill the container. You might consider using flex: 0 0 auto so that items cannot grow or shrink beyond their default widths.
I've also added left and right margins so that the items don't run together.
body {
margin: 0;
line-height: 1.2em;
font-family: Arial, Helvetica, sans-serif;
}
html,
body {
height: 100%;
}
.cc_nav {
display: flex;
flex-direction: row;
width: 100%;
margin-top: 0;
padding-top: 10px;
height: 20%;
align-items: center;
justify-content: center;
overflow: hidden;
position: fixed;
top: 0;
background-color: white;
text-align: center;
}
a {
text-decoration: none;
color: rgba(0, 0, 0, 0.8);
font-family: Tenar Sans;
font-size: .8em;
margin: 0 1em;
flex: 0 0 auto;
}
a {
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
overflow: hidden;
}
a:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0;
left: 0;
background-color: rgb(192, 192, 192);
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
a:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
<header>
<div class="cc_nav" id="centered_nav">
HOME
SERVICES
ABOUT
<img src="images/logo_6.png" alt="Claire Crawford" id="logo_Claire" />
PORTFOLIO
BLOG
GET IN TOUCH
</div>
</header>
For reference, see flex.
Incidentally, there also seems to be a typo in your code; the closing </div> tag shows as an opening <div> tag.
I am on my phone now so I can't rewrite the code for you but I can recommend Bootstrap Flex Box instead. It's really helpful. Helped me many times. https://getbootstrap.com/docs/4.0/utilities/flex/
Try this in bootstrap 4
<div class="d-flex flex-column">
<div class="p-2">Flex item 1</div>
<div class="p-2">Flex item 2</div>
<div class="p-2">Flex item 3</div>
</div>
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>
No, I have no code to demonstrate but I have been wondering: Is it possible to change a font-awesome logo with just transition? Such as: Change the class? I did a little bit of research on w3schools and How can create transition effect in font awesome icon found this link aswell, but they didn't really help and this question has been with me for a long time.
so, the question is: Is it possible to make a logo change (font awesome) with css transition or do I need javascript for it?
in case the question shouldn't be posted here. please tell me where it should so I can move it.
Cheers,
Here you go:
This has been done here: https://codepen.io/toaster99/pen/BpgzQR
HTML:
<div id="container">
<div class="button">
<div class="icons">
<i class="fa fa-apple icon-default"></i>
<i class="fa fa-arrow-circle-down icon-hover"></i>
</div>
Download
</div>
</div>
CSS:
#attribution {
position: fixed;
right: 10px;
bottom: 10px;
color: #FE8989;
z-index: 100;
font-weight: bold;
cursor: pointer;
a {
color: inherit;
text-decoration: inherit;
}
}
#container {
background: linear-gradient(#8affff,#80eded);
position: relative;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
}
.button {
position: relative;
margin-bottom: 40px;
display: inline-flex;
justify-content: center;
align-items: center;
background: #FE8989;
box-shadow: 0px 0px 0 0px rgba(0,0,0,0);
border-radius: 50px;
width: 25.25rem;
padding: 1rem 0;
font-family: 'Montserrat', sans-serif;
font-weight: 600;
font-size: 2.75rem;
color: white;
cursor: pointer;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
.icons {
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin: 0 2.3rem 0 0;
width: 1.25rem;
height: 2.6rem;
i {
position: absolute;
top: 0;
left: 0;
display: block;
}
.icon-default {
transition: opacity .3s, transform .3s;
}
.icon-hover {
transition: opacity .3s, transform .3s;
transform: rotate(-180deg) scale(.5);
opacity: 0;
}
}
&:hover {
transform: scale(1.2);
box-shadow: 20px 15px rgba(0,0,0,0.15);
.icon-hover {
transform: rotate(0deg) scale(1);
opacity: 1;
}
.icon-default {
transform: rotate(180deg) scale(.5);
opacity: 0;
}
}
}
yes, its pretty simple after you see the solution but I was confused too which led me to this post.
css
#keyframes pulse {
0% {
color:transparent;
}
50% {
color: #065803;
}
75% {
color:rgb(113, 139, 0);
}
100% {
color: #065803;
}
0% {
color:rgb(189, 176, 1);
}
}
#linked{
font-size: 16.5rem;
color: white;
display: flex;
justify-content: center;
}
i{
animation: pulse 8s infinite ease;
} ```
HTML
<i id="linked" class="fab fa-linkedin"></i>
</a>
</div>
<div class="col-2-of-2">
<a href="projects.html" target="_blank">
<i id="linked" class="fas fa-code"></i>
</a>
```
I wan the arrows on my navbar to produce the animation I've created when I hover the options on top of them,
When my mouse hovers "contact", "register" or "login", the arrows under them should move down indicating that they are dropdown buttons, how can I do this? I already have the code of the animation but I don't know how to sync this code with my buttons, I would appreciate any help. Here's the code:
#arrow1 {
position: absolute;
top: 11%;
left: 83.5%;
transform: translate(-50%, -50%);
width: 15px;
height: 100px;
text-align: center;
line-height: 110px;
color: white;
font-size: 30px;
overflow: hidden;
color: yellow;
}
#arrow1 {
margin: 0;
padding: 0;
animation: animate 1s;
right: 0;
pointer-events: none;
}
#keyframes animate {
50% {
transform: translateX(-8px);
margin-top: -35px;
}
}
#arrow2 {
position: absolute;
top: 11%;
left: 66%;
transform: translate(-50%, -50%);
width: 15px;
height: 100px;
text-align: center;
line-height: 110px;
color: white;
font-size: 30px;
overflow: hidden;
color: yellow;
}
#arro2 {
margin: 0;
padding: 0;
animation: animate 1s;
right: 0;
pointer-events: none;
}
#keyframes animate {
50% {
transform: translateX(-8px);
margin-top: -35px;
}
}
#arrow3 {
position: absolute;
top: 11%;
left: 48.7%;
transform: translate(-50%, -50%);
width: 15px;
height: 100px;
text-align: center;
line-height: 110px;
color: white;
font-size: 30px;
overflow: hidden;
color: yellow;
}
#arrow3 {
margin: 0;
padding: 0;
animation: animate 1s;
right: 0;
pointer-events: none;
}
#keyframes animate {
50% {
transform: translateX(-8px);
margin-top: -35px;
}
}
<ul>
<li id="inicio">INICIO</li>
<li id="contacto">CONTACTO</li>
<li id="registrate">REGISTRATE</li>
<li id="ingresar">INGRESAR</li>
<div class="circle">
<i class="fas fa-angle-down" id="arrow1"></i>
<i class="fas fa-angle-down" id="arrow2"></i>
<i class="fas fa-angle-down" id="arrow3"></i>
</div>
</ul>
Since you have your animation assigned to each arrow ID, that animation is playing on page load.
To have the animation play only when the cursor is hovering over the element, you need to add a :hover pseudo-class to each arrow and add the animation within that block.
#arrow1:hover {
animation: animate 1s;
}
After doing that, you should have something like this:
#container {
width: 100%;
height: 80px;
background: #151515;
}
#container,
.navItem {
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
transform: translateZ(0);
}
.navItem {
cursor: pointer;
}
.navItem:hover .arrow {
animation: animate 1s;
}
.navText {
font-family: 'Arial', sans-serif;
color: #fff;
text-transform: uppercase;
letter-spacing: 1px;
}
.arrow {
position: absolute;
color: #ffff4c;
bottom: -15px;
}
#keyframes animate {
50% {
transform: translateY(8px);
margin-top: -35px;
}
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div id="container">
<div class="navItem">
<div class="navText">
Contacto
</div>
<i class="fas fa-angle-down arrow"></i>
</div>
</div>
You may notice that I also edited the HTML and CSS for that example, but the idea is the same. This brings me to my next point, and something that may help you.
Classes
Using ID's is a perfectly acceptable way to write your markup and use CSS to style; however, using id as opposed to class can be cumbersome. Since you have multiple arrows, I would advise using classes as opposed to ID's.
So, all of your arrows would be assigned a class. In my example, I used a simple .arrow class. This is proper CSS styling. ID's are unique and should only be used sparingly, usually only once in a document. Classes are reused.
I should also note that this is purely a syntactical thing. CSS will treat ID's and classes similarly if you require it.
Transitions
You may have also noticed that the animation in my example stops if you hover away from the navItem. This is expected behavior if using a :hover pseudo-class on an element. A workaround is substituting an animation for a transition.
Transitions are an alternate way to apply animated properties to elements. They will animate 'forward' and 'backward' on, say, pseudo-classes like :hover and :focus.
Here's what that example looks like with a transition in place of an animation.
#container {
width: 100%;
height: 80px;
background: #151515;
}
#container,
.navItem {
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
transform: translateZ(0);
}
.navItem {
cursor: pointer;
}
.navItem:hover .arrow {
transform: translateY(8px);
}
.navText {
font-family: 'Arial', sans-serif;
color: #fff;
text-transform: uppercase;
letter-spacing: 1px;
}
.arrow {
position: absolute;
color: #ffff4c;
bottom: -15px;
transition: all 1s;
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div id="container">
<div class="navItem">
<div class="navText">
Contacto
</div>
<i class="fas fa-angle-down arrow"></i>
</div>
</div>
So this gives you a much smoother interaction when hovering over a menu.
Pseudo Elements
Lastly, I want to touch up on using Pseudo Elements for things like icons. They're useful for adding additional children to a parent element, without affecting your written markup.
We can replace the arrows with a pseudo-element to clean up our HTML, as well as creating a more manageable workspace. Here's that example, again, but using a pseudo-element in place of HTML for the arrow.
#container {
width: 100%;
height: 80px;
background: #151515;
}
#container,
.navItem {
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
transform: translateZ(0);
}
.navItem {
cursor: pointer;
}
.navItem:hover .navText::after {
transform: translateY(8px);
}
.navText {
font-family: 'Arial', sans-serif;
color: #fff;
text-transform: uppercase;
letter-spacing: 1px;
text-align: center;
}
.navText::after {
content: "\f107";
font-family: 'FontAwesome';
color: #FFFF00;
position: absolute;
transition: all 1s;
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div id="container">
<div class="navItem">
<div class="navText">
Contacto
</div>
</div>
</div>
Conclusion
Should you have any further questions, I'd be happy to answer them and go more in depth.
I also leave you with this final example via Codepen:
https://codepen.io/jeffheral/pen/NYKbZq
The HTML tags may not be what you want, but feel free to change them. The important thing is we have a solid setup of ID's and classes. If you want to add more navigation items, you only need to add more HTML to your document.
Instead of targetting every arrow individually, you can use a more generic solution:
.menu {
display: flex;
list-style: none;
background-color: #444;
}
.menu li {
padding: 10px 15px;
cursor: pointer;
padding-bottom: 20px;
position: relative;
margin: 5px;
color: white;
font-weight: bold;
font-family: sans-serif;
}
.menu li:after {
font-family: FontAwesome;
font-size: 20px;
font-weight: bold;
content: '\f107';
display: inline-block;
color: yellow;
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 0);
transition: transform 0.3s ease;
}
.menu li:hover {
background-color: rgba(0, 0, 0, 0.25);
}
.menu li:hover:after {
transform: translate(-50%, 5px);
}
<ul class="menu">
<li>INICIO</li>
<li>CONTACTO</li>
<li>REGISTRATE</li>
<li>INGRESAR</li>
</ul>
I have a small issue, I need to rotate 2 spans and create a perfect 'X'.
I've created a JSfiddle for this. Can you guys help me?
I can't seem to get my head around how much should i transform origin...
HTML
<div class="toggle-btn">
<span></span>
<span></span>
</div>
SASS
.toggle-btn {
width: 38px;
height: 19px;
cursor: pointer;
position: relative;
margin-top: 18px;
text-align: center;
&:after {
content: '';
display: block;
clear: both;
}
span {
height: 2px;
margin: 5px 0px;
background: #333;
width: 100%;
display: block;
transition: .15s ease-in;
text-align: center;
&.toggled {
&:nth-of-type(1) {
transform: rotate(-45deg);
transform-origin: 22px 9px;
}
&:nth-of-type(2) {
transform: rotate(45deg);
transform-origin: 20px -5px;
}
}
}
}
and JS
$('.toggle-btn').on('click',function(){
$(this).find('span').toggleClass('toggled');
});
This appears to work. I had to adjust the margin to 4px. The rotation needs to come after the x/y translation because translating after the rotation appears to change the point of origin on which the element is rotating instead of origin of the element. You can observe this behavior by trying a large (100px) x-translation after the rotation.
.toggle-btn {
width: 38px;
height: 19px;
cursor: pointer;
position: relative;
margin-top: 18px;
text-align: center;
overflow: show;
&:after {
content: '';
display: block;
clear: both;
}
span {
height: 2px;
margin: 4px 0px;
background: #333;
width: 38px;
display: block;
transition: .15s ease-in;
text-align: center;
&.toggled {
&:nth-of-type(1) {
transform: translate(0px, 3px) rotate(-45deg);
}
&:nth-of-type(2) {
transform: translate(0px, -3px) rotate(45deg);
}
}
}
}