I have a nav element with 4 items.
When I click on any of the elements, I notice that the items shift apart slightly, and the div expands.
<div id="siteNavigation" class="navDiv">
<nav>
<ul>
<li><span>Home</span></li>
<li>Meet Me</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
.navDiv {
display: inline;
width: auto;
float: right;
border: solid;
}
nav ul {
clear: both;
list-style-position: inside;
clear: left;
list-style: none;
margin-left: 0;
width: auto;
padding-top: 32px;
text-align: center;
white-space: nowrap;
}
nav ul li {
display: inline-block;
white-space: nowrap;
padding-left: 8px;
border: none;
}
nav ul li a {
color: #000000;
/* #E3CF9C */
font-size: 1em;
font-weight: bold;
text-decoration: none;
letter-spacing: 0.05em;
padding: 10px 3.125% 26px 3.125%;
text-transform: uppercase;
border: none;
}
nav ul li a:hover {
color: #BF0000;
}
nav ul li a.selected {
color: #BF0000;
}
nav ul li a.selected:hover {
color: #E3CF9C;
}
JSFiddle example: https://jsfiddle.net/rfhasw48/1/
What do I need to change to make the nav stay a constant size?
Just remove the padding from nav ul li a.
Updated CSS:
.navDiv {
display: inline;
width: auto;
float: right;
border: solid;
}
nav ul {
clear: both;
list-style-position: inside;
clear: left;
list-style: none;
margin-left: 0;
width: auto;
padding-top: 32px;
text-align: center;
white-space: nowrap;
}
nav ul li {
display: inline-block;
white-space: nowrap;
padding-left: 8px;
border: none;
}
nav ul li a {
color: #000000;
/* #E3CF9C */
font-size: 1em;
font-weight: bold;
text-decoration: none;
letter-spacing: 0.05em;
text-transform: uppercase;
border: none;
}
nav ul li a:hover {
color: #BF0000;
}
nav ul li a.selected {
color: #BF0000;
}
nav ul li a.selected:hover {
color: #E3CF9C;
}
Related
After nearly a week I am still struggling with toggle on navigation.
This is my current CSS, what I need to do now, is simply get the toggle to open, it did open before so something minor is stopping it now but I cant work it out. I do not really know much about CSS as I keep forgetting it, but I do not know javascript or jquery
.nav {
background-color: #3333FF;
width: 100%;
}
.menu label,
#hamburger {
display: none;
}
.menu ul {
font-family: Monserrat, sans-serif;
font-size: 18px;
color: white;
list-style-type: none;
margin: 0;
padding: 0;
}
.menu ul li {
text-align: center;
display: inline-block;
padding: 10px;
width: 11.11%;
}
.menu ul li a {
color: #fff;
text-decoration: none;
}
.menu li:visited {
background: #0000EE;
color: #fff;
}
.menu li:active,
.active {
background: #0000EE;
color: #fff;
}
.menu li:hover {
background: #0000EE;
color: #fff;
}
label {
margin: 0 20px 0 0;
font-size: 20px;
line-height: 44px;
display: none;
}
#toggle {
display: none;
}
/* Show Hamburger */
#media screen and (max-width: 768px) {
.nav {
background-color: #3333FF;
width: 100%;
}
``` .menu label {
display: inline-block;
color: #fff;
background-color: #3333FF;
padding-bottom: 8px;
}
.menu ul {
display: none;
}
.menu ul li {
display: block;
border-top: 1px solid #333;
}
.menu ul li:active {
display: block;
}
.menu label {
cursor: pointer;
margin: 0 20px 0 0;
font-size: 20px;
font-weight: bold;
line-height: 44px;
display: block;
}
#toggle:checked+.menu {
display: block;
}
<div class="nav">
<div class="menu">
<label for="toggle">☰</label><input type="checkbox" id="toggle">
<ul>
<li>Home</li>
<li>News</li>
<li>Contacts</li>
<li>Policies</li>
<li class="active">Members</li>
<li>Volunteer</li>
<li>Links</li>
</ul>
</div>
</div>
Here is an example for this. You can try this code. It is fully tested. I hope it will help you. You can change colors and backgrounds as per needed in this code.
nav ul ul {
display: none;
}
nav ul ul li {
float: none;
}
nav li {
float: left;
list-style-type: none;
}
nav li a {
text-decoration: none;
display: inline-block;
margin: 10px 20px 5px 0;
padding: 8px 10px;
}
nav li a:link, nav li a:visited {
color: #646565;
background: #e8e9eb;
}
nav li a:link:hover, nav li a:visited:hover {
color: black;
}
nav li:hover ul {
display: block;
position: absolute;
}
input.toggle,
label.toggle {
display: none;
}
label.toggle {
font-weight: 900;
font-size: 1.2em;
padding: 10px 20px;
}
#media (max-width: 960px) {
nav {
display: none;
}
input.toggle, .toggle span {
display: none;
}
input[type=checkbox]:checked ~ nav, label.toggle {
display: block;
cursor: pointer;
}
nav li {
float: none;
}
nav li:hover ul {
display: block;
position: relative;
}
nav li ul {
display: block;
}
nav li ul li {
margin-left: 20px;
}
nav li a {
display: block;
margin-left: 20px;
}
}
<div class="wrapper">
<label class="toggle" for="toggle">☰ <span>Menue</span></label>
<input class="toggle" id="toggle" type="checkbox">
<nav>
<ul>
<li class="current">Home</li>
<li>News</li>
<li>Contacts</li>
<li>Policies</li>
<li>Members</li>
<li>Volunteer</li>
<li>Links</li>
</ul>
</nav>
</div>
Just change your selector from:
#toggle:checked+.menu {
display: block;
}
to:
#toggle:checked+ ul {
display: block;
}
See snippets below:
.nav {
background-color: #3333FF;
width: 100%;
}
.menu label,
#hamburger {
display: none;
}
.menu ul {
font-family: Monserrat, sans-serif;
font-size: 18px;
color: white;
list-style-type: none;
margin: 0;
padding: 0;
}
.menu ul li {
text-align: center;
display: inline-block;
padding: 10px;
width: 11.11%;
}
.menu ul li a {
color: #fff;
text-decoration: none;
}
.menu li:visited {
background: #0000EE;
color: #fff;
}
.menu li:active,
.active {
background: #0000EE;
color: #fff;
}
.menu li:hover {
background: #0000EE;
color: #fff;
}
label {
margin: 0 20px 0 0;
font-size: 20px;
line-height: 44px;
display: none;
}
#toggle {
display: none;
}
/* Show Hamburger */
#media screen and (max-width: 768px) {
.nav {
background-color: #3333FF;
width: 100%;
}
.menu label {
display: inline-block;
color: #fff;
background-color: #3333FF;
padding-bottom: 8px;
}
.menu ul {
display: none;
}
.menu ul li {
display: block;
border-top: 1px solid #333;
}
.menu ul li:active {
display: block;
}
.menu label {
cursor: pointer;
margin: 0 20px 0 0;
font-size: 20px;
font-weight: bold;
line-height: 44px;
display: block;
}
#toggle:checked+ul {
display: block;
}
<div class="nav">
<div class="menu">
<label for="toggle">☰</label><input type="checkbox" id="toggle">
<ul>
<li>Home</li>
<li>News</li>
<li>Contacts</li>
<li>Policies</li>
<li class="active">Members</li>
<li>Volunteer</li>
<li>Links</li>
</ul>
</div>
</div>
I created a dropdown menu and I am trying to get rid of the little space that I am getting at the beginning of the dropdown, between the parent component and its children, as shown in the screenshot below:
I want the drop down to begin from where the tab starts, something like this:
--------
| Parent
-----------
| Child
------------
Please, find a code snippet attached below:
ul {
list-style-type: none;
margin: 0;
padding-left: 25px;
padding-right: 10px;
position: absolute;
}
li {
display: inline-block;
float: left;
margin-right: 1px;
}
li a {
display: block;
min-width: 138.7px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
padding-left: 10px;
padding-right: 10px;
}
li:hover a {
background: green;
}
li:hover ul a {
background: grey;
color: #2f3036;
height: 40px;
line-height: 40px;
text-align: center;
}
li:hover ul a:hover {
background: green;
color: #fff;
}
li ul {
display: none;
}
li ul li {
display: block;
float: none;
}
li ul li a {
width: auto;
min-width: 100px;
}
ul li a:hover+.hidden,
.hidden:hover {
display: block;
width: auto;
}
#menu {
text-align: center;
}
<ul class="menu">
<li>Somthing</li>
<li> something
<ul class="hidden">
<li>somethoing</li>
<li>something</li>
</ul>
</li>
</ul>
Thanks in advance.
Set the padding to 0 on your hidden class. .hidden{padding: 0;} and also remove the li ul li a{width:auto; min-width:100px;} JSFiddle I changed your media query so it can be viewed in here.
ul {
list-style-type:none;
margin:0;
padding-left: 25px;
padding-right: 10px;
position: absolute;
}
li {
display:inline-block;
float: left;
margin-right: 1px;
}
li a {
display:block;
min-width:138.7px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff;
background: #2f3036;
text-decoration: none;
padding-left: 10px;
padding-right: 10px;
}
li:hover a {
background:green ;
}
li:hover ul a {
background: grey;
color: #2f3036;
height: 40px;
line-height: 40px;
text-align:center;
}
li:hover ul a:hover {
background: green;
color: #fff;
}
li ul {
display: none;
}
li ul li {
display: block;
float: none;
}
.hidden{
padding: 0;
}
ul li a:hover + .hidden, .hidden:hover {
display:block;
width: auto;
}
#menu{
text-align:center;
}
#media screen and (max-width : 460px){
ul {
position: static;
display: none;
}
li {
margin-bottom: 1px;
}
ul li, li a {
width: 100%;
}
.show-menu {
display:block;
}
}
<ul class="menu">
<li>Something</li>
<li> something
<ul class="hidden">
<li>something</li>
<li>something</li>
</ul>
</li>
</ul>
li{position: relative;}
ul li ul{padding: 0; width: 100%;}
So I'm simply trying to get the text in each line item to be position at the bottom of the square rather than stuck at the top. Here is a screenshot of what my nav looks like http://imgur.com/QLPBYQK
And here is my code:
<div id="nav">
<ul>
<li>Home</li>
<li>Supplies</li>
<li>FAQ</li>
</ul>
</div>
#nav {
height: 50px;
width: 950px;
margin: auto;
background-color: #FF5252;
font-family: sans-serif, Georgia;
border: 5px solid white;
}
#nav ul {
margin: 0px;
padding: 0px;
}
#nav ul li {
float: left;
width: 145px;
}
#nav ul li a {
font-size: 20px;
text-align: center;
color: white;
background-color: #FF5252;
display: block;
text-decoration: none;
height: 50px;
}
JSFiddle.
Add this attribute:
line-height:80px;
To the Class:
#nav ul li a {
font-size: 20px;
text-align: center;
color: white;
background-color: #FF5252;
display: block;
text-decoration: none;
height: 50px;
line-height:80px;
}
Add list-style: none to #nav ul li and line-height: 50px(should be the same as height of the a element, if you want to center the text vertically) to #nav ul li a.
Demo
#nav ul li {
float: left;
width: 145px;
list-style: none;
}
#nav ul li a {
font-size: 20px;
text-align: center;
color: white;
background-color: #FF5252;
display: block;
text-decoration: none;
height: 50px;
line-height: 50px;
}
Don't use height; instead use appropriate padding-top.
#nav ul li a {
font-size: 20px;
text-align: center;
color: white;
background-color: #FF5252;
display: block;
text-decoration: none;
padding-top: 28px;
}
Use padding-top or
line-height in nav ul li a
My dropdown works fine, except it closes before i can move mouse top of last link in it.
CSS
nav {
width: 100%;
display: inline-block;
margin-bottom: 1%;
text-align: center;
background-color: #F0F0F0;
}
nav .links {
width: 100%;
line-height: 1.2;
font-size: 100%;
text-decoration: underline;
text-align: center;
}
nav .links a {
color: #666666;
text-decoration: none;
word-spacing: normal;
}
nav .links a:visited {
color: #666666;
text-decoration: none;
}
nav .links a:hover {
color: #383838;
text-decoration: none;
}
nav .links a:active {
color: #666666;
text-decoration: none;
}
nav ul {
position:relative;
list-style:none;
color: #666666;
white-space: nowrap;
}
nav li{
position:relative;
float: left;
margin-left: 5%;
}
nav ul li ul {
display: none;
position: absolute;
background-color: #F0F0F0;
border: 2px solid;
border-radius: 5px;
padding: 0.5em 1em 0.5em 0.5em;
line-height: 1.2;
}
ul li:hover ul {
display: block;
}
HTML
<nav>
<div class="links">
<ul>
<li>ETUSIVU</li>
<li>HENKILÖKUVA JA HISTORIA</li>
<li>KORISTEKERAMIIKKA</li>
<li>GALLERIA
<ul>
<li>Keramiikkaveistokset</li>
<li>Keramiikka - kuparityöt</li>
<!--Next link is the one where dropdown closes before mouse reaches it-->
<li>Krisu testi</li>
</ul>
</li>
</ul>
</div>
I tested it with Chrome and FF. CSS is not top skill for me and i think this should work but obviously im wrong :)
I would appreciate help with this greatly, thanks.
EDIT
I changed nav ul li ul as...
nav ul li ul {
z-index: 1;
display: none;
position: absolute;
background-color: #F0F0F0;
border: 2px solid;
border-radius: 5px;
padding: 0.5em 1em 0.5em 0.5em;
}
and now it works just fine. So basically i just added z-index there.
There is an image right below dropdows, not sure is it possible that it messes this one? Atleast z-index did help...
im fairly new to ASP.net and CSS i would like to style my link button like my other <a href> buttons in css but they are not working.
this is my code for menu
<div id="templatemo_menu">
<ul>
<li><span>Reconciliation</span>
<ul>
<li>
<asp:LinkButton ID="MyLink" runat="server" OnClick="MyLink_Click" Text="Double Entry Per Total Expired"></asp:LinkButton>
</li>
</ul>
</li>
<li><span>Reports</span>
<ul>
<li><span>Report Generation</span></li>
<li><span>Upload Prenda</span></li>
<li><span>Navision Uploader</span></li>
</ul>
</li>
<li><span>Maintenance</span>
<ul>
<li><span>Report Matrix</span></li>
<li><span>Branches</span></li>
<li><span>Audit Trail</span></li>
</ul>
</li>
</ul>
</div>
and this is my CSS for the Menu
/* menu */
#templatemo_menu
{
clear: both;
width: 100%;
height: 30px; /*padding: 0 10px;*/ /*margin-bottom: 20px;*/ /*margin-left:13px;*/
background: url(../Images/bgContent.jpg) center no-repeat;
}
#templatemo_menu ul
{
/*float: left;*/
margin: 0 auto;
text-align: center;
width: 100%;
display: inline-block;
height: 70px;
margin: 0;
padding: 1px 0;
list-style: none;
}
#templatemo_menu ul li
{
padding: 0 0 0 0;
margin: 0;
display: inline-block;
}
#templatemo_menu ul li a
{
float: left;
display: block;
height: 22px;
width: 440px;
padding: 5px 0 0 0;
font-size: 11px;
color: #666;
text-align: center;
text-decoration: none;
font-weight: normal;
outline: none;
border: none;
background: url(../Images/templatemo_menu_divider.gif) repeat-y right;
}
#templatemo_menu ul li a span
{
display: block;
font-size: 17px;
font-weight: normal;
color: #ffffff;
}
#templatemo_menu ul li .last
{
background: none;
}
#templatemo_menu ul li a:hover, #templatemo_menu ul .current
{
color: #a13c03;
}
#templatemo_menu ul li a:hover span, #templatemo_menu ul .current span
{
color: #a13c03;
}
#templatemo_menu ul li a span:hover
{
color: #a13c03;
}
#templatemo_menu ul li:hover
{
background: #0298D7;
}
#templatemo_menu li:hover ul
{
display: block;
background: #0A5185;
height: auto;
width: 440px;
margin-top: 25px;
z-index: 2;
}
#templatemo_menu li ul
{
display: none;
position: absolute;
}
#templatemo_menu li ul li
{
clear: both;
border-style: none;
}
#templatemo_menu li ul li:hover
{
background-color: #0298D7;
}
i tried a.MyLink:link{do css here} nut it is not working.. any help?? :(
Change your link button to this
<asp:LinkButton ID="MyLink" runat="server"><span>Double Entry Per Total Expired</span></asp:LinkButton>
Your style is targeting the span > anchor, so you'll need to add that span around the text like you did for the other anchor tags