Difference between .bttn:before and .bttn:hover:before [duplicate] - html

This question already has answers here:
How can I write a ':hover' condition for 'a:before' and 'a:after'?
(7 answers)
Closed 4 years ago.
I used the following code snippet to get the effect on the Submit buttons in the form.
Codepen Link
HTML:
a.bttn-dark:hover {
color: #FFF;
}
a.bttn-dark:focus {
color: #FFF;
}
.bttn:before {
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
position: absolute;
top: 0;
left: 50%;
right: 50%;
bottom: 0;
opacity: 0;
content: '';
background-color: #FF0072;
z-index: -2;
}
.bttn:hover:before {
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
left: 0;
right: 0;
opacity: 1;
}
<div class="flex">
Continue
</div>
<div class="flex dark">
Continue
</div>
I am confused about the usage of following,
what would be different if a:hover is only used instead of a.bttm-dark:hover ?
bttn:before and bttn:hover:before
why is the pseudo element bttn:hover appearing in the HTML document after bttn element? Shouldn't it come before?

Follow below css code.
CSS:
a.bttn {
color: #FF0072;
text-decoration: none;
}
a.bttn-dark {
color: #644cad;
text-decoration: none;
}
a.bttn:hover {
color: #FFF;
}
a.bttn-dark:hover {
color: #FFF;
}
a.bttn-dark:focus {
color: #FFF;
}
.bttn {
font-size:18px;
letter-spacing:2px;
text-transform:uppercase;
display:inline-block;
text-align:center;
width:270px;
font-weight:bold;
padding:14px 0px;
border:3px solid #FF0072;
border-radius:2px;
position:relative;
box-shadow: 0 2px 10px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.1);
}
.bttn:before {
-webkit-transition:0.5s all ease;
transition:0.5s all ease;
position:absolute;
top:0;
left:50%;
right:50%;
bottom:0;
opacity:0;
content:'';
background-color:#FF0072;
z-index:-2;
}
.bttn:hover {
-webkit-transition:0.5s all ease;
transition:0.5s all ease;
left:0;
right:0;
opacity:1;
}
.bttn:focus {
transition:0.5s all ease;
left:0;
right:0;
opacity:1;
}
.bttn:hover:before {
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
left: 0;
right: 0;
opacity: 1;
}
.bttn-dark {
font-size:18px;
letter-spacing:2px;
text-transform:uppercase;
display:inline-block;
text-align:center;
width:270px;
font-weight:bold;
padding:14px 0px;
border:3px solid #644cad;
border-radius:2px;
position:relative;
box-shadow: 0 2px 10px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.1);
}
.bttn-dark:before {
-webkit-transition:0.5s all ease;
transition:0.5s all ease;
position:absolute;
top:0;
left:50%;
right:50%;
bottom:0;
opacity:0;
content:'';
background-color:#644cad;
z-index:-2;
}
.bttn-dark:hover {
-webkit-transition:0.5s all ease;
transition:0.5s all ease;
left:0;
right:0;
opacity:1;
}
.bttn-dark:focus {
transition:0.5s all ease;
left:0;
right:0;
opacity:1;
}
.bttn-dark:hover:before {
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
left: 0;
right: 0;
opacity: 1;
}

Related

Use overlay effect several times on the same page, with different content (pure CSS)

