I am developing a website of http://hcldesign.co.uk/ and have added a nav menu effect i found and integrated it onto my site using CSS.
The only problem is I can't figure out how to have the hover effect stay when i click the menu item and then the hover effect to also show on the current/active page/menu item. When i add the code i think it should be such as :Active this breaks the menu hover effect.
Current Code used for the menu is below
`a:focus {
color: #c9c9c9 !important;
text-decoration: none;
}
#menu-primary-menu {
font-family: 'roboto', roboto, roboto;
text-align: center;
text-transform: uppercase;
font-weight: 500;
letter-spacing: 1px;
}
#menu-primary-menu * {
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: all 0.35s ease;
transition: all 0.35s ease;
}
#menu-primary-menu li {
display: inline-block;
list-style: outside none none;
margin: 0em 1.5em;
padding: 0;
}
#menu-primary-menu a {
padding: 0.25em 0;
color: #fff;
position: relative;
text-decoration: none;
display: inline-block;
}
#menu-primary-menu a:before,
#menu-primary-menu a:after {
height: 3px;
position: absolute;
content: '';
-webkit-transition: all 0.35s ease;
transition: all 0.35s ease;
background-color: #3588dc;
width: 0;
}
#menu-primary-menu a:before {
top: 0;
left: 0;
}
#menu-primary-menu a:after {
bottom: 0;
right: 0;
}
#menu-primary-menu a:hover {
color: #fff;
}
#menu-primary-menu .active a {
color: #fff;
}
#menu-primary-menu a:hover:before,
#menu-primary-menu .current a:before,
#menu-primary-menu a:hover:after,
#menu-primary-menu .current a:after {
width: 100%;
}
#menu-primary-menu a {
font-size: 14px;
margin: -10px
}
Any help will be appreciated.
Thanks
Give each <body id="mypage-one"> a id. You also have to give your <nav> item like <li id="nav-page-one"> a id as well.
If you now going in your css that way, you'll have your effect you wish.
#mypage-one, #nav-page-one {
background-color: #2a88bd;
}
#mypage-two, #nav-page-two {
background-color: #2a88bd;
}
If your comma separated css selectors matches now, you'll get the background-color set to #2a88bd or how ever your hover effect is.
Hope you'll be successful.
I think when u using scrolling nav it's hard to do it as above. You can use jQuery to reach your goal. Look on this codepen how it works:
https://codepen.io/anon/pen/EvXVXm
$('.link').on('click', function(event) {
$('.link').removeClass('active');
$target = $(event.target);
$target.addClass('active');
});
I think it will be helpful.
Regards
Related
I have a nav bar on the left corner of the page. the nav bar is already set on margin-left: -120px; on hover, it transforms to 105px, so I would like to have smooth back when un-hover the element.
I have tried to use transition on the ul, ul li, ul li a, putting them in different classes. nothing really working with me...
/* ----- NAVBAR ----- */
ul {
position: fixed;
z-index: 99;
}
.li1{
animation: move1 2s;
}
.li2{
animation: move1 3s;
}
.li3{
animation: move1 4s;
}
.li4{
animation: move1 5s;
}
.li5{
animation: move1 6s;
}
ul li {
text-align: center;
list-style: none;
padding-top: 10px;
margin-left: -120px;
}
ul li a {
text-align: center;
display: block;
text-decoration: none;
height: 30px;
line-height: 30px;
font-size: 12px;
font-weight: 400;
letter-spacing: 5px;
background: #1a2738;
width: 140px;
color: #fff;
text-transform: capitalize;
border-radius: 15px;
}
ul li a:hover {
background: #1a2738;
color: #fff;
animation: move2 1s forwards;
}
#keyframes move1 {
0% {
opacity: 0;
transform: translate(-50px);
}
40% {
opacity: 100;
transform: translate(105px);
}
}
#keyframes move2 {
100% {
transform: translate(105px);
}
}
I hope to know what's the actual problem, help please, thanks!
I think you are over complicating the CSS using keyframes you can use a transition instead see below code:
/* ----- NAVBAR ----- */
ul {
position: fixed;
z-index: 99;
}
ul li {
text-align: center;
list-style: none;
padding-top: 10px;
margin-left: -120px;
}
ul li a {
text-align: center;
display: block;
text-decoration: none;
height: 30px;
line-height: 30px;
font-size: 12px;
font-weight: 400;
letter-spacing: 5px;
background: #1a2738;
width: 140px;
color: #fff;
text-transform: capitalize;
border-radius: 15px;
transition: transform 1s ease-in-out;
transform: translateX(-50px);
}
ul li a:hover {
background: #1a2738;
color: #fff;
transform: translateX(105px);
}
If you are looking for a simple slide out and slide back in effect, one way to approach it is to simple use transform: transitionX(-120px) on your ul element, and just readjust the value from -120px to 0px on the hover of the ul, like so:
ul {
list-style-type: none;
padding: 1em;
background-color: #ececec;
color: #333;
display: inline-block;
transition: transform 600ms;
transform: translateX(-120px);
}
ul:hover {
transform: translateX(0px); //you can adjust this measurement unit to whatever value you wish, such as 105px
}
ul li {
text-align: center;
list-style: none;
padding-top: 10px;
}
ul li a {
text-align: center;
display: block;
text-decoration: none;
height: 30px;
line-height: 30px;
font-size: 12px;
font-weight: 400;
letter-spacing: 5px;
background: #1a2738;
width: 140px;
color: #fff;
text-transform: capitalize;
border-radius: 15px;
}
<ul>
<li>Home</li>
<li>About</li>
<li>contact</li>
</ul>
I am making a website: Website. In the menubar I have an underline when a specifi menu is active, or you hover over the menu options.
I would like that there is some px space from the menu text to the underline. How is that possible?
I tried to set a border-bottom:1px solid white, but that does not do the trick for me.
It is the following CSS the underline is on:
.wpmega-black-white .wpmm-mega-wrapper > li:hover,
.wpmega-black-white .wpmm-mega-wrapper > li.current-menu-item {
text-decoration: underline;
margin-top: 0.8em;
transition: all ease 0.3s;
-webkit-transition: all ease 0.3s;
-ms-transition: all ease 0.3s;
}
Edited
delete previous codes and modify your CSS as I wrote:
in your CSS files /css/style.css?ver=4.9.4 find and change these block of codes. please have a backup before modifinig
please note that you should not delete other parameters of elements, only change what I wrote.
.wp-megamenu-main-wrapper.wpmm-orientation-horizontal ul.wpmm-mega-wrapper > li > a {
padding: 20px 15px 10px 20px;
}
.wp-megamenu-main-wrapper.wpmm-orientation-horizontal ul.wpmm-mega-wrapper > li.current-menu-item a, .wp-megamenu-main-wrapper.wpmm-orientation-vertical ul.wpmm-mega-wrapper > li.current-menu-item a{
border-bottom: 2px solid #FFF;
}
.wp-megamenu-main-wrapper.wpmm-orientation-horizontal.wpmm-askins-wrapper ul.wpmm-mega-wrapper > li.menu-item-has-children > a:after {
top: 60%;
}
add this to your own css file
.wp-mega-menu-link:hover {
border-bottom: 2px solid #FFF;
}
text-decoration does exactly what is says it does, underline the text...you can't move the location of that underline (yet). You would have to use a positioned pseudo-element on the inner span.
For example:
ul {
list-style: none;
background: #000;
}
li {
display: inline-block;
}
li>a {
color: white;
padding: 20px 15px 20px 20px;
position: relative;
display: block;
font-size: 16px;
font-weight: 400;
font-style: normal;
line-height: 1.6;
overflow: visible;
font-family: "Work Sans", Helvetica, Arial, sans-serif;
text-transform: capitalize;
text-align: left;
text-decoration: none;
}
li>a span {
position: relative;
}
li>a span::after {
content: "";
position: absolute;
bottom: -10px;
/* adjust spacing here */
left: 0;
width: 0%;
height: 1px;
transition: width .3s ease;
background: transparent;
}
li>a.current-item span::after {
background: currentcolor;
width: 100%;
}
li>a:hover span::after {
width: 100%;
background: currentcolor;
}
<ul>
<li><span>MY TEXT HERE</span></li>
<li><span>MY NEW ITEM</span></li>
</ul>
This also means they can be animated.
The problem in my code is that it is not rotating the :before ( { ) and :after ( } ) elements.
It rotates only if I set position: absolute on them, which disturbs their position and makes it difficult to bring back in wanted position
Can someone explain why this is happening?
Update: this code is working fine in chrome and IE 11 but not firefox. with firefox above problem
/* you should start reading from here..... */
a:before{
opacity: 0;
content: '{';
font-size: 40px;
line-height: 1;
transition: opacity 0.3s, transform 0.4s;
}
a:after{
opacity: 0;
content: '}';
font-size: 40px;
line-height: 1;
transition: opacity 0.3s, transform 0.4s;
}
a:hover:after{
opacity: 1;
transform: rotateX(1turn);
}
a:hover:before{
opacity: 1;
transform: rotateX(1turn);
}
/* no need to read after this */
a{
text-decoration: none;
color: black;
transition: color 0.3s;
position: relative;
}
a:hover{
color: red;
}
body{
margin: 0;
padding: 0;
font-size: 25px;
color: black;
font-weight: 700;
line-height: 1;
}
.nav{
display: block;
margin: 100px auto;
width: 80%;
text-align: center;
}
ul{
list-style: none;
display: inline-block;
padding: 0;
margin: 0;
border-top: 2px solid black;
border-bottom: 2px solid black;
}
li{
float: left;
margin: 0 20px;
padding: 15px 10px;
}
li a{
margin: 0;
padding: 0;
}
ul:after{
content: '';
display: table;
clear: both;
}
<div class="nav">
<ul>
<li>HELLO</li>
<li>HELLO</li>
<li>HELLO</li>
<li>HELLO</li>
<li>HELLO</li>
</ul>
</div>
giving the :before and :after element display: inline-block; does the trick.
I'm working on a menu and having some trouble with text not appearing the way I'd like it to.
Here is a screenshot of what I'm having trouble with. There appears to be extra space below the link—the top and bottom aren't equal. There is no padding there, either. It is just a link within an <li>. What do I have wrong?
ul {
list-style-type: none;
height: 184px;
text-align: right;
padding: 0;
font-weight: 300;
}
li {
display: inline-block;
width: 50%;
text-align: left;
}
a:link, a:active {
font-size: 16px;
color: #000;
text-decoration: none;
-webkit-transition: background-color 0.3s, border-color 0.3s;
transition: background-color 0.3s, border-color 0.3s;
line-height: 2em;
}
a:hover {
background-color: #adadad;
}
a {
width: 100%;
padding: 0 0.5em;
}
<ul>
<li>Home</li>
<li>About</li>
<li>Contact Us</li>
</ul>
I see no issues. Apply your css styles to your A tag though, not the li. Also, for clarity to see what is going on, I put a border around each a tag. Check out the fiddle, everything looks fine to me. Height in DIV's is automatic if you don't set it statically. i.e., it all looks fine, I see no extra spacing with the CSS I provided below.
http://jsfiddle.net/4dbuuuq4/
CSS
ul {
list-style-type: none;
height: 184px;
padding: 0;
font-weight: 300;
}
li a {
display: inline-block;
width: 50%;
text-align: left;
border:solid 1px #ccc;
}
li a:hover{
cursor:pointer;
background-color:#ccc;
color:#fff;
}
a:link,
a:active {
font-size: 16px;
color: #000;
text-decoration: none;
-webkit-transition: background-color 0.3s, border-color 0.3s;
transition: background-color 0.3s, border-color 0.3s;
}
a {
width: 100%;
padding: 0 0.5em;
}
You can use display: table-cell instead of inline-block and use height instead of line-height on a:
ul {
list-style-type: none;
height: 184px;
text-align: right;
padding: 0;
font-weight: 300;
}
li {
display: inline-block;
width: 50%;
text-align: left;
}
a:link,
a:active {
font-size: 16px;
color: #000;
text-decoration: none;
-webkit-transition: background-color 0.3s, border-color 0.3s;
transition: background-color 0.3s, border-color 0.3s;
}
a:hover {
background-color: #adadad;
}
ul li a {
width: 100%;
padding: 0 0.5em;
display: table-cell;
vertical-align: middle;
height: 2em;
}
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact Us
</li>
</ul>
I'm trying to create a mobile navigation with the :target pseudo-class. My problem is when i open the navigation the open button don't hide to get the close button visible.
This don't work -> #nav-menu:target #mobile-menu-open
This is my code:
HTML
<nav>
<ul id="nav-menu">
<li>Side A</li>
<li>Side B</li>
</ul>
</nav>
CSS
nav {
clear: both;
text-align: left;
height: 24px;
margin: auto;
position: relative;}
#nav-menu {
display: none;}
#nav-menu li {
display: block;
text-align: left;
padding: 11px 8px;
font-weight: bold;
font-size: 14px;}
#nav-menu a:link, #nav-menu a:visited {
color:#CCC;
text-decoration: none;
transition: all 0.15s ease-in-out;}
#nav-menu a:hover, #nav-menu a:visited hover {
color:#FFF;
text-decoration: none;
transition: all 0.15s ease-in-out;}
#mobile-menu-open {
display: block;}
#mobile-menu-close {
display: none;}
#mobile-menu-open, #mobile-menu-close {
width: 24px;
height: 18px;
background: url(../bilder/mobile-menu-button.png) bottom no-repeat;
margin-top: 91px;
padding-left: 9px;
opacity: 0.75;
filter: alpha(opacity=50);
transition: all 0.3s ease-in-out;}
#mobile-menu-open:hover, #mobile-menu-close:hover {
opacity: 1.0;
filter: alpha(opacity=100);}
#nav-menu:target {
display: block;
padding-top: 11px;
background: #333;}
#nav-menu:target #mobile-menu-open {
display: none;}
#nav-menu:target #mobile-menu-close {
display: block;}
OK here is an example of it
Fiddle
you need to add + to this #nav-menu:target + #mobile-menu-open
I got it :D
I just put the id="nav-menu" to the and changed the css show and hide navigation to #nav-menu ul ...
The problem was that after targeting the #nav-menu the button where outside the div ... hope my explanation is understandable ...
Greetz, Björn