I was trying to make an interactive hamburger icon and found a tutorial and the code for it on code pen. The problem is the code I found on code pen does not work on my machine, but it is generating results on code pen. Also, in the CSS, I could see some properties placed within other properties which I did not understand. Please see the code below.
HTML:
<div class="nav-icon cross">
<div class="span"></div>
</div>
CSS:
.nav-icon{
height:70px;
width:88px;
position:relative;
.span {
height:6px;
width:55px;
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
margin:auto;
background:black;
transition:all 0.3s;
&::before,&::after {
height:6px;
width:100%;
background:black;
position:absolute;
content:"";
transition:all 0.3s;
}
&::after {
top:20px;
}
&::before {
top:-20px;
}
}
&.active .span::after {
top:0;
transform:rotate(45deg);
}
&.active .span::before {
top:0;
transform:rotate(-45deg);
}
&.active .span{
background:none;
}
}
Which you posted it's a SCSS and you have to compile it into CSS
You can read about the scss just following link
sass link
.nav-icon {
height: 70px;
width: 88px;
position: relative;
}
.nav-icon .span {
height: 6px;
width: 55px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
background: black;
transition: all 0.3s;
}
.nav-icon .span::before,
.nav-icon .span::after {
height: 6px;
width: 100%;
background: black;
position: absolute;
content: "";
transition: all 0.3s;
}
.nav-icon .span::after {
top: 20px;
}
.nav-icon .span::before {
top: -20px;
}
.nav-icon.active .span::after {
top: 0;
transform: rotate(45deg);
}
.nav-icon.active .span::before {
top: 0;
transform: rotate(-45deg);
}
.nav-icon.active .span {
background: none;
}
/*# sourceMappingURL=style.css.map */
<div class="nav-icon cross">
<div class="span"></div>
</div>
The ampersand (&) symbol in SASS represents a placeholder for the wrapper of the element you're selecting.
For example, if you have:
.paragraph {
color: blue;
&.active {
color: red;
}
}
is the same as writing
.paragraph {
color: blue;
}
.paragraph.active {
color: red;
}
Related
I'm unsure how to tackle what i'm doing.
I'm basically trying to achieve the above. I have a section tag and a list of li tags with a hr tag for the line. They overlap poorly though and don't sit/look as smoothly as i'd like.
Html:
<section class="navigation">
<li class="page_nav--one">One</li>
<hr class="page_nav--line_break" />
<li class="page_nav--two">Two</li>
<li class="page_nav--three">Three</li>
</section>
and my css looks like :
.navigation {
background: #fff;
text-align: center;
margin: 50px 0;
display: block;
.page_nav--line_break {
position: absolute;
display: block;
height: 1px;
top: -14px;
border: 0;
border-top: 1px solid #ccc;
/* margin: 1em 0; */
padding: 0;
width: 400px;
right: 202px;
z-index: 999999;
}
li {
display: inline-block;
list-style: none;
position: relative;
margin: 10px 85px;
}
li:before {
content: '';
height: 16px;
width: 16px;
background-size: 16px 16px;
position: absolute;
top: -23px;
left: 16px;
margin: auto;
cursor: pointer;
pointer-events: none;
}
li:nth-child(1):before {
background: url("trianle_image.png");
}
li:nth-child(2):before {
left: 23px;
background: url("trianle_image.png");
}
li:nth-child(3):before {
left: 35px;
background: url("trianle_image.png");
}
}
Is there a better method/way of achieving what i'm after or am I going about it the correct way?
I would probably use :after pseudo elements.
<div class="diamond"></div>
<div class="diamond"></div>
<div class="diamond"></div>
then the CSS with pseudo elements looks like this:
.diamond {
width:10px;
height:10px;
position:relative:
float:left;
margin-right:100px;
}
.diamond:last-of-type {
margin-right:0;
}
.diamond:after {
content:""
display:block;
width:100px;
height:1px;
background-color:gray;
position:absolute;
top:5px;
left:5px;
}
.diamond:last-of-type:after {
display:none;
}
So the theory is that the after element is your line (like you have) and it is as wide as the margin between the two elements, placed exactly where you need it. Then the last one is hidden.
FIDDLE
I'm working in a module box which redirects the user to an external website.
I've managed to create the layout and the content is displayed properly, however when I added the hover effect, the div is no longer clickable and so does not redirect to the external website.
Here is my jsfiddle
And here is my code:
<div class="module-box">
<div class="module-dummy"></div>
<div class="module-body module-pinterest">
<a href="www.google.com">
<div class="module-pinterest-title">Some text</div>
<div class="module-pinterest-description">
Some other text</div>
</a>
</div>
and my CSS:
.module-box {
display: inline-block;
position: relative;
width: 100%;}
.module-dummy {
margin-top: 100%;}
.module-body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;}
.module-pinterest {
background-color: #7C56BE;}
.module-pinterest-title {
padding: 25px 25px 0px 25px;
color: #FFF;}
.module-pinterest-description {
padding: 25px 25px 0px 25px;
font-size: 22px;
line-height: 26px;
font-weight: bold;
color: #FFF;}
.module-pinterest:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.2);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;}
.module-pinterest:hover:after {
opacity:1;}
Thanks!!
Add pointer-events:none; to your .module-pinterest:hover:after css code, like so:
.module-pinterest:hover:after {
opacity: 1;
pointer-events:none;
}
Here is the JSFiddle demo
if you move all your .module-pinterest styles to the anchor, then it should work:
.module-pinterest a {
display:block;
width:100%;
height:100%;
background-color: #7C56BE;
}
.module-pinterest a:after {
content:'\A';
position:absolute;
width:100%; height:100%;
top:0; left:0;
background:rgba(0,0,0,0.2);
opacity:0;
transition: all 0.5s;
-webkit-transition: all 0.5s;
}
.module-pinterest a:hover:after {
opacity:1;
}
Updated fiddle
Since you are using positioning for overlaying of color upon hover, convert your anchor to block and add position:relative and a z-index value:
.module-body a {
position: relative;
z-index: 9;
display:block;
}
Here is fiddle:
https://jsfiddle.net/kw5ybq9e/3/
I am trying to change a text in a button HERE. The transition in the color works fine, but the transition on the span positions do not work.
Here is my code:
<style>
#btnIniciarFacturacion{
width: 200px;
height: 30px;
}
#btnIniciarFacturacion {
position: relative;
-webkit-transition: 2s;
transition: 2s;
overflow: hidden;
}
.btnIniciarFacturacion-content {
position: absolute;
left:0;
top:0;
font-size: 20px;
font-weight: bolder;
}
#btnIniciarFacturacion:hover{
background-color: orange;
}
#btnIniciarFacturacion .btnIniciarFacturacion-top{
top:0;
}
#btnIniciarFacturacion:hover .btnIniciarFacturacion-top{
top:-50px;
}
#btnIniciarFacturacion .btnIniciarFacturacion-bottom {
top:50px;
}
#btnIniciarFacturacion:hover .btnIniciarFacturacion-bottom {
top:0px;
}
</style>
<button class="" id="btnIniciarFacturacion">
<span class="btnIniciarFacturacion-top btnIniciarFacturacion-content" id="spanTotalFacturado"> TOTAL !##</span>
<span class="btnIniciarFacturacion-bottom btnIniciarFacturacion-content">Iniciar FacturaciĆ³n</span>
</button>
You're missing the transition style on the span elements:
.btnIniciarFacturacion-content {
position: absolute;
left:0;
top:0;
font-size: 20px;
font-weight: bolder;
transition: 2s;
}
Wondering if this is the best method to add an image to the beginning and end of my navigation. As it stands my navigation looks like this:
But realistically I would like to add this corner piece to the edges of it:
Here is my CSS of me trying to implement it:
#menu-top {
position:relative;
margin:0 -10px 0;
padding:.25em 0 0;
border-width:0;
color:#fff;
text-align:left;
background: url( http://www.leaguememe.co.uk/wp-content/uploads/2014/01/Horizontalbannermiddletop.png );
min-height:50px;
}
#menu-top:before {
content:'';
z-index: 20;
background: url( http://www.leaguememe.co.uk/wp-content/uploads/2014/01/Horizontaltop_left.png );
position:absolute;
left:0;
/* bottom:-5px; */
bottom: 0px;
width:0;
height:0;
display:block;
border-color:transparent #222 transparent transparent;
border-style:solid;
border-width:0px 10px 5px 0;
}
#menu-top:after {
content:'';
position:absolute;
right:0;
bottom:-5px;
width:0;
height:0;
display:block;
border-color:transparent transparent transparent #222;
border-style:solid;
border-width:0 0 5px 10px;
}
#menu-top ul {
position:relative;
margin:0;
padding:.5em 30px;
list-style-type:none;
text-align:center;
}
#menu-top ul:before {
content:'';
position:absolute;
top:4px;
left:-5px;
width: 34px;
height: auto;
display:block;
background: url( http://www.leaguememe.co.uk/wp-content/uploads/2014/01/Horizontaltop_left.png );
}
#menu-top ul:after {
content:'';
position:absolute;
top:4px;
right:-5px;
width:27px;
height:39px;
display:block;
}
#menu-top li {
display:inline;
margin:0 .25em 1em;
padding:0;
line-height:2.5em;
}
#menu-top li a {
background-color: #111;
color: #e9d6d6;
cursor: pointer;
display: inline-block;
font-weight: bold;
text-align: center;
line-height: 1;
outline: 0;
padding: .45em .6em;
white-space: nowrap;
-webkit-transition: background-color, -webkit-box-shadow 0.2s linear;
}
#menu-top li a:hover,
#menu-top li a:active {
text-decoration:none;
}
Am I getting the use of :Before and :After wrong?
You could do this a number of ways, including the use of pseudoelements. In the following, I placed two elements at the top left, and top right of my nav element. I then assigned the new background image, and flipped the element to the right so it mirrors that on the left:
nav {
position: relative;
width: 703px; height: 45px;
background: url("http://i.stack.imgur.com/PMV59.png");
}
nav::before, nav::after {
content: "";
display: block;
width: 95px; height: 50px;
position: absolute; top: -8px; left: -5px;
background: url("http://i.stack.imgur.com/IqsBV.png");
}
nav::after {
left: auto; right: -5px;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
}
Which results in the following:
I should note that the transform property was only used because you provided the left corner image only. This property is not going to be supported in Internet Explorer 8 (which does support :before and :after). If you'd like the above to support IE8, you'll need to abandon the transform, and instead provide a different background for the :after pseudoelement.
Demo: http://jsfiddle.net/NXP3g/1/
Below is the html in question
By default it appears as:
Which is completely wrong, it should be on two lines and it should also look "pretty" but it looks pretty ugly at the moment.
The aim of the box is so that it looks like a "Loading" box which after time (already incorporated into my main bit of code) for it to disappear once loaded, so the only problem with this at the moment is that it looks ugly and doesn't layout correctly :(
The reason I have two div blocks inside the main div is because they're going to be different size and color text (I think)
If anyone has a completely different looking loading message/bar/popup that they think I would like to use please feel free to post.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.loading1 a {
position: fixed;
cursor: pointer;
left: 50%;
top: 10%;
color: white;
padding-left: 5px;
}
.loading2 a {
position: fixed;
cursor: pointer;
left: 50%;
top: 10%;
color: white;
padding-left: 5px;
}
.loading {
z-index: 999;
position: fixed;
left: 50%;
top: 10%;
width: 150px;
height: 80px;
border: 1px solid white;
-moz-border-radius: 10px;
border-radius: 10px;
background: #D8B93F;
}
#circularG{
position:relative;
width:25px;
height:25px}
.circularG{
position:absolute;
background-color:#0E4216;
width:6px;
height:6px;
-moz-border-radius:4px;
-moz-animation-name:bounce_circularG;
-moz-animation-duration:1.12s;
-moz-animation-iteration-count:infinite;
-moz-animation-direction:linear;
-webkit-border-radius:4px;
-webkit-animation-name:bounce_circularG;
-webkit-animation-duration:1.12s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:linear;
-o-border-radius:4px;
-o-animation-name:bounce_circularG;
-o-animation-duration:1.12s;
-o-animation-iteration-count:infinite;
-o-animation-direction:linear;
-ms-border-radius:4px;
-ms-animation-name:bounce_circularG;
-ms-animation-duration:1.12s;
-ms-animation-iteration-count:infinite;
-ms-animation-direction:linear;
}
#circularG_1{
left:0;
top:10px;
-moz-animation-delay:0.42s;
-webkit-animation-delay:0.42s;
-o-animation-delay:0.42s;
-ms-animation-delay:0.42s;
}
#circularG_2{
left:3px;
top:3px;
-moz-animation-delay:0.56s;
-webkit-animation-delay:0.56s;
-o-animation-delay:0.56s;
-ms-animation-delay:0.56s;
}
#circularG_3{
top:0;
left:10px;
-moz-animation-delay:0.7s;
-webkit-animation-delay:0.7s;
-o-animation-delay:0.7s;
-ms-animation-delay:0.7s;
}
#circularG_4{
right:3px;
top:3px;
-moz-animation-delay:0.84s;
-webkit-animation-delay:0.84s;
-o-animation-delay:0.84s;
-ms-animation-delay:0.84s;
}
#circularG_5{
right:0;
top:10px;
-moz-animation-delay:0.98s;
-webkit-animation-delay:0.98s;
-o-animation-delay:0.98s;
-ms-animation-delay:0.98s;
}
#circularG_6{
right:3px;
bottom:3px;
-moz-animation-delay:1.12s;
-webkit-animation-delay:1.12s;
-o-animation-delay:1.12s;
-ms-animation-delay:1.12s;
}
#circularG_7{
left:10px;
bottom:0;
-moz-animation-delay:1.26s;
-webkit-animation-delay:1.26s;
-o-animation-delay:1.26s;
-ms-animation-delay:1.26s;
}
#circularG_8{
left:3px;
bottom:3px;
-moz-animation-delay:1.4s;
-webkit-animation-delay:1.4s;
-o-animation-delay:1.4s;
-ms-animation-delay:1.4s;
}
#-moz-keyframes bounce_circularG{
0%{
-moz-transform:scale(1)}
100%{
-moz-transform:scale(.3)}
}
#-webkit-keyframes bounce_circularG{
0%{
-webkit-transform:scale(1)}
100%{
-webkit-transform:scale(.3)}
}
#-o-keyframes bounce_circularG{
0%{
-o-transform:scale(1)}
100%{
-o-transform:scale(.3)}
}
#-ms-keyframes bounce_circularG{
0%{
-ms-transform:scale(1)}
100%{
-ms-transform:scale(.3)}
}
</style>
</head>
<body>
<div class="loading"><div id="circularG">
<div id="circularG_1" class="circularG">
</div>
<div id="circularG_2" class="circularG">
</div>
<div id="circularG_3" class="circularG">
</div>
<div id="circularG_4" class="circularG">
</div>
<div id="circularG_5" class="circularG">
</div>
<div id="circularG_6" class="circularG">
</div>
<div id="circularG_7" class="circularG">
</div>
<div id="circularG_8" class="circularG">
</div>
</div>
<div class="loading1"><a>Loading, Please Wait...</a></div><div class="loading2"><br><a>(click to abort)</a></div></div>
</body>
</html>
Thanks
You don't need the position:fixed, top and left on anything inside the loading box. I have also made some changes to the positioning and spacing. Hope you like it!
http://jsfiddle.net/myajouri/9eZNQ/
HTML
<div class="loading">
<div id="circularG">
<div id="circularG_1" class="circularG"></div>
<div id="circularG_2" class="circularG"></div>
<div id="circularG_3" class="circularG"></div>
<div id="circularG_4" class="circularG"></div>
<div id="circularG_5" class="circularG"></div>
<div id="circularG_6" class="circularG"></div>
<div id="circularG_7" class="circularG"></div>
<div id="circularG_8" class="circularG"></div>
</div>
<div class="loadingText">
Loading, Please Wait...
(click to abort)
</div>
</div>
CSS
.loadingText {
color: white;
font-family: sans-serif;
font-size: 16px;
}
.loadingText a {
line-height: 32px;
color: inherit;
font-size: 14px;
text-decoration: none;
}
.loading {
z-index: 999;
position: fixed;
left: 50%;
top: 50%;
width: 170px;
height: 90px;
margin-left: -95px;
margin-top: -55px;
padding: 10px;
border: 1px solid white;
-moz-border-radius: 10px;
border-radius: 10px;
background: rgba(0, 0, 0, 0.75);
text-align: center;
}
#circularG {
position:relative;
width:25px;
height:25px;
margin: 5px auto 15px auto;
}
.circularG {
position:absolute;
background-color: white;
width:6px;
height:6px;
-moz-border-radius:4px;
-moz-animation-name:bounce_circularG;
-moz-animation-duration:1.12s;
-moz-animation-iteration-count:infinite;
-moz-animation-direction:linear;
-webkit-border-radius:4px;
-webkit-animation-name:bounce_circularG;
-webkit-animation-duration:1.12s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:linear;
-o-border-radius:4px;
-o-animation-name:bounce_circularG;
-o-animation-duration:1.12s;
-o-animation-iteration-count:infinite;
-o-animation-direction:linear;
-ms-border-radius:4px;
-ms-animation-name:bounce_circularG;
-ms-animation-duration:1.12s;
-ms-animation-iteration-count:infinite;
-ms-animation-direction:linear;
}
#circularG_1 {
left:0;
top:10px;
-moz-animation-delay:0.42s;
-webkit-animation-delay:0.42s;
-o-animation-delay:0.42s;
-ms-animation-delay:0.42s;
}
#circularG_2 {
left:3px;
top:3px;
-moz-animation-delay:0.56s;
-webkit-animation-delay:0.56s;
-o-animation-delay:0.56s;
-ms-animation-delay:0.56s;
}
#circularG_3 {
top:0;
left:10px;
-moz-animation-delay:0.7s;
-webkit-animation-delay:0.7s;
-o-animation-delay:0.7s;
-ms-animation-delay:0.7s;
}
#circularG_4 {
right:3px;
top:3px;
-moz-animation-delay:0.84s;
-webkit-animation-delay:0.84s;
-o-animation-delay:0.84s;
-ms-animation-delay:0.84s;
}
#circularG_5 {
right:0;
top:10px;
-moz-animation-delay:0.98s;
-webkit-animation-delay:0.98s;
-o-animation-delay:0.98s;
-ms-animation-delay:0.98s;
}
#circularG_6 {
right:3px;
bottom:3px;
-moz-animation-delay:1.12s;
-webkit-animation-delay:1.12s;
-o-animation-delay:1.12s;
-ms-animation-delay:1.12s;
}
#circularG_7 {
left:10px;
bottom:0;
-moz-animation-delay:1.26s;
-webkit-animation-delay:1.26s;
-o-animation-delay:1.26s;
-ms-animation-delay:1.26s;
}
#circularG_8 {
left:3px;
bottom:3px;
-moz-animation-delay:1.4s;
-webkit-animation-delay:1.4s;
-o-animation-delay:1.4s;
-ms-animation-delay:1.4s;
}
#-moz-keyframes bounce_circularG {
0% {
-moz-transform:scale(1)
}
100% {
-moz-transform:scale(.3)
}
}
#-webkit-keyframes bounce_circularG {
0% {
-webkit-transform:scale(1)
}
100% {
-webkit-transform:scale(.3)
}
}
#-o-keyframes bounce_circularG {
0% {
-o-transform:scale(1)
}
100% {
-o-transform:scale(.3)
}
}
#-ms-keyframes bounce_circularG {
0% {
-ms-transform:scale(1)
}
100% {
-ms-transform:scale(.3)
}
}
.loading1 a {
position: fixed;
cursor: pointer;
left: 50%;
top: 10%;
color: white;
padding-left: 5px;
}
.loading2 a {
position: fixed;
cursor: pointer;
left: 50%;
top: 10%;
color: white;
padding-left: 5px;
}
.loading {
z-index: 999;
position: fixed;
left: 50%;
top: 10%;
width: 150px;
height: 80px;
border: 1px solid white;
-moz-border-radius: 10px;
border-radius: 10px;
background: #D8B93F;
}
You need to take a look at your positioning. s you have all 3 of them set to fixed and left = 50% and top = 10%.
Due to this they will all sit in the same place on the page.
Have a look at W3School it explains it all in there and you can have a mess about with that :)
You have them set to fixed to left: 50%; top: 10%;
Try changing
.loading1 a {
position: fixed;
cursor: pointer;
left: 50%;
top: 10%;
color: white;
padding-left: 5px;
}
.loading2 a {
position: fixed;
cursor: pointer;
left: 50%;
top: 10%;
color: white;
padding-left: 5px;
}
To:
.loading1 a {
position: relative;
cursor: pointer;
left: 5%;
color: white;
padding-left: 5px;
}
.loading2 a {
position: relative;
cursor: pointer;
left: 5%;
color: white;
padding-left: 5px;
}
Updated fiddle here. In this fiddle I removed your <br>. It is two different divs so there is a break already.