I'm using this Pure CSS hamburger menu code: https://codepen.io/Joanc/pen/XYYZdE
body
{
margin: 0;
padding: 0;
/*make it look decent enough*/
background: #232323;
color: #cdcdcd;
font-family: "Avenir Next", "Avenir", sans-serif;
overflow-x: hidden; /*needed because hiding the menu on the right side is not perfect*/
}
a
{
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
a:hover
{
color: tomato;
}
#menuToggle
{
display: block;
position: absolute;
top: 50px;
right: 50px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0; /*hide this*/
z-index: 2; /*and place it over the hamburger*/
-webkit-touch-callout: none;
}
/*Just a quick hamburger*/
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
/*Transform all the slices of hamburger into a crossmark*/
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
/*But let's hide the middle one*/
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
/*Ohyeah and the last one should go the other direction*/
#menuToggle input:checked ~ span:nth-last-child(2)
{
opacity: 1;
transform: rotate(-45deg) translate(0, -1px);
}
/*Make this absolute positioned at the top left of the screen*/
#menu
{
position: absolute;
width: 300px;
margin: -100px 0 0 0;
padding: 50px;
padding-top: 125px;
right: -100px;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/*to stop flickering of text in safari*/
transform-origin: 0% 0%;
transform: translate(100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
/*And let's fade it in from the left*/
#menuToggle input:checked ~ ul
{
transform: scale(1.0, 1.0);
opacity: 1;
}
<!-- Made by Erik Terwan -->
<!-- 24th of November 2015 -->
<!-- MIT License -->
<nav role='navigation'>
<div id="menuToggle">
<!--
A fake / hidden checkbox is used as click reciever,
so you can use the :checked selector on it.
-->
<input type="checkbox" />
<!--
Some spans to act as a hamburger.
They are acting like a real hamburger,
not that McDonalds stuff.
-->
<span></span>
<span></span>
<span></span>
<!--
Too bad the menu has to be inside of the button
but hey, it's pure CSS magic.
-->
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Info</li>
<li>Contact</li>
<li>Show me more</li>
</ul>
</div>
</nav>
After endless tryouts, I find myself completely unable to set the height of the side navbar to 100% and change the width according to the screen size.
What am I missing? What cannot I see? I would extremely appreciate any kind of help.
Thank you in advance and cheers!
This is the solution:
#menu
{
position: absolute;
height: 100vh;
width: 50vw;
margin: -100px 0 0 0;
padding: 50px;
padding-top: 125px;
right: -100px;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/* to stop flickering of text in safari */
transform-origin: 0% 0%;
transform: translate(100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
if you use: vh - vw instead of the % everything should work fine.
this works because it'll only fill up 100% of the height or 50% of the viewport, and not the parent.
Adding height: 100vh to your #menu css tells the container to fill 100% of the viewport height. If you change from the fixed-width of width: 300px to width: 25vw for example, your menu will only ever occupy 25% of the viewport width.
body
{
margin: 0;
padding: 0;
/*make it look decent enough*/
background: #232323;
color: #cdcdcd;
font-family: "Avenir Next", "Avenir", sans-serif;
overflow-x: hidden; /*needed because hiding the menu on the right side is not perfect*/
}
a
{
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
a:hover
{
color: tomato;
}
#menuToggle
{
display: block;
position: absolute;
top: 50px;
right: 50px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0; /*hide this*/
z-index: 2; /*and place it over the hamburger*/
-webkit-touch-callout: none;
}
/*Just a quick hamburger*/
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
/*Transform all the slices of hamburger into a crossmark*/
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
/*But let's hide the middle one*/
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
/*Ohyeah and the last one should go the other direction*/
#menuToggle input:checked ~ span:nth-last-child(2)
{
opacity: 1;
transform: rotate(-45deg) translate(0, -1px);
}
/*Make this absolute positioned at the top left of the screen*/
#menu
{
position: absolute;
width: 25vw;
height: 100vh;
margin: -100px 0 0 0;
padding: 50px;
padding-top: 125px;
right: -100px;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/*to stop flickering of text in safari*/
transform-origin: 0% 0%;
transform: translate(100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
/*And let's fade it in from the left*/
#menuToggle input:checked ~ ul
{
transform: scale(1.0, 1.0);
opacity: 1;
}
<!-- Made by Erik Terwan -->
<!-- 24th of November 2015 -->
<!-- MIT License -->
<nav role='navigation'>
<div id="menuToggle">
<!--
A fake / hidden checkbox is used as click reciever,
so you can use the :checked selector on it.
-->
<input type="checkbox" />
<!--
Some spans to act as a hamburger.
They are acting like a real hamburger,
not that McDonalds stuff.
-->
<span></span>
<span></span>
<span></span>
<!--
Too bad the menu has to be inside of the button
but hey, it's pure CSS magic.
-->
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Info</li>
<li>Contact</li>
<li>Show me more</li>
</ul>
</div>
</nav>
i've made a change to the navigation from scrolling in only one page to linking them to other pages instead. but i cant seem to make the href link work after that. i dont know what could be the problem here
i havent made any changes to the CSS, originally it was meant to be a navigation for one page, but im changing it to navigation to other pages
im pretty sure i need to do something to the css but im not sure what
it is
class="sidebar-navigation hidde-sm hidden-xs">
<div class="logo">
<img src="img/logo.png" alt="logo" style=" margin-top:13px;width:100%;height:100%;">
</div>
<nav>
<ul>
<li>
<a href="index.html">
<span class="rect"></span>
<span class="circle"></span>
Home
</a>
</li>
<li>
<a href="company.html">
<span class="rect"></span>
<span class="circle"></span>
Company
</a>
</li>
.sidebar-navigation nav {
position: relative;
top: 60%;
left: 60%;
-webkit-transform: translateX(-60%) translateY(-60%);
-moz-transform: translateX(-60%) translateY(-60%);
-ms-transform: translateX(-60%) translateY(-60%);
-o-transform: translateX(-60%) translateY(-60%);
transform: translateX(-60%) translateY(-60%);
}
.sidebar-navigation ul {
margin-left: 45px;
list-style: none;
padding: 0;
}
.sidebar-navigation li{
padding: 10px 0;
}
.sidebar-navigation span{
display: inline-block;
position:relative;
}
.sidebar-navigation nav a{
display: inline-block;
color: #fff;
margin-top: 5px;
text-decoration: none!important;
font-size: 15px;
letter-spacing: 0.5px;
text-transform: capitalize;
}
.circle{
margin-right: 5px;
height: 10px;
width: 10px;
left: 0px;
top: -1px;
border-radius: 50%;
background-color: transparent;
border: 2px solid #fff;
transition: all 0.3s;
}
.rect{
height: 1px;
width: 0px;
left: 0;
bottom: 5.5px;
background-color: #fff;
-webkit-transition: -webkit-transform 0.1s, width 0.6s;
-moz-transition: -webkit-transform 0.1s, width 0.6s;
transition: transform 0.1s, width 0.6s;
}
I have a tooltip to show my search when hovering over an icon. That works fine in itself.
My problem is, that this icon is inside an inline-block navigation and cause it acts as the parent of my tooltip it has to have the large width of it which messes up my layout.So if I don't extend the width of my parent with the Icon the Tooltip messes up due to the small width of ~30px of it's parent.
If I extend the width from my parent to 300px (The size of my tooltip), it messes up my layout.
I need a way of relieving the tooltip itself from the inside of the element with the Icon.
HTML Structure:
<div id="search">
<div class="wrapper">
<div class="popper inline">
<i class="fa fa-tags" />
<div class="tooltip">
<form>
<input placeholder="Search Tags" autocomplete="off" />
<button type="submit">
<a class="btn">
<i class="fa fa-search" />
</a>
</button>
</form>
</div>
<div class="inline">
<form>
<input placeholder="Search Tags" autocomplete="off" autofocus="true" />
<button type="submit">
<a class="btn">
<i class="fa fa-search" />
</a>
</button>
</form>
</div>
</div>
</div>
CSS (Scss):
#search {
background: $secondary;
padding: .25rem;
div.popper {
background: transparent;
border: none;
font-size: .8rem;
color: $highlight;
}
.inline form {
button, input, a {
background: transparent;
border: none;
font-size: .8rem;
color: $highlight;
}
input[type="Search"] {
width: 1368px;
outline: none;
font-style: italic;
font-size: .7rem;
padding: 1rem .5rem;
}
button {
margin-left: 1rem;
}
}
}
.popper {
position: relative;
width: 300px;
}
.popper .tooltip {
background: $secondary;
bottom: 100%;
color: $highlight;
display: block;
left: -25px;
margin-bottom: 20px;
opacity: 0;
padding: .8rem;
pointer-events: none;
position: absolute;
width: 300px;
max-width: 90%;
border-radius: 3px;
-webkit-transform: translateY(10px);
-moz-transform: translateY(10px);
-ms-transform: translateY(10px);
-o-transform: translateY(10px);
transform: translateY(10px);
-webkit-transition: all .25s ease-out;
-moz-transition: all .25s ease-out;
-ms-transition: all .25s ease-out;
-o-transition: all .25s ease-out;
transition: all .25s ease-out;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.popper .tooltip:before {
bottom: -20px;
content: " ";
display: block;
height: 25px;
left: 0;
position: absolute;
width: 100%;
}
/* CSS Triangles - see Trevor's post */
.popper .tooltip:after {
border-left: solid transparent 7px;
border-right: solid transparent 7px;
border-top: solid $secondary 7px;
bottom: -7px;
content: " ";
height: 0;
left: 50%;
margin-left: -13px;
position: absolute;
width: 0;
}
.popper:hover .tooltip {
opacity: 1;
pointer-events: auto;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
-ms-transform: translateY(0px);
-o-transform: translateY(0px);
transform: translateY(0px);
}
I am grateful for all Your help! If you need further information, comment please.
I have a weird problem is firefox (not in google or safari) where you get 1px margin on the sides of the image when you move the window. I don't not if this a bug in firefox or I have just missed something, but it as been really annoying me.
Update: the first problem was fixed with a simple update to firefox, but the problem has came back after adding the transition to change the opacity.
#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,600);
html,
body,
ul {
padding: 0;
margin: 0;
}
body {
font-family: "Open Sans";
}
ul:after {
content: "";
display: table;
clear: both;
}
li {
position: relative;
display: block;
float: left;
width: 25%;
background-color: pink;
}
li img {
display: block;
width: 100%;
opacity: 1;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
li .text {
position: absolute;
color: white;
left: 0;
top: 60%;
width: 100%;
-webkit-transform: translateY(-100%);
-moz-transform: translateY(-100%);
-ms-transform: translateY(-100%);
-o-transform: translateY(-100%);
transform: translateY(-100%);
text-align: center;
opacity: 0;
}
li .text h1 {
margin: 0px;
font-weight: 300;
font-size: 20px;
}
li:hover img {
opacity: 0.3;
}
li:hover .text {
opacity: 1;
}
<ul>
<li>
<img src="http://lorempixel.com/200/200/">
<div class="text">
<h1>"Rubber Ducky"</h1>
<small>001</small>
</div>
</li>
<li>
<img src="http://lorempixel.com/200/200/">
<div class="text">
<h1>"Rubber Ducky"</h1>
<small>001</small>
</div>
</li>
<li>
<img src="http://lorempixel.com/200/200/">
<div class="text">
<h1>"Rubber Ducky"</h1>
<small>001</small>
</div>
</li>
<li>
<img src="http://lorempixel.com/200/200/">
<div class="text">
<h1>"Rubber Ducky"</h1>
<small>001</small>
</div>
</li>
</ul>
For navigation, I opted to use CSS shapes rather than images with overlaid text. However, in every browser, the text appears misaligned towards the right.
Preview on jsFiddle
HTML code:
<nav id="globalNav">
<ul>
<li>
<div class="stars"></div>
<a id="navHome">home</a>
</li>
<li>
<div class="stars"></div>
<a id="navWork">work</a>
</li>
<li>
<div class="stars"></div>
<a id="navAbout">about</a>
</li>
</ul>
</nav>
CSS code:
#globalNav {
position: fixed;
z-index: 1;
width: 100%;
height: 100px;
top: 0;
left: 0;
overflow: hidden;
background-color: #1b2326;
color: #2A363B;
}
#globalNav ul {
margin: 1.25em auto;
padding: 0;
position: relative;
-webkit-padding-start: 0;
-moz-padding-start: 0;
text-align: center;
}
#globalNav li {
padding: 0 3.5em;
display: inline-block;
}
#globalNav a {
position: absolute;
top: 1.3em;
padding: 0 0.25em;
-moz-padding-start: 0;
font-size: 1em;
text-transform: uppercase;
color: #FECEA8;
}
#globalNav a:hover {
position: absolute;
top: 1.3em;
padding: 0 0.25em;
-moz-padding-start: 0;
font-size: 1em;
text-transform: uppercase;
color: #ED6161;
-webkit-transition: .3s ease-in;
-moz-transition: .3s ease-in;
-ms-transition: .3s ease-in;
-o-transition: .3s ease-in;
transition: .3s ease-in;
}
/* dodecagram stars */
.stars {
background: #2A363B;
width: 60px;
height: 60px;
position: relative;
}
.stars:before, .stars:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 60px;
width: 60px;
background: #2A363B;
}
.stars:before {
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
}
.stars:after {
-webkit-transform: rotate(60deg);
-moz-transform: rotate(60deg);
-ms-transform: rotate(60deg);
-o-transform: rotate(60deg);
}
I already searched the forum (i.e., Center text with background CSS “shape”), however the solution didn't work for me.
Add the following CSS to your <a> tags inside the shapes and they will align in the center of the shape :)
position: absolute;
top: 1.3em;
-moz-padding-start: 0;
font-size: 1em;
text-transform: uppercase; /* Also, note that I removed the padding */
color: #FECEA8;
display: block;
width: 60px;
word-wrap: break-word;
}
http://jsfiddle.net/TVkNK/7/
Adding text-align:center to the css did it for me. I also used padding-top to add appropriate padding for vertical centering.