I would like to use and adapt to my need this pure CSS overlay effect:
My need is to use this effect three times, on the same page, with different content when I click, how can I separate them? When I simply copy the whole DIV and I change the content, only the last content will be applied on the three DIV
HTML
<input type="checkbox" id="op"></input>
<div class="lower">
<label for="op">click the text</label>
</div>
<div class="overlay overlay-hugeinc">
<label for="op"></label>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Clients</li>
<li>Contact</li>
</ul>
</nav>
</div>
CSS
#import "http://webfonts.ru/import/notcourier.css";
body{
background:url('http://cs625217.vk.me/v625217712/1a11c/0QgZ5V0MWEo.jpg');
}
.lower{
width:340px;
margin:10% auto;
padding:50px;
background:white;
opacity:0.8;
color:black;
box-shadow:inset 0 0 0 1px black;
border:30px solid white;
}
.lower:hover{
background:black;
color:white;
box-shadow:inset 0 0 0 1px white;
border:30px solid black;
}
input{
display:none;
}
.lower label{
font-family: 'NotCourierSans';
text-transform:uppercase;
font-size:40px;
text-align:center;
}
.lower label:hover{
cursor:pointer;
}
.overlay{
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0,0,0,0.9);
}
.overlay label{
width: 58px;
height:58px;
position: absolute;
right: 20px;
top: 20px;
background: url('http://tympanus.net/Development/FullscreenOverlayStyles/img/cross.png');
z-index: 100;
cursor:pointer;
}
.overlay nav {
text-align: center;
position: relative;
top: 50%;
height: 60%;
font-size: 54px;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.overlay ul {
list-style: none;
padding: 0;
margin: 0 auto;
display: inline-block;
height: 100%;
position: relative;
}
.overlay ul li {
display: block;
height: 20%;
height: calc(100% / 5);
min-height: 54px;
}
.overlay ul li a {
font-weight: 300;
display: block;
color: white;
text-decoration:none;
-webkit-transition: color 0.2s;
transition: color 0.2s;
font-family: 'NotCourierSans';
text-transform:uppercase;
}
.overlay ul li a:hover,
.overlay ul li a:focus {
color: #849368;
}
.lower~.overlay-hugeinc{
opacity: 0;
visibility: hidden;
-webkit-transition: opacity 0.5s, visibility 0s 0.5s;
transition: opacity 0.5s, visibility 0s 0.5s;
}
#op:checked~.overlay-hugeinc{
opacity: 1;
visibility: visible;
-webkit-transition: opacity 0.5s;
transition: opacity 0.5s;
}
.overlay-hugeinc nav {
-moz-perspective: 300px;
}
.overlay-hugeinc nav ul {
opacity: 0.4;
-webkit-transform: translateY(-25%) rotateX(35deg);
transform: translateY(-25%) rotateX(35deg);
-webkit-transition: -webkit-transform 0.5s, opacity 0.5s;
transition: transform 0.5s, opacity 0.5s;
}
#op:checked~.overlay-hugeinc nav ul {
opacity: 1;
-webkit-transform: rotateX(0deg);
transform: rotateX(0deg);
}
#op:not(:checked)~.overlay-hugeinc nav ul {
-webkit-transform: translateY(25%) rotateX(-35deg);
transform: translateY(25%) rotateX(-35deg);
}

CSS Transition on hover: animate mouse-out as well

