I have been trying everything I can think of, (not very good at this)
Im trying to center the text in those buttons vertically, here is the code:
<div id="menu">
<ul class="clearfix">
<li><i class="fa fa-home"></i> Home</li>
<li><i class="fa fa-hdd-o"></i> Services</li>
<li><i class="fa fa-area-chart"></i> Pricings & plans</li>
<li><i class="fa fa-envelope"></i> Contact</li>
<li><i class="fa fa-users"></i> The Team</li>
<!-- <li><i class="fa fa-sign-in"></i> Login</li>
<li><a href="#"><i class="fa fa-user"></i> Register</li>-->
</ul>
and the CSS:
#menu {
margin: 20px auto 0 auto;
width: 60%
}
#menu ul {
padding:0px;
list-style-type:none;
}
#menu a {
background-color: #EBEBEB;
font-size: 15px;
line-height: 10px;
height: 60px;
width: 100px;
position: relative;
padding: 0 20px;
float: left;
margin-top: 5px;
display: block;
color: #385c5b;
letter-spacing: 0.5px;
text-transform: uppercase;
font-weight: bold;
text-align: center;
text-shadow: 1px 1px 1px rgba(255,255,255,0.3);
border-radius: 3px 3px 0 0;
border-color:#eaeaea;
box-shadow:1px 1px 5px rgba(0,0,0,0.7);
margin-bottom: 5px;
}
#menu a:hover {
background-color:#5ba4b5;
}
#menu li {
float:left;
display:block;
margin-right:5px;
}
Thanks for any replies or other techniques.
You can use line-height see this http://jsfiddle.net/sfnxkav5/
#menu ul li a{
line-height:50px;
}
This won't center it exactly but it is suitable for the height you have given
You can use display:table-cell on the anchor tags
JSfiddle Demo
#menu {
margin: 20px auto 0 auto;
width: 60%
}
#menu ul {
padding: 0px;
list-style-type: none;
}
#menu a {
background-color: #EBEBEB;
font-size: 15px;
height: 60px;
width: 100px;
position: relative;
padding: 0 20px;
margin-top: 5px;
color: #385c5b;
letter-spacing: 0.5px;
text-transform: uppercase;
font-weight: bold;
text-align: center;
text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.3);
border-radius: 3px 3px 0 0;
border-color: #eaeaea;
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.7);
display: table-cell;
vertical-align: middle;
}
#menu a:hover {
background-color: #5ba4b5;
}
#menu li {
float: left;
display: block;
margin-right: 5px;
margin-bottom: 5px;
}
<div id="menu">
<ul class="clearfix">
<li><i class="fa fa-home"></i> Home
</li>
<li><i class="fa fa-hdd-o"></i> Services
</li>
<li><a id="a" href="#"><i class="fa fa-area-chart" ></i> Pricings & plans</a>
</li>
<li><i class="fa fa-envelope"></i> Contact
</li>
<li><i class="fa fa-users"></i> The Team
</li>
<!-- <li><i class="fa fa-sign-in"></i> Login</li>
<li><a href="#"><i class="fa fa-user"></i> Register</li>-->
</ul>
Related
.social-buttons ul li .fab:hover{
font-size: 30px;
}
.social-buttons{
position: absolute;
top: 100px;
left: 20px;
}
.social-buttons ul{
list-style: none;
}
.social-buttons ul li{
position: relative;
height: 50px;
width: 50px;
background-color: white;
border-radius: 10px;
margin: 10px 0px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
.social-buttons ul li .fab{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
font-size: 25px;
}
.social-buttons ul li .fab:hover{
font-size: 30px;
}
<script src="https://kit.fontawesome.com/fc692f1356.js" crossorigin="anonymous"></script>
<div class="social-buttons">
<ul>
<a href="#">
<li>
<i class="fab fa-instagram"></i>
</li>
</a>
<a href="#">
<li>
<i class="fab fa-pinterest"></i>
</li>
</a>
<a href="#">
<li>
<i class="fab fa-facebook-f"></i>
</li>
</a>
<a href="#">
<li>
<i class="fab fa-youtube"></i>
</li>
</a>
</ul>
I wrote the above code. It only increases the font size when hovering on only icons.
In the above fiddle . I want to change the font size(icon size) of .fab(icons) when the user hovers on .social-buttons ul li(the box covering the social media icons)
Replace .social-buttons ul li .fab:hover{ with .social-buttons ul li:hover .fab{.
Please note that your HTML is currently invalid. You have useless a tags wrapping your list items. Remove those, they're not allowed at that point. ul can only have li children. If you want the link-like mouse cursor, just add cursor: pointer; on the li.
.social-buttons {
position: absolute;
top: 100px;
left: 20px;
}
.social-buttons ul {
list-style: none;
}
.social-buttons ul li {
position: relative;
height: 50px;
width: 50px;
background-color: white;
border-radius: 10px;
margin: 10px 0px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
cursor: pointer;
}
.social-buttons ul li .fab {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 25px;
}
.social-buttons ul li:hover .fab {
font-size: 30px;
}
<script src="https://kit.fontawesome.com/fc692f1356.js" crossorigin="anonymous"></script>
<div class="social-buttons">
<ul>
<li>
<i class="fab fa-instagram"></i>
</li>
<li>
<i class="fab fa-pinterest"></i>
</li>
<li>
<i class="fab fa-facebook-f"></i>
</li>
<li>
<i class="fab fa-youtube"></i>
</li>
</ul>
</div>
For some reason I can't get my last nav link to stay with the rest of them. I can do this if i set .dropdown ul li .menu position to absolute, but then the drop down links are pushed to the right and not centered. Padding-right nor margin-right doesn't resolve this issue.
JSFiddle
Before
After
Position: Absolute
.title {
font-family: 'Philosopher', sans-serif;
margin-left: 20px;
color: white;
float: left;
padding-right: 70px;
padding-top: 5px;
}
#body {
background-color: black;
}
.dropdown ul {
padding-top: 10px;
}
.dropdown ul li .menu {
position: absolute;
float: none;
}
.menu-hover-lines {
margin-top: 35px;
float: right, bottom;
text-align: center;
text-transform: uppercase;
font-weight: 400;
letter-spacing: 3px;
transition: all 0.35s ease;
}
.menu-hover-lines li a {
padding: 0.75rem 0;
color: white;
position: relative;
margin-left: 1rem;
margin-right: 4rem;
margin-top: 20px;
}
.menu-hover-lines li:first-child a {
margin-left: 10px;
}
.menu-hover-lines li.active > a {
background-color: transparent;
}
/* Nav transition settings */
.menu-hover-lines a::before,
.menu-hover-lines a::after {
height: 3px;
position: absolute;
content: '';
transition: all 0.40s ease;
background-color: #932929;
width: 0;
}
.menu-hover-lines a::before {
top: 0;
left: 0;
}
.menu-hover-lines a::after {
bottom: 0;
right: 0;
}
/* Nav text settings on hover*/
.menu-hover-lines a:hover,
.menu-hover-lines li.active > a {
color: #8e8e8e;
transition: all 0.40s ease;
}
.menu-hover-lines a:hover::before,
.menu-hover-lines .active a::before,
.menu-hover-lines a:hover::after,
.menu-hover-lines .active a::after {
width: 100%;
}
.dropdown li .menu {
display: none;
}
.dropdown li:hover .menu {
display: inline-block;
float: none;
}
<!-- Nav Bar -->
<div class="dropdown" >
<ul class="menu dropdown menu-hover-lines" data-dropdown-menu>
<li>Home</li>
<li >Collections
<ul class="menu">
<li>Autos</li>
<li>Models</li>
<li>Extreme Sports</li>
</ul>
</li>
<li>About me</li>
<li>Get in touch
<ul class="menu">
<li><i class="fas fa-envelope fa-2x" data-toggle="tooltip" title="Email me!"></i></li>
<li><i class="fab fa-twitter fa-2x" data-toggle="tooltip" title="Tweet me!"></i></li>
<li><i class="fab fa-instagram fa-2x" data-toggle="tooltip" title="Message me!"></i></li>
</ul>
</li>
</ul>
</div>
I think you need to add left:0 and top:100% to your dropdown-menu with position:absolute. Remember to add position:relative to your .menu>li...
I have added .dropdown-menu class in the dropdown ul...
Also I noticed that you have written float: right, bottom in your css which is not valid...
Stack Snippet
body {
font: 13px Verdana;
}
.menu {
padding: 0;
display: flex;
}
.menu>li {
margin: 0 10px;
list-style: none;
position: relative;
}
.menu li a {}
.dropdown-menu {
padding: 0;
position: absolute;
top: 100%;
left: 0;
border: 1px solid;
padding: 10px;
}
.dropdown-menu>li {
list-style: none;
}
<!-- Nav Bar -->
<div class="dropdown">
<ul class="menu dropdown menu-hover-lines" data-dropdown-menu>
<li>Home</li>
<li>Collections
<ul class="dropdown-menu">
<li>Autos</li>
<li>Models</li>
<li>Extreme Sports</li>
</ul>
</li>
<li>About me</li>
<li>Get in touch
<ul class="menu">
<li><i class="fas fa-envelope fa-2x" data-toggle="tooltip" title="Email me!"></i></li>
<li><i class="fab fa-twitter fa-2x" data-toggle="tooltip" title="Tweet me!"></i></li>
<li><i class="fab fa-instagram fa-2x" data-toggle="tooltip" title="Message me!"></i></li>
</ul>
</li>
</ul>
</div>
I am working on a navigation sidebar with icons which on hover display text along with icon with reference to JFarrow's https://codepen.io/JFarrow/pen/fFrpg
<li>
<a href="http://justinfarrow.com">
<i class="fa fa-home fa-2x"></i>
<span class="nav-text">Dashboard</span>
</a>
</li>
But in my case I would like to hide icons when I hover on the sidebar and display only text.
May I know a best way to do this?
A pure css solution would be the next:
Hope this helps
Hice icon image
nav.main-menu:hover i:before {
display: none;
}
Adapt sidebar width
nav.main-menu:hover {
width:200px;
}
Reduce icon space
nav.main-menu:hover .fa{
width: 10px;
}
Added snipet so everyone can try it
#import url(//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css);
}
#import url(https://fonts.googleapis.com/css?family=Titillium+Web:300);
.fa-2x {
font-size: 2em;
}
.fa {
position: relative;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
font-size: 20px;
}
.main-menu:hover,
nav.main-menu.expanded {
width: 250px;
overflow: visible;
}
.main-menu {
background: #212121;
border-right: 1px solid #e5e5e5;
position: absolute;
top: 0;
bottom: 0;
height: 100%;
left: 0;
width: 60px;
overflow: hidden;
-webkit-transition: width .05s linear;
transition: width .05s linear;
-webkit-transform: translateZ(0) scale(1, 1);
z-index: 1000;
}
.main-menu>ul {
margin: 7px 0;
}
.main-menu li {
position: relative;
display: block;
width: 250px;
}
.main-menu li>a {
position: relative;
display: table;
border-collapse: collapse;
border-spacing: 0;
color: #999;
font-family: arial;
font-size: 14px;
text-decoration: none;
-webkit-transform: translateZ(0) scale(1, 1);
-webkit-transition: all .1s linear;
transition: all .1s linear;
}
.main-menu .nav-icon {
position: relative;
display: table-cell;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
font-size: 18px;
}
.main-menu .nav-text {
position: relative;
display: table-cell;
vertical-align: middle;
width: 190px;
font-family: 'Titillium Web', sans-serif;
}
.main-menu>ul.logout {
position: absolute;
left: 0;
bottom: 0;
}
.no-touch .scrollable.hover {
overflow-y: hidden;
}
.no-touch .scrollable.hover:hover {
overflow-y: auto;
overflow: visible;
}
a:hover,
a:focus {
text-decoration: none;
}
nav {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
nav ul,
nav li {
outline: 0;
margin: 0;
padding: 0;
}
.main-menu li:hover>a,
nav.main-menu li.active>a,
.dropdown-menu>li>a:hover,
.dropdown-menu>li>a:focus,
.dropdown-menu>.active>a,
.dropdown-menu>.active>a:hover,
.dropdown-menu>.active>a:focus,
.no-touch .dashboard-page nav.dashboard-menu ul li:hover a,
.dashboard-page nav.dashboard-menu ul li.active a {
color: #fff;
background-color: #5fa2db;
}
.area {
float: left;
background: #e2e2e2;
width: 100%;
height: 100%;
}
#font-face {
font-family: 'Titillium Web';
font-style: normal;
font-weight: 300;
src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v2/anMUvcNT0H1YN4FII8wpr24bNCNEoFTpS2BTjF6FB5E.woff) format('woff');
}
nav.main-menu:hover i:before {
display: none;
}
nav.main-menu:hover {
width: 200px;
}
nav.main-menu:hover .fa {
width: 10px;
}
<html>
<head>
</head>
<body>
<div class="area"></div>
<nav class="main-menu">
<ul>
<li>
<a href="http://justinfarrow.com">
<i class="fa fa-home fa-2x"></i>
<span class="nav-text">
Dashboard
</span>
</a>
</li>
<li class="has-subnav">
<a href="#">
<i class="fa fa-laptop fa-2x"></i>
<span class="nav-text">
UI Components
</span>
</a>
</li>
<li class="has-subnav">
<a href="#">
<i class="fa fa-list fa-2x"></i>
<span class="nav-text">
Forms
</span>
</a>
</li>
<li class="has-subnav">
<a href="#">
<i class="fa fa-folder-open fa-2x"></i>
<span class="nav-text">
Pages
</span>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-bar-chart-o fa-2x"></i>
<span class="nav-text">
Graphs and Statistics
</span>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-font fa-2x"></i>
<span class="nav-text">
Typography and Icons
</span>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-table fa-2x"></i>
<span class="nav-text">
Tables
</span>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-map-marker fa-2x"></i>
<span class="nav-text">
Maps
</span>
</a>
</li>
<li>
<a href="#">
<i class="fa fa-info fa-2x"></i>
<span class="nav-text">
Documentation
</span>
</a>
</li>
</ul>
<ul class="logout">
<li>
<a href="#">
<i class="fa fa-power-off fa-2x"></i>
<span class="nav-text">
Logout
</span>
</a>
</li>
</ul>
</nav>
</body>
</html>
You will need to set width:0 and visibility:hidden to the fa on .main-menu:hover
Also use flexbox...don't use table on <a> elements.
.main-menu:hover .fa {
width: 0;
visibility: hidden;
}
Stack Snippet
#import url(//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css);
}
#import url(https://fonts.googleapis.com/css?family=Titillium+Web:300);
.fa-2x {
font-size: 2em;
}
.fa {
position: relative;
width: 60px;
height: 36px;
line-height: 36px;
text-align: center;
font-size: 20px;
}
.main-menu:hover,
nav.main-menu.expanded {
width: 250px;
overflow: visible;
}
.main-menu {
background: #212121;
border-right: 1px solid #e5e5e5;
position: absolute;
top: 0;
bottom: 0;
height: 100%;
left: 0;
width: 60px;
overflow: hidden;
-webkit-transition: width .05s linear;
transition: width .05s linear;
-webkit-transform: translateZ(0) scale(1, 1);
z-index: 1000;
}
.main-menu>ul {
margin: 7px 0;
}
.main-menu li {
position: relative;
display: block;
width: 250px;
}
.main-menu li>a {
position: relative;
display: flex;
align-items: center;
border-spacing: 0;
color: #999;
font-family: arial;
font-size: 14px;
text-decoration: none;
-webkit-transform: translateZ(0) scale(1, 1);
-webkit-transition: all .1s linear;
transition: all .1s linear;
}
.main-menu .nav-icon {
position: relative;
width: 60px;
height: 36px;
text-align: center;
vertical-align: middle;
font-size: 18px;
}
.main-menu .nav-text {
position: relative;
width: 190px;
font-family: 'Titillium Web', sans-serif;
}
.main-menu>ul.logout {
position: absolute;
left: 0;
bottom: 0;
}
.no-touch .scrollable.hover {
overflow-y: hidden;
}
.no-touch .scrollable.hover:hover {
overflow-y: auto;
overflow: visible;
}
a:hover,
a:focus {
text-decoration: none;
}
nav {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
nav ul,
nav li {
outline: 0;
margin: 0;
padding: 0;
}
.main-menu li:hover>a,
nav.main-menu li.active>a,
.dropdown-menu>li>a:hover,
.dropdown-menu>li>a:focus,
.dropdown-menu>.active>a,
.dropdown-menu>.active>a:hover,
.dropdown-menu>.active>a:focus,
.no-touch .dashboard-page nav.dashboard-menu ul li:hover a,
.dashboard-page nav.dashboard-menu ul li.active a {
color: #fff;
background-color: #5fa2db;
}
.area {
float: left;
background: #e2e2e2;
width: 100%;
height: 100%;
}
#font-face {
font-family: 'Titillium Web';
font-style: normal;
font-weight: 300;
src: local('Titillium WebLight'), local('TitilliumWeb-Light'), url(http://themes.googleusercontent.com/static/fonts/titilliumweb/v2/anMUvcNT0H1YN4FII8wpr24bNCNEoFTpS2BTjF6FB5E.woff) format('woff');
}
.main-menu:hover .fa {
width: 0;
visibility: hidden;
}
.main-menu:hover a {
padding-left: 20px;
}
<div class="area"></div>
<nav class="main-menu">
<ul>
<li><i class="fa fa-home fa-2x"></i><span class="nav-text">Dashboard</span></li>
<li class="has-subnav"><i class="fa fa-laptop fa-2x"></i><span class="nav-text">UI Components</span></li>
<li class="has-subnav"><i class="fa fa-list fa-2x"></i><span class="nav-text">Forms</span></li>
<li class="has-subnav"><i class="fa fa-folder-open fa-2x"></i><span class="nav-text">Pages</span></li>
<li><i class="fa fa-bar-chart-o fa-2x"></i><span class="nav-text">Graphs and Statistics</span></li>
<li><i class="fa fa-font fa-2x"></i><span class="nav-text">Typography and Icons</span></li>
<li><i class="fa fa-table fa-2x"></i><span class="nav-text">Tables</span></li>
<li><i class="fa fa-map-marker fa-2x"></i><span class="nav-text">Maps</span></li>
<li><i class="fa fa-info fa-2x"></i><span class="nav-text">Documentation</span></li>
</ul>
<ul class="logout">
<li><i class="fa fa-power-off fa-2x"></i><span class="nav-text">Logout</span></li>
</ul>
</nav>
Default the icon to display none and then add hover css property. Something like this,
<li>
<a href="http://justinfarrow.com">
<i class="fa fa-home fa-2x my_icon"></i>
<span class="nav-text">
Dashboard
</span>
</a>
</li>
<style>
.my_icon{
display :none;
}
.my_icon:hover{
display :visible;
}
</style>
I have two elements menu and header/ribbon with user information. menu looks good but ribbon with username not fit into a page very well. Please see my code:
JSFiddle
jQuery(document).ready(function() {
jQuery('.toggle-nav').click(function(e) {
jQuery(this).toggleClass('active');
jQuery('.menu ul').toggleClass('active');
e.preventDefault();
});
});
body{
width:100%;
margin: 0 auto;
}
.menu {
width: 100%;
position:relative;
display:inline-block;
}
.menu ul.active {
display:none;
}
.menu ul {
position:absolute;
top:90%;
left:0px;
padding:10px 10em 0em 2em; /* menu width */
border-radius:7px;
background:#4CAF50;
}
.menu ul:after { /* black triangle position */
width:0px;
height:0px;
position:absolute;
top:0%;
left:22px;
content:'';
transform:translate(0%, -100%);
border-left:7px solid transparent;
border-right:7px solid transparent;
border-bottom:7px solid #303030;
}
.menu li {
margin:5px -100px 5px 0px; /* text inside menu width */
float:none;
display:block;
}
.menu li * {
vertical-align: middle;
}
.menu a {
display:block;
}
.toggle-nav {
padding:20px; /* squere element size */
float:left;
display:inline-block;
box-shadow:0px 1px 1px rgba(0,0,0,0.15);
border-radius:4px;
background:#4CAF50;
color:#FFFFFF;
font-size:25px;
transition:color linear 0.15s;
font-weight: bold;
}
.toggle-nav:hover, .toggle-nav.active {
text-decoration:none;
color:#FFFFFF;
}
.band {
position:relative;
top:-72px;
right:-70px;
padding:14px; /* element size */
width: 100%;
float:left;
display:inline-block;
box-shadow:0px 1px 1px rgba(0,0,0,0.15);
border-radius:4px;
background:#4CAF50;
color:#FFFFFF;
font-size:17px;
transition:color linear 0.15s;
font-weight: bold;
}
.ribbon:before {
content: "";
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<nav class="menu">
<ul class="active">
<li class="current-item"><a href="?action=?home">
<i class="fa fa-home fa-3x" aria-hidden="true"></i> <strong class="fa-home-1x home-text">Home</strong></a></li>
<li>
<i class="fa fa-sign-language fa-3x" aria-hidden="true"></i> <strong class="a-sign-language-1x sign-language-text">Menu1</strong></li>
<li>
<i class="fa fa-flag-checkered fa-3x" aria-hidden="true"></i> <strong class="a-sign-language-1x sign-language-text">Manu2</strong></li>
<li>
<i class="fa fa-truck fa-3x" aria-hidden="true"></i> <strong class="a-sign-language-1x sign-language-text">Menu3</strong></li>
<li>
<i class="fa fa-sign-out fa-3x" aria-hidden="true"></i> <strong class="fa-home-1x sign-out-text">Sign Out</strong></li>
</ul>
<a class="toggle-nav" href="#"><i class="fa fa-bars"></i></a>
</nav>
<div class="band"><i class="fa fa-user" aria-hidden="true"></i> User Name<i class="ribbon"></i><i class="fa fa-sign-language" aria-hidden="true"></i> Another name</div>
When a screen is wide you can see a big white gap on the right-hand side but when I'm looking this code on a small screen then ribbon overlap. How I can show always 100% width of ribbon menu square need to be in same position and same width
You can change the width of .band to:
width: calc(100% - 97px);
as the width of the menu is fixed to 97px, including the paddings and margins. We can get the left space for the right part by getting the full width - 97px (100% - 97px) by using calc().
Wish that this helped you.
You could do it with CSS flex:
jQuery(document).ready(function() {
jQuery('.toggle-nav').click(function(e) {
jQuery(this).toggleClass('active');
jQuery('.menu ul').toggleClass('active');
e.preventDefault();
});
});
body {
display: flex;
}
.menu {
position: relative;
}
.menu ul.active {
display: none;
}
.menu ul {
position: absolute;
top: 90%;
left: 0;
padding: 10px 10em 0em 2em; /* menu width */
border-radius: 7px;
background: #4CAF50;
}
.menu ul:after { /* black triangle position */
width: 0;
height: 0;
position: absolute;
top: 0;
left: 22px;
content: '';
transform: translate(0%, -100%);
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #303030;
}
.menu li {
margin: 5px -100px 5px 0px; /* text inside menu width */
float: none;
display: block;
}
.menu li * {
vertical-align: middle;
}
.menu a {
display: block;
}
.toggle-nav {
padding: 20px; /* squere element size */
float: left;
display: inline-block;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.15);
border-radius: 4px;
background: #4CAF50;
color: #FFFFFF;
font-size: 25px;
transition: color linear 0.15s;
font-weight: bold;
}
.toggle-nav:hover, .toggle-nav.active {
text-decoration: none;
color: #FFFFFF;
}
.band {
flex: 0 1 100%;
padding: 14px; /* element size */
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.15);
border-radius: 4px;
background:#4CAF50;
color: #FFFFFF;
font-size: 17px;
transition: color linear 0.15s;
font-weight: bold;
margin-left: 10px;
}
.ribbon:before {
content: '';
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<nav class="menu">
<ul class="active">
<li class="current-item"><a href="?action=?home">
<i class="fa fa-home fa-3x" aria-hidden="true"></i> <strong class="fa-home-1x home-text">Home</strong></a></li>
<li>
<i class="fa fa-sign-language fa-3x" aria-hidden="true"></i> <strong class="a-sign-language-1x sign-language-text">Menu1</strong></li>
<li>
<i class="fa fa-flag-checkered fa-3x" aria-hidden="true"></i> <strong class="a-sign-language-1x sign-language-text">Manu2</strong></li>
<li>
<i class="fa fa-truck fa-3x" aria-hidden="true"></i> <strong class="a-sign-language-1x sign-language-text">Menu3</strong></li>
<li>
<i class="fa fa-sign-out fa-3x" aria-hidden="true"></i> <strong class="fa-home-1x sign-out-text">Sign Out</strong></li>
</ul>
<a class="toggle-nav" href="#"><i class="fa fa-bars"></i></a>
</nav>
<div class="band"><i class="fa fa-user" aria-hidden="true"></i> User Name<i class="ribbon"></i><i class="fa fa-sign-language" aria-hidden="true"></i> Another name</div>
JSFiddle
try this one:
body{
width:100%;
margin: 0 auto;
}
.menu {
width: 100%;
position:relative;
display:inline-block;
}
.menu ul.active {
display:none;
}
.menu ul {
position:absolute;
top:90%;
left:0px;
padding:10px 10em 0em 2em; /* menu width */
border-radius:7px;
background:#4CAF50;
}
.menu ul:after { /* black triangle position */
width:0px;
height:0px;
position:absolute;
top:0%;
left:22px;
content:'';
transform:translate(0%, -100%);
border-left:7px solid transparent;
border-right:7px solid transparent;
border-bottom:7px solid #303030;
}
.menu li {
margin:5px -100px 5px 0px; /* text inside menu width */
float:none;
display:block;
}
.menu li * {
vertical-align: middle;
}
.menu a {
display:block;
}
.toggle-nav {
padding:20px; /* squere element size */
float:left;
display:inline-block;
box-shadow:0px 1px 1px rgba(0,0,0,0.15);
border-radius:4px;
background:#4CAF50;
color:#FFFFFF;
font-size:25px;
transition:color linear 0.15s;
font-weight: bold;
}
.toggle-nav:hover, .toggle-nav.active {
text-decoration:none;
color:#FFFFFF;
}
.band {
position:relative;
top:-72px;
right:-70px;
padding:14px; /* element size */
width: 100%;
float:left;
display:inline-block;
box-shadow:0px 1px 1px rgba(0,0,0,0.15);
border-radius:4px;
background:#4CAF50;
color:#FFFFFF;
font-size:17px;
transition:color linear 0.15s;
font-weight: bold;
}
.ribbon:before {
content: "";
display: block;
}
DEMO HERE
I have a CSS menu with a submenu. Everything works fine, but the submenu on my right menu item goes outside the container. I'm wondering if there is a way to prevent this.
Here is what it's doing:
http://s28.postimg.org/dbl1vmtql/dropdown.png
Here is my code:
<body>
<div class="container">
<div class="header">
</div>
<div class="nav">
<ul id="nav">
<li><i class="fa fa-home"></i> Home</li>
<li><i class="fa fa-css3"></i> CSS</li>
<li><i class="fa fa-list-ul"></i> XML</li>
<li><i class="fa fa-pencil-square-o"></i> Form</li>
<li><i class="fa fa-globe"></i> Connected Media
<ul>
<li><i class="fa fa-comments"></i> Discussion</li>
<li><i class="fa fa-street-view"></i> Google Maps</li>
<li><i class="fa fa-wordpress"></i> WordPress</li>
</ul>
</li>
<li><i class="fa fa-html5"></i> HTML 5</li>
<li><i class="fa fa-search"></i> Research
<ul>
<li><i class="fa fa-th-large"></i> Web Page Layout</li>
<li><i class="fa fa-copyright"></i> Copyright & Privacy</li>
<li><i class="fa fa-list-alt"></i> References</li>
</ul>
</li>
</ul>
</div>
<div class="content">
</div>
</div>
</body>
And here is my CSS;
body {
background: -webkit-linear-gradient(#E1E1E1, #D6D6D6); /* For Safari 5.1 to 6.0 */
background: -moz-linear-gradient(#E1E1E1, #D6D6D6); /* For Firefox 3.6 to 15 */
background: linear-gradient(#E1E1E1, #D6D6D6); /* Standard syntax */
background-attachment: fixed;
margin: 0px 0px 0px 0px;
font-family: Verdana;
font-size: 14px;
color: #000000;
}
.container {
width:920px;
margin: 0 auto;
-webkit-box-shadow: 0px 0px 7px 2px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 7px 2px rgba(0,0,0,0.75);
box-shadow: 0px 0px 7px 2px rgba(0,0,0,0.75);
}
.content {
background-color: #F6F6F6;
padding: 5px;
height: 910px;
margin-left: auto;
margin-right: auto;
}
.header {
background-color: #F6F6F6;
padding: 5px;
margin-left: auto;
margin-right: auto;
height: 200px;
border-bottom: 1px solid #454545;
}
.nav {
background-color: #CCC;
width: 920px;
height: 30px;
border-bottom: 1px solid #454545;
}
.nav ul {
list-style:none;
display: inline;
-webkit-padding-start: 0px;
line-height: 30px;
}
.nav ul li {
float:left;
}
.nav ul li a {
padding: 6px 28px 6px 28px;
text-decoration: none;
font-weight: bold ;
color: #000;
letter-spacing: -0.5px;
-webkit-transition: background-color 1s;
-moz-transition: background-color 1s;
transition: background-color 1s;
}
.nav ul li a:hover {
background-color:#DFDFDF;
color: #272727;
padding: 6px 28px 6px 28px;
}
.nav ul li a.active {
background: #DFDFDF;
padding: 6px 28px 6px 28px;
}
ul#nav ul {
display: none;
}
ul#nav li:hover > ul {
position: absolute;
display: block;
height: 30px;
background-color: #CCC;
border-bottom: 1px solid #000;
border-right: 1px solid #000;
border-left: 1px solid #000;
}
ul#nav li:hover > ul li a {
float: right;
line-height: 30px;
color: #000000;
text-decoration: none;
padding: 0 30px 0 0;
}
ul#nav li:hover > ul li a:hover {
color: #000000;
text-decoration: none;
}
You need to set the main content container with:
position: relative;
And then style this last submenu with:
position: absolute;
right: 0;