I hope someone can guide me towards the right direction. I was learning how to use the :before and :after in CSS, so I tried to create a menu navigation, somehow I managed to make it how I wanted with displaying the right shadow image as :before and a :after but now as soon as I roll over my menu it goes up. I tried to put padding and margin with !important but nothing worked.
My second problem is in <li> I have a link <a> but it only changes color of rollover on text. I want to change the color on the whole menu <li> but it doesn't work. My code is in this JsFiddle:
HTML:
<div id="menu">
<ul>
<li class="proxima_bold">Menu1</li>
<li class="proxima_bold">Menu2</li>
<li class="proxima_bold">Menu3</li>
<li class="proxima_bold">Menu4</li>
</ul>
</div>
CSS:
#menu {
text-transform:uppercase;
position:relative;
}
#menu ul{
margin: 0; padding: 0;
float: left;
margin-top:-10px !important;
color:#787878;
}
#menu ul li{
display: inline;
float: left;
padding: 20px 15px 20px 15px;
color:#787878;
background: url(http://www.example.com/p7lpz) no-repeat 0 20px;
}
#menu ul li:hover{
background: url(http://www.example.com/2v4ik) repeat-x;
padding:0;
margin:0;
color: #7fc652 !important;
cursor:pointer;
}
#menu ul li a {
color: #787878;
display:inline-block;
}
#menu ul li a:hover {
color: #7fc652;
}
#menu ul li:hover:after,
#menu ul li:hover:before{
content: "";
position:relative;
top:0;
width:15px;
height:55px;
display:inline-block;
vertical-align:middle;
}
#menu ul li:hover:after{
right: -15px;
background: url(http://www.example.com/9tly4) no-repeat 0 0;
}
#menu ul li:hover:before{
left: -15px;
background: url(http://www.example.com/u969z) no-repeat 0 0;
}
#menu ul li .selected{
float: left;
text-decoration: none;
font-weight:bold;
color: white;
padding: 0 20px 0 20px;
color:#444;
background: url(http://www.example.com/p7lpz) no-repeat 0 0;
}
Please let me know how to fix this.
I HAVE FIXED IT MYSELF. Thank you all for your time.
Is this what you want? I am not sure what the images are supposed to do.
jsfiddle
Related
I have a dropdown menu that is working well except for one minor bug that I cannot solve.
The first dropdown menu item appears normally. However, the second dropdown menu item is shifted slightly to the right. I am guessing that the margin-right that I set to the link caused the dropdown menu to shift slightly to the right. If that is the case, what can I do to go around the problem?
It's a simple nav menu that sets the position of the dropmenu item to absolute, and is hidden by the parent element's overflow:hidden feature. On hover, the dropdown menu is brought into view with overflow:visible.
The live site is here -> nav menu
CSS
#mainMenu {
position: relative;
}
#mainMenu ul {
list-style: none;
float: right;
background-color: #FFFFFF;
}
#mainMenu ul li {
position: relative;
display: inline;
float: left;
/*padding-right: 1.5em;*/
font-size: 1.2em;
zoom:1;
overflow: hidden;
}
#mainMenu>ul>li {
line-height: 2em;
}
#mainMenu ul li:hover {
overflow: visible;
}
#mainMenu ul li a {
float: left;
text-decoration: none;
color: black;
padding: 0 1em;
}
#mainMenu>ul>li:last-child a {
padding:0.4em 1em 0.4em 1em;
border-radius:4px;
background-color: #00b200;
color: #FFFFFF;
}
#mainMenu ul li a:hover{
text-decoration: none;
color: rgb(42, 160, 239);
}
#mainMenu ul ul{
position: absolute;
top: 2em;
left: 60%;
width: 10em;
margin-left: -3em;
height: auto;
border: solid #CCC;
border-width: 0 1px 1px;
}
#mainMenu ul ul:first-child{
padding-top: 2em;
}
#mainMenu ul ul li,
#mainMenu ul ul a {
display:block;
float:none;
border:0;
box-shadow:none;
text-align:center;
font-size: 1em;
padding: 0.4em;
text-align: left;
}
#mainMenu ul ul li:first-child {
border-top:1px solid rgb(72, 147, 196);
}
#mainMenu ul ul li {
border-top: 1px solid #e9e9e9;
}
#mainMenu a:active,
#mainMenu a:focus,
#mainMenu a:hover {
background:#F2F6FA;
color:#333;
}
HTML
<div id="nav-row">
<h1>
<a href="\">
Corporate Site
<span></span>
</a>
</h1>
<div id="mainMenu">
<ul>
<li>About
<ul>
<li class="company">Company Profile</li><li class="team">
The Team</li><li class="linsux">
Pricing Packages</li>
</ul></li>
<li>Services
<ul>
<li class="webDesign">Websites</li><li class="Emails">
Landing Pages</li><li class="Logos">
Logos</li>
</ul></li>
</li>
<li>Case Studies</li><li>
Blog</li><li>
Contact</li><li>
Free Web Analysis</li>
</ul>
</div>
</div>
It because you use to indent the submenu % of parent width which isn't the same. margin-left: -3em is a constant.
Use, for example:
left: -10px; /* I see the first submenu cca. 10px before the parent LI */
margin-left: 0;
Not sure why you indent by 60% and the move the submenu back using -3em.
try the following :
#mainMenu ul ul {
left: 39% !important;
}
Or
#mainMenu ul ul {
left: 0;
margin-left: 0;
}
I have a dropdown menu on my website, and its acting buggy, the dropdown works, but it shifts my whole website when its hovered over.
code pen http://codepen.io/anon/pen/uaFDj
#nav {
}
#nav {
background: none repeat scroll 0 0 #585858;
border-radius: 3px;
height: 50px;
margin-bottom: 10px;
padding: 0;
}
#searchbar input[type=text] {
background: none repeat scroll 0 0 #fff;
border: 1px solid black;
height: 25px;
padding: 1px 1px 1px 5px;
width: 230px;
}
#searchbar input[type="submit"] {
background: none repeat scroll 0 0 #1abc9c;
border: 1px solid #12ab8d;
color: white;
cursor: pointer;
font-size: 14px;
padding: 4px 15px;
}
#searchbar { margin-right:10px; }
#nav ul {
list-style: none outside none;
margin: 0;
padding: 0 0 0 10px;
}
#nav ul li {
line-height:50px;
float:left;
}
#nav ul li a {
line-height:50px;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
font-weight:400;
text-decoration:none;
color:#FFF;
background-color:none repeat scroll 0 0 #585858;
display:block;
padding:0 20px;
}
#nav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
#nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a;
position: relative;
}
#nav ul ul li a {
padding: 15px 40px;
color: #fff;
}
#nav ul ul li a:hover {
background: #4b545f;
}
#nav ul li a:hover {
background-color:#333;
}
#nav ul li a.active {
background-color:#333;
}
#nav ul li active {
background-color:red;
}
li.active {
float: right !important;
}
li.active_messages {
float: right;
}
#nav ul>li:hover>ul {
top:initial;
}
my html
<div id="nav">
<ul>
<li>Home</li>
<li>Categories
<ul>
<li>Photoshop</li>
<li>Illustrator</li>
<li>Web Design</li>
</ul>
</li>
<li>About us</li>
<li>Profile</li>
<li>My Listings</li>
<li>Get Verified!</li>
<li>Log out</li>
<li class="active">
<div id="searchbar">
<form action="search.php" method="get">
<input type="text" hidden="" value="product/search" name="route">
<input type="text" required="" placeholder="Search..." name="search">
<input type="submit" value="Search">
</form>
</div></li>
</ul>
</div>
it only bugs when its in full screen without ay sidebar stroller. thanks for the upcoming help.
Thank you for the upcoming help and support from everyone.
Without even looking at your code I can tell you why. The width of the dropdown is moving some margin to the right causing the search bar and probably anything else underneath the dropdown to move right.
Just make a <ul> list-style-type: none; with <li> display: inline or block;
Also you're not setting a width to anything but the search bar, which might be another cause.
Try setting a width to your nav.
Hey now just define some css as like this
#nav ul li {
position:relative;
}
#nav ul > li ul{
display:none;
}
#nav ul li:hover ul{
display:block;
}
Give max width for #nav and width 100%
#nav{
background: none repeat scroll 0 0 #585858;
border-radius: 3px;
height: 50px;
margin-bottom: 10px;
max-width: 858px;
padding: 0;
width: 100%;
}
so that it won't move anymore.
DEMO
why are you giving top:100%;
#nav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; display:none;
}
#nav ul>li:hover>ul {
display:block;
}
UPDATE : to keep a highlighted DEMO
#nav ul li:hover > a{
background-color:#333;
}
I have made a dropdown menu with rollover image. The rollover image almost works (Benedict Cumberbatch is meant to turn into an otter) and a submenu to drop down (which at the moment doesn't appear).
What have I done wrong? Here is the JSfiddle
The HTML >>
<ul id="nav">
<li><img src="http://static.tumblr.com/bw1wxme/Lgsmzv53i/rollover-1.jpg">
<ul>
<li>1.2.1.1. Sub-Level-3</li>
<li>1.2.1.2. Sub-Level-3</li>
<li>1.2.1.3. Sub-Level-3</li>
<li>1.2.1.4. Sub-Level-3</li>
</ul>
</li>
The CSS >>
#nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
opacity:1;
}
#nav li {
float: left; }
#nav li a {
display: block;
padding: 8px 15px;
text-decoration: none;
font-weight: bold;
color: #069;
}
#nav li a:hover {
color: #c00;
background-color: #fff;
}
#nav ul {
list-style-type:none;
display:none;
}
#nav .about:hover {background-image:url('http://static.tumblr.com/bw1wxme/RjMmzv543/rollover-2.jpg');}
You should add this to your css:
#nav li:hover ul {display:block;}
To show it when hover
Updated JsFiddle
I am working on a site for my brother's new plumbing company, and I am having two issues with my navigation menu. I copied some CSS from a tutorial site and tried altering it to my taste, but I can't figure out why this is happening. When I hover over the top-level menu item ("Services" in this case), the sub-menu appears as it should, but the background of the LI's extend outside of the screen. I have tried changing/setting widths on different areas of the CSS, but my limited knowledge has me scratching my head bald. I have a temporary site up, but I am testing this new version with Media Queries locally.
It won't let me post a screenshot without 10 reputation, so here is a link: http://www.sourceplumbing.com/Capture.png
The HTML:
<nav>
<ul>
<li>About Us</li>
<li>Services
<ul>
<li>Leak Detection</li>
<li>Water Heaters</li>
<li>Plumbing Fixtures</li>
</ul>
</li>
<li>Reviews</li>
<li>Contact Us</li>
</ul>
</nav>
The CSS:
nav ul li:hover > ul {
display: block;
}
nav ul {
width:100%;
height:auto;
min-width:550px;
background: -webkit-linear-gradient(#d5d5d5, #595959); /* For Safari */
background: -o-linear-gradient(#d5d5d5, #595959); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(#d5d5d5, #595959); /* For Firefox 3.6 to 15 */
background: linear-gradient(#d5d5d5, #595959); /* Standard syntax */
-webkit-border-radius: 25px;
-o-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
font-size: 16px;
font-family: "Times New Roman", Times, serif;
font-weight: bold;
text-align: center;
text-shadow: 2px 2px 2px #cccccc;
text-decoration:none;
list-style: none;
position: relative;
display: table;
}
nav a:link, a:visited {
text-decoration: none;
color: #000000;
padding: 8px 0px 8px 8px;
}
nav ul:after {
content: "";
clear:both;
display: block;
}
nav ul li {
display:inline-block;
width:auto;
}
nav ul li:hover a {
text-decoration:none;
color: #fff;
}
nav ul li a:link, a:visited {
display: block;
padding: 5px;
color:#000;
text-decoration: none;
}
nav ul ul {
background: #999;
border-radius: 0px;
padding: 0;
position: absolute;
width:150px;
}
nav ul ul li {
width:150px;
border-top: 1px solid #ccc;
position: relative;
display:block;
}
nav ul ul li a {
width:150px;
padding: 5px;
text-align:left;
color:#000;
display:block;
}
nav ul ul li a:hover {
color:#FFF;
}
I do have another issue, but if I can get this figured out, I will move onto that one next. I would appreciate any help you can offer!
What you are looking for is min-width: 550px;. This is causing ALL <ul> to expand to a min width of 550px.
Taking this out will fix the problem. I guess that was there for the nav to stop it getting to small, in that case you should be about to put that under nav and not nav ul.
DEMO HERE
Putting the min-width in the right place:
nav {
min-width: 550px;
}
DEMO HERE
I have a 100% wide DIV that contains a centered navigation menu and nothing else. The navigation menu is created using html lists and has some drop-down elements in it.
When you hover over a link in the navigation menu, the background color of that link changes, so naturally I don't want any visible top/bottom margins between the navigation menu and the DIV container - however, the menu is adding a 5px bottom margin which makes the design less attractive.
Here's what I'm having trouble with. I'm trying to use a responsive-design so the page can easily adapt between different browser resolutions, so I cannot specify an exact height for the DIV/nav bar. I need the DIV/nav bar's height to automatically adjust so it can contain the navigation elements for screens with smaller resolutions.
I can get the margin removed without the drop down menu, and I can get it to work without having the navigation centered, but I cannot get the margin removed while keeping the drop down menu and having it centered. Any help would be greatly appreciated.
JSFiddle http://jsfiddle.net/XJRHy/
HTML code:
<div class="navigation">
<nav>
<ul>
<li>One</li>
<li>Two
<ul>
<li>White</li>
<li>Red</li>
<li>Blue</li>
</ul>
</li>
<li>Four</li>
<li>Five</li>
</ul>
</nav>
</div>
CSS
.navigation {
width: 100%;
height:auto;
margin-left:auto;
margin-right:auto;
text-align:center;
background-color:#c0c0c0;
font-family: 'Open Sans', sans-serif;
}
nav {
text-align: center;
width:100%;
text-transform: uppercase;
font-size:1.375em;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
list-style: none;
position: relative;
display: inline-table;
margin:0;
padding:0;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float:left;
}
nav ul li:hover {
background: #4289a9;
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 10px 20px 10px 20px;
color: #000000; text-decoration: none;
font-weight:bold;
}
nav ul ul {
background: #5f6975; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
z-index:5000;
}
nav ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid #575f6a; position: relative;
z-index:5000;
}
nav ul ul li a {
padding: 10px 20px 10px 20px;
color: #fff;
z-index:5000;
}
nav ul ul li a:hover {
background: #4b545f;
z-index:5000;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
z-index:5000;
}
You can fix it as follows:
nav ul {
border: 1px solid blue; /* for demo only */
list-style: none;
position: relative;
display: inline-table;
margin:0;
padding:0;
vertical-align: top;
}
nav ul is an inline element with some white space below the base line.
Use vertical-align: top to remove it.
See Demo Fiddle