I want to animate a css-arrow (pointing to the left) on hover to move slightly right on hover and stay there. Once the mouse hovers out the arrow it should move backwards with the animation as well.
#-webkit-keyframes arrow-left {
0% {
-webkit-transform: translateX(0);
transform:translateX(0);
}
20% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
100% {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
}
}
#keyframes arrow-left {
0% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
20% {
-webkit-transform:translateX(0);
transform:translateX(0);
}
100% {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
}
}
.arrow-icon.left:hover {
-webkit-animation:arrow-left 0.35s ease-in;
animation:arrow-left 0.35s ease-in;
-webkit-transform-origin:50% 0%;
-ms-transform-origin:50% 0%;
transform-origin:50% 0%
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
Any idea on how to make the animation out work as well, so it animates back and doesn't jump back?
https://jsfiddle.net/gsvjwxxj/
Instead of using keyframes to perform the translate, use transition plus cubic-bezier.
$(document).ready(function(){
$('.menu-icon').click(function(){
$(this).toggleClass('open');
});
/*setTimeout(function () {
$('.mouse-icon').fadeOut(250, function() { $(this).remove(); });
}, 5000);*/
});
* {
margin: 0;
padding: 0;
}
body {
margin: 100px;
}
/* ---------------------------------------------- /*
* Animated arrow icon
/* ---------------------------------------------- */
.arrow-icon {
position: relative;
width:26px;
height:4px;
background:#000;
cursor: pointer;
-webkit-transition: width .15s ease-in-out, -webkit-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
-moz-transition: width .15s ease-in-out, -moz-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
-o-transition: width .15s ease-in-out, -o-transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
transition: width .15s ease-in-out, transform 0.3s cubic-bezier( 0.42, 0.08, 0.18, -0.24);
}
.arrow-icon.left:hover, .arrow-icon.right:hover {
width:36px;
}
.arrow-icon.down:hover, .arrow-icon.up:hover {
height:36px;
}
.arrow-icon.down:hover:after{
top: 15px;
}
.arrow-icon:before {
position:absolute;
content:"";
}
.arrow-icon.left:before, .arrow-icon.right:before {
width: 52px;
height: 26px;
}
.arrow-icon.down:before, .arrow-icon.up:before {
width: 26px;
height: 52px;
}
.arrow-icon:before {
position:absolute;
content:"";
width: 52px;
height: 26px;
}
.arrow-icon.left:before {
top: -12px;
left: -12px;
}
.arrow-icon.right:before {
top: -12px;
left: -12px;
}
.arrow-icon.down:before {
top: -12px;
left: -12px;
}
.arrow-icon.up:before {
top: -12px;
left: -12px;
}
.arrow-icon:after {
position:absolute;
content:"";
transform:rotate(45deg);
top:-8px;
width:16px;
height:16px;
background:transparent;
border-color: #000;
}
.arrow-icon.left:after{
border-left:4px solid;
border-bottom:4px solid;
}
.arrow-icon.right:after{
right:0;
border-right:4px solid;
border-top:4px solid;
}
.arrow-icon.down, .arrow-icon.up {
width: 4px;
height: 26px;
left: 10px;
}
.arrow-icon.down:after{
top: 6px;
left:-8px;
border-right:4px solid;
border-bottom:4px solid;
}
.arrow-icon.up:after {
top:0px;
left:-8px;
border-right:4px solid;
border-top:4px solid;
transform:rotate(-45deg);
}
.arrow-icon.left{
-webkit-transform-origin:50% 0%;
-ms-transform-origin:50% 0%;
transform-origin:50% 0%;
}
.arrow-icon.left:hover {
transform:translateX(-12px);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="arrow-icon left"></div>
you don't have to use animation for this. you can just use transform:translateX(-12px)
see here > fiddle
or snippet below :
let me know if it helps
* {
margin: 0;
padding: 0;
}
body {
margin: 100px;
}
/* ---------------------------------------------- /*
* Animated arrow icon
/* ---------------------------------------------- */
.arrow-icon {
position: relative;
width:26px;
height:4px;
background:#000;
cursor: pointer;
-webkit-transition: .15s ease-in-out;
-moz-transition: .15s ease-in-out;
-o-transition: .15s ease-in-out;
transition: .15s ease-in-out;
}
.arrow-icon.left:hover, .arrow-icon.right:hover {
width:36px;
}
.arrow-icon:before {
position:absolute;
content:"";
}
.arrow-icon.left:before, .arrow-icon.right:before {
width: 52px;
height: 26px;
}
.arrow-icon:before {
position:absolute;
content:"";
width: 52px;
height: 26px;
}
.arrow-icon.left:before {
top: -12px;
left: -12px;
}
.arrow-icon:after {
position:absolute;
content:"";
transform:rotate(45deg);
top:-8px;
width:16px;
height:16px;
background:transparent;
border-color: #000;
-webkit-transition: .1s ease-in-out;
-moz-transition: .1s ease-in-out;
-o-transition: .1s ease-in-out;
transition: .1s ease-in-out;
}
.arrow-icon.left:after{
border-left:4px solid;
border-bottom:4px solid;
}
.arrow-icon.left:hover {
-webkit-transform:translateX(-12px);
transform:translateX(-12px);
-ms-transform-origin:50% 0%;
transform-origin:50% 0%;
}
<div class="arrow-icon left"></div>

Hover effect when hover image

I want to make a hover effect, when hover the image like this:
On the Internet found many similar examples but they all either with jquery or js. I would like to know whether it is possible to do purely with css...
UPDATE: here's a code found, but it is too big :(
.view-content {
height: 330px;
}
h2.view-title {
font-size: 3rem;
font-weight: bold;
color: #7d7a7a;
text-align: center;
text-shadow: 0 0px 0px;
}
.view {
width: 300px;
height: 200px;
margin: 10px;
float: left;
border: 5px solid #fff;
overflow: hidden;
position: relative;
text-align: center;
box-shadow: 0px 0px 5px #aaa;
cursor: default;
}
.view .view-mask, .view {
width: 300px;
height: 200px;
position: absolute;
overflow: hidden;
top: 0;
left: 0;
}
.view img {
display: block;
position: relative;
}
.view a.view-info {
display: inline-block;
text-decoration: none;
padding:0;
text-align: center;
color: white;
font-size: 1.9rem;
font-weight: 600;
vertical-align: middle;
}
.view-effect .view-mask {
opacity: 0;
overflow:visible;
border:100px solid rgba(0,0,0,0.7);
box-sizing:border-box;
transition: all 0.3s ease-in-out;
}
.view-effect a.view-info {
position:relative;
top:-20px;
opacity: 0;
transition: opacity 0.3s 0s ease-in-out;
}
.view-effect:hover .view-mask {
opacity: 1;
border:100px solid rgba(0,0,0,0.7);
}
.view-effect:hover a.view-info {
opacity:1;
transition-delay: 0.3s;
}
<div class="view view-effect">
<img src="http://storage7.static.itmages.ru/i/16/0708/h_1467979220_8325708_d41d8cd98f.png" height="200" width="300" alt=""> <p></p>
<div class="view-mask">
Show project
</div>
</div>
Checkout below code as what you want or just click on below link :-
https://jsfiddle.net/ananddeepsingh/99bop25r/
HTML
<div class="box"> <img src="http://placehold.it/400x300">
<div class="overbox">
<div class="title overtext"> CSS Script </div>
<div class="tagline overtext"> Animated Text Overlay On Hover </div>
</div>
</div>
CSS
.box {
cursor: pointer;
height: 300px;
position: relative;
overflow: hidden;
width: 400px;
}
.box img {
position: absolute;
left: 0;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
}
.box .overbox {
background-color: #304562;
position: absolute;
top: 0;
left: 0;
color: #fff;
z-index: 100;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
opacity: 0;
width: 360px;
height: 240px;
padding: 130px 20px;
}
.box:hover .overbox {
opacity: 1;
}
.box .overtext {
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
transform: translateY(40px);
-webkit-transform: translateY(40px);
}
.box .title {
font-size: 2.5em;
text-transform: uppercase;
opacity: 0;
transition-delay: 0.1s;
transition-duration: 0.2s;
}
.box:hover .title,
.box:focus .title {
opacity: 1;
transform: translateY(0px);
-webkit-transform: translateY(0px);
}
.box .tagline {
font-size: 0.8em;
opacity: 0;
transition-delay: 0.2s;
transition-duration: 0.2s;
}
.box:hover .tagline,
.box:focus .tagline {
opacity: 1;
transform: translateX(0px);
-webkit-transform: translateX(0px);
}
Yes you can do that using pure CSS. for that purpose you may use :after pseudo class as,
.img-wrapper {
position:relative;
display:inline-block;
overflow:hidden;
cursor:pointer
}
.img-wrapper .hover-div{
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
opacity:0;
display:inline-block;
text-align:center;
background:rgba(0,0,0,0.3);
-webkit-transition: 0.5s ease-in-out;
-moz-transition: 0.5s ease-in-out;
-o-transition: 0.5s ease-in-out;
transition: 0.5s ease-in-out;
-webkit-transform: translateY(100%);
-moz-transform: translateY(100%);
-o-transform: translateY(100%);
-ms-transform: translateY(100%);
transform: translateY(100%);
}
.img-wrapper:hover .hover-div{
top:0;
opacity:1;
-webkit-transform: translateY(0);
-moz-transform: translateY(0);
-o-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0);
}
.img-wrapper:hover img {
-webkit-filter:grayscale(1);
-moz-filter:grayscale(1);
filter:grayscale(1);
}
.mybutton{
background:#FFFFFF;
color:#111111;
padding:10px 20px;
border-radius:5px;
display:inline-block;
margin-top:100px;
-webkit-transition: 0.3s ease-in-out;
transition: 0.3s ease-in-out;
}
.mybutton:hover{
background:#111111;
color:#FFFFFF;
}
<div class="img-wrapper">
<img src="https://unsplash.it/200" >
<div class="hover-div">
<a class="mybutton">My Button</a>
</div>
</div>
Just use ':hover' after the element you want to show the effect on. For example, if you wanted to use it on the header you would create a new css tag called
header:hover{} and then you could put an opactiy of maybe 0.5 to make the object fade on hover. Hope this helps!
Yes it is possible only through HTML and CSS. Below there is an example code:
HTML:
<div class="imagebox">
<div class="transparent"><i class="fa fa-search" aria-hidden="true"></i>
<p>Zoom</p></div>
<img src="images/yourimage.jpg">
</div>
CSS:
.imagebox{
position: relative;
}
.imagebox:hover .transparent{
display: block;
}
.transparent{
background: rgba(0,0,0,0.5);
position: absolute;
height: 100%;
width: 100%;
display: none;
cursor: pointer;
}
.transparent i{
position: absolute;
left: 50%;
top: 30%;
color: #fff;
font-size: 20px;
}
.transparent p{
position: absolute;
left: 45%;
top: 50%;
color: #fff;
font-size: 20px;
}

Tidying up css code

I have a .css file for my website which does all the formatting for the side navigation bar. The only problem is that it looks messy and it seems to be inefficient as I kept on having to copy the same code again and again only to change one or two value per slide pop out. I am wanting to know how I could make it neater and more efficient.
This is what the relevant css code looks like
nav {
display: block;
color:white;
border:2px;
border-color:aqua;
border-style:solid;
border-right-style:none;
padding:10px;
text-transform: uppercase;
}
/*First nav box*/
#topnav {
top: 100px;
right: 0px;
position: fixed;
z-index: 3000;
background-color:white;
border-bottom-style:none;
width:20px;
height:20px;
line-height: 20px;
text-align:center;
vertical-align:
-webkit-transition: 250ms all ease-out;
transition: 250ms all ease-out;
color:black;
}
#topnav:hover span {display:none}
#topnav:hover {
width:3cm;
background-color:black;
border-bottom-style:solid;
color:white;
}
#topnav:hover:before {
content:"Top";
}
/*Second nav box*/
#nav2 {
top: 140px;
right: 0px;
position: fixed;
z-index: 3000;
background-color:red;
border-bottom-style:none;
border-top-style:none;
width:20px;
height:20px;
line-height: 20px;
text-align:center;
vertical-align:
-webkit-transition: 250ms all ease-out;
transition: 250ms all ease-out;
color:black;
}
#nav2:hover span {display:none}
#nav2:hover {
width:3cm;
background-color:black;
border-bottom-style:solid;
border-top-style:solid;
color:white;
}
#nav2:hover:before {
content:"Red";
}
/*Third nav box*/
#nav3 {
top: 180px;
right: 0px;
position: fixed;
z-index: 3000;
background-color:blue;
border-bottom-style:none;
border-top-style:none;
width:20px;
height:20px;
line-height: 20px;
text-align:center;
vertical-align:
-webkit-transition: 250ms all ease-out;
transition: 250ms all ease-out;
color:black;
}
#nav3:hover span {display:none}
#nav3:hover {
width:3cm;
background-color:black;
border-bottom-style:solid;
border-top-style:solid;
color:white;
}
#nav3:hover:before {
content:"blue";
}
/*Fourth nav box*/
#nav4 {
top: 220px;
right: 0px;
position: fixed;
z-index: 3000;
background-color:green;
border-bottom-style:none;
border-top-style:none;
width:20px;
height:20px;
line-height: 20px;
text-align:center;
vertical-align:
-webkit-transition: 250ms all ease-out;
transition: 250ms all ease-out;
color:black;
}
#nav4:hover span {display:none}
#nav4:hover {
width:3cm;
background-color:black;
border-bottom-style:solid;
border-top-style:solid;
color:white;
}
#nav4:hover:before {
content:"green";
}
/*Fifth nav box*/
#nav5 {
top: 260px;
right: 0px;
position: fixed;
z-index: 3000;
background-color:purple;
border-bottom-style:none;
border-top-style:none;
width:20px;
height:20px;
line-height: 20px;
text-align:center;
vertical-align:
-webkit-transition: 250ms all ease-out;
transition: 250ms all ease-out;
color:black;
}
#nav5:hover span {display:none}
#nav5:hover {
width:3cm;
background-color:black;
border-bottom-style:solid;
border-top-style:solid;
color:white;
}
#nav5:hover:before {
content:"purple";
}
/*Sixth nav box*/
#nav6 {
top: 300px;
right: 0px;
position: fixed;
z-index: 3000;
background-color:orange;
border-bottom-style:none;
border-top-style:none;
width:20px;
height:20px;
line-height: 20px;
text-align:center;
vertical-align:
-webkit-transition: 250ms all ease-out;
transition: 250ms all ease-out;
color:black;
}
#nav6:hover span {display:none}
#nav6:hover {
width:3cm;
background-color:black;
border-bottom-style:solid;
border-top-style:solid;
color:white;
}
#nav6:hover:before {
content:"orange";
}
/*Bot nav box*/
#botnav {
top: 340px;
right: 0px;
position: fixed;
z-index: 3000;
background-color:white;
border-top-style:none;
width:20px;
height:20px;
line-height: 20px;
text-align:center;
vertical-align:
-webkit-transition: 250ms all ease-out;
transition: 250ms all ease-out;
color:black;
}
#botnav:hover span {display:none}
#botnav:hover {
width:3cm;
background-color:black;
border-top-style:solid;
color:white;
}
#botnav:hover:before {
content:"200";
}
Also here is a JSFiddle with the code in practice to show you what it looks like. Also if I need to change the HTML to make the css more efficient let me know.
Thanks for any help
Edit
So based off Darren's answer and Stafox's answer, I have condensed the code to this.
nav {
display: block;
color:white;
border:2px;
border-color:aqua;
border-left-style:solid;
padding:10px;
text-transform: uppercase;
right: 0px;
position: fixed;
z-index: 3000;
width:20px;
height:20px;
line-height: 20px;
text-align:center;
-webkit-transition: 250ms all ease-out;
transition: 250ms all ease-out;
color:black;
}
#topnav:hover, #nav2:hover, #nav3:hover,
#nav4:hover, #nav5:hover, #nav6:hover,
#botnav:hover {
z-index:5000;
width:3cm;
background-color:black;
border-style:solid;
border-right-style:none;
color:white;
}
nav:hover span
{
display:none
}
/*First nav box*/
#topnav {
top: 100px;
background-color:white;
border-top-style:solid;
}
#topnav:hover:before {
content:"Top";
}
/*Second nav box*/
#nav2 {
top: 140px;
background-color:red;
}
#nav2:hover:before {
content:"Red";
}
/*Third nav box*/
#nav3 {
top: 180px;
background-color:blue;
}
#nav3:hover:before {
content:"blue";
}
/*Fourth nav box*/
#nav4 {
top: 220px;
background-color:green;
}
#nav4:hover:before {
content:"green";
}
/*Fifth nav box*/
#nav5 {
top: 260px;
background-color:purple;
}
#nav5:hover:before {
content:"purple";
}
/*Sixth nav box*/
#nav6 {
top: 300px;
background-color:orange;
}
#nav6:hover:before {
content:"orange";
}
/*Bot nav box*/
#botnav {
top: 340px;
background-color:white;
border-bottom-style:solid;
}
#botnav:hover:before {
content:"200";
}
Here is a JSFiddle of it in use.
Are there any other suggestions?
You could group the common navigational elements within a CSS class.
For instance, your topnav, nav2, nav3, nav4 and nav5 all have the following in common:
Colour
Position
Transition
Right
Border
Line height
So it may make more sense to have a base element with these styles rather than repeating them.
.navigation-base {
color: black;
position: fixed;
transition: 250ms all ease-out;
right: 0px;
}
And then apply the navigation-base to all navigational elements and then add an additional class where they differ.
.navigation-unsuccessful {
background-color: red;
}
.navigation-success {
background-color: green;
}
<nav class="navigation-base navigation-success">
<!-- Navigational components -->
</nav>
The idea is to move general properties to common .selector.
And override unique properties if needed.
Something like this: https://jsfiddle.net/Stafox/qrv2h9k5/1/

Display list in horizontal line - li in html with css

How to modify this code to display list in horizontal line menu
Currently this code displays in vertical
I want it in horizonyal line form
how make it display list in horizontal line form?
<html><head><style>
.metromenu {
display:block;;
position:relative;
width:40%;
margin:0 auto;
z-index:1;
}
.metromenu, .sub-metromenu {
list-style:none;
}
.metromenu li {
display:inline-block;
float:left;
margin-right:2px;
margin-top:2px;
}
.metromenu a{
display:block;
position:relative;
width:120px;
height:32px;
text-decoration:none;
font-family:'arial';
text-align:center;
letter-spacing:2px;
line-height:26px;
color:#fff;
padding:6px 20px 0 20px;
background-color: hsl(200,70%,50%);
-webkit-transition:all 0.2s ease-out;
-moz-transition:all 0.2s ease-out;
-o-transition:all 0.2s ease-out;
}
.metromenu a:hover {
background-color: hsl(200,80%,65%);
}
.metromenu span {
display:inline-block;;
position:absolute;
top:18px;
right:10px;
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 6px solid #fff;
}
.metromenu li:hover > a{ /* activates link when mouse over sub-metromenu */
background-color: hsl(200,80%,65%);
}
/*sub-metromenu trigger*/
.metromenu li a:hover ~ ul{
opacity:1;
visibility:visible;
}
.sub-metromenu {
opacity:0;
visibility:hidden;
position:absolute;
z-index:10;
-webkit-transition:all 0.2s ease-out;
-moz-transition:all 0.2s ease-out;
-o-transition:all 0.2s ease-out;
}
.sub-metromenu:hover {
opacity:1;
visibility:visible;
}
.sub-metromenu li a{
background-color: hsl(250,70%,60%);
}
.sub-metromenu li:first-child a{
height:72px;
}
.sub-metromenu li a:hover{
background-color: hsl(250,80%,70%);
}
.metromenu .orange {
background-color: hsl(20,70%,60%);
}
.metromenu .orange:hover {
background-color: hsl(20,80%,70%);
}
.metromenu .green {
background-color: hsl(110,60%,60%);
}
.metromenu .green:hover {
background-color: hsl(110,70%,70%);
}
</style>
</head>
<body>
<div>
<ul class="metromenu">
<li>Web Tools</li>
<li>Smartphones<span></span>
<ul class="sub-metromenu">
<li>Latest Smartphones</li>
<li>Windows</li>
<li>Android</li>
</ul>
</li>
<li>Others</li>
</ul>
</div> </body> </html>
I took code from here http://codepen.io/maxim/pen/DrvLx
Try this
.metromenu {
display: block;
margin: 0 auto;
position: relative;
width: 100%;
z-index: 1;
}
I changed the width from 40% to 100%. Here is the fiddle. Let me know if this was helpful or if you have any queries.
Edit I [sub menu fix]: Also set the width for sub-menu or they will go vertical.
.sub-metromenu {
opacity:0;
visibility:hidden;
position:absolute;
z-index:10;
-webkit-transition:all 0.2s ease-out;
-moz-transition:all 0.2s ease-out;
-o-transition:all 0.2s ease-out;
width: 10%;
}
Updated fiddle