Here is my Codepen demo which I want to show like image snap below the link:
Codepen Demo
Snap:
I used this css:
.menu > ul > li:first-child {
color: red !important;
}
To make left most link Red but still it shows Grey line.
Actually it should look like this:
Problem 2:
The length of the line above alert box should span to entire width of the page. How to do this?
I tried with chaging:
.menu > ul {
display: block;
list-style: none;
border-bottom: 0.1em solid #9e9e9e;
width: 152%; // makig it 200% increase width of entire page. Rather I want to increase the width of lie only
margin-left: -2%;
}
Try this
.menu > ul > li:first-child a {
color: red !important;
}
DEMO
Your code is fine, the only issue is that the a is getting overrid by the color from actual properties for the hyperlink as
a {
// properties..
}
Change the code to this:
.menu > ul > li:first-child a {
color: red !important;
}
Which will apply the settings to the hyperlink of the left most list item under the un ordered list in the element with class menu! :)
You forgot to add anchor selector at the end of:
.menu > ul > li:first-child a {
color: red !important;
}
Related
I have a blog over at wordpress.com and there is a problem with the dropdown box on my main navigation.
When the mouse is hovering over, it appears, but when you move out of it to click a link its goes.
Heres the blog: https://readingartlab.wordpress.com/
Dropdown menu for 'Workshops'. This problem occurs when I added margin-top: 11%; so that it would align with the rule beneath it.
Any help? Thanks in advance.
EDIT:
This is the CSS that has been changed:
.main-navigation ul ul {
padding: 8px 0;
margin-top: 11%;
}
So, the issue here is that there is a set amount of space devoted to your .menu-item -- when you hover over it, that triggers the submenu, but in order to move into the submenu, your mouse is actually leaving the space that triggers the hover effect. In Chrome Developer tools, when you click on the list item for Workshops in the HTML window, you see exactly how much space is around the list item:
Ideally, you'll reconfigure the CSS for that whole navigation area so there's more padding around the list item.
You can also try to trigger the focus class that the drop-down caret uses via jQuery, but that runs into some of the same problems and you end up either having to leave the submenu open until you click elsewhere or set it to remove on mouseleave of a larger parent element, like the header, which is pretty wonky.
You can't hover the margin of an element. Use padding or border instead to fill the gap between the parent en child element.
Have a look at this minimalistic demo on jsfiddle.
ul.menu > li {
display:inline-block;
padding:5px;
}
ul.menu > li > ul {
display:none;
border-top:5px solid $navigation-background-color;
margin:5px -5px -5px;
}
ul.menu > li:hover > ul {
display:block;
}
ul.menu > li > ul > li {
display:block;
padding:5px;
}
Add a little padding to the bottom of your parent menu item
.menu-item-has-children > a {padding-bottom: 10px; margin-bottom: -10px; }
If you target just those with a child item - .menu-item-has-children - it won't affect the other menu items. The negative margin-bottom offsets the expansion of the menu area that occurs with the adding of the padding-bottom. Using the > selector says, "Target the <a> elements that are a direct descendent just one level deep of the things with class menu-item-has-children." (So your extra padding won't affect the spacing / padding on your submenu.)
This is a great article about Child and Sibling Selectors in CSS - CSS Tricks: Child and Sibling Selectors
I hope these codes will solve the issue.
.site-header {
border: 0;
padding-bottom: 0;
}
.search-navigation {
border-top: 0;
margin-bottom: 0;
}
#media screen and (min-width: 960px) {
.search-navigation {
margin-top: 30px;
padding-top: 0;
border-top: 1px solid #cecece;
border-bottom: 1px solid #cecece;
}
}
.main-navigation li {
padding: 15px 0;
border: 0 !important;
}
#media screen and (min-width: 960px) {
.main-navigation .menu-item-has-children {
padding-right: 0;
}
}
.main-navigation .menu-item-has-children > a {
padding-right: 38.5px;
}
.main-navigation a {
display: block;
padding: 0 15px;
border-right: 1px solid #e0e0e0;
}
.main-navigation>div>ul>li:last-child a {
border: 0;
}
It was happening because there was a gap between submenu and < li > which you are using for triggering hover.visual
i am having left navigation in my web page See the attached pic to get better idea of what i have in design
as shown in pic i have 15px padding on both sides of navigation but problem is that when i hover over any of element in navigation its background color should be set to dark grey to the full width means 15 px padding on both sides must be eliminated on hover state and background color
i really cant get how to solve this problem on hover state i can add this
.nav > li > a:hover { background-color: #f18c2e;
}
but how do i show it full width background color as per given Pic ?
You can set the box-shadow to cover the left and right side (15px offset):
nav li:hover {
background:gray;
cursor:default;
box-shadow: 15px 0 0 gray, -15px 0 0 gray;
}
Demo.
Try something like this: http://jsbin.com/vebopu/2/
Considering the following CSS:
/* Your 15px padding */
.nav > li {
padding: 15px;
}
/* Where you set the initial stuff */
.nav > li > a {
background-color: #111;
color: #fff;
display:inline-block;
}
/* You want to remove the padding on li hover */
.nav > li:hover {
padding: 0;
}
/* But you still want the resulting size to keep the padding */
.nav > li:hover a {
background-color: #f00;
padding: 15px;
}
My problem is that I've got a div at the top of my site that has a dropdown menu with a float to the left, the thing is that under that div where I want to have a header whenever I hover over the menu the header floats to the left as well.
I tried to do a clear div after the top div then on css use clear:both; but it didn't really help
Here's the JSfiddle:
http://jsfiddle.net/Safushi/XRNP5/
ul {
font-size: 16px;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
padding: 5px 15px 5px 15px;
background: #464646;
white-space: nowrap;
}
ul li a:hover {
background: #565656;
}
is some of the code for the menu (had to paste some code to be able to paste JSfiddle link).
It will be fixed by adding a
position: absolute;
to the ul that contains the submenu.
The child ul element needs to be absolutely positioned if you don't want it to effect the other elements.
Example Here
#top li > ul {
position:absolute;
width:100%;
}
And as Adrift mentions, you may also want to give the ul a width of 100%.
You got the layer of HTML file right,but the property "position" wrong.
Demo
Once a tag's settled position:absolute; ,it will only be positioned referring to its containing block.So you need to set #menu{postion:relative;} to let its parent-tag be the containing block.In fact,now the submenu is totally deleted from the normal flow,so it won't affect the styles of other tags.
Moreover,I highly recommend you to resist to use descendant selectors,which not only let your browser slower,and your code maintenance much more complex as well.
For a website I need to make a css/html menu like this:
As you can see there some yellow borders to the left and also to the right of the menu links that fill up the availabe width. Also there is a background image underneath the menu with a gradient in it.
Does somebody has any idee on how to achive this menu style?
Code so far:
<div id="submenu">
<ul>
<li class="selected">
Wirtschaft<div></div>
<ul>
<li>Kurzeinführung Wirtschaft</li>
<li>Wirtschaftstheorie</li>
<li>Arbeitsmarkt</li>
<li class="selected">Geld- und Konjunktur</li>
<li>Staatsfinanzen</li>
<li>Wirtschaft: alle Beiträge</li>
</ul>
</li>
</ul>
</div>
#submenu {
width: 225px;
}
#submenu ul {
list-style-type: none;
}
#submenu ul li a {
border-left: 6px solid transparent;
padding-left: 4px;
display: block;
margin-bottom: 15px;
color: #222624;
font-size: 17px;
}
#submenu ul li a:hover,
#submenu ul li.selected > a {
border-left: 6px solid #CAB106;
}
#submenu ul li ul li a {
margin-bottom: 7px;
font-size: 14px;
}
EDIT: the gradient in the picture actually resides in the body and i think it can not be done with pure css so it has to be a background image.
EDIT2: the solution provided by PeterVR works great! unfortunately i am stuck with another list with the same style but without the blocks ending complete when the ul ends. any idea on how to achive this with the code provided by PeterVR?
something like this perhaps: http://jsfiddle.net/AXze7/1/
I changed a few thing in your css:
- set the main ul to overflow hidden
- removed the display block from your <a> tags
- set the <a> tags to position relative, for the following to work:
#submenu ul li a:hover:after,
#submenu ul li.selected > a:after {
background: #CAB106;
content: ' ';
display: block;
height: 100%;
width: 225px;
margin-left: 4px;
position: absolute;
left: 100%;
top: 0;
}
This adds the green blocks after the anchor tags.
EDIT:
I updated my fiddle for your second case: http://jsfiddle.net/AXze7/2/
A short overview of what changed:
I removed the overflow:hidden from the ul, and put it on the li
I tweaked the styling and played with the pixels to make it look a bit more like your screenshot. Comparing this with the previous example should help you understand how to achieve what.
I added an extra pseudo-class :before for the arrow icon that appears to change on hover/select.
The code looks like this:
#submenu ul li a:before,
#submenu ul li.selected > a:before {
background: #fcc; /* put your black arrow image here */
content: ' ';
display: block;
height: 12px;
width: 12px;
margin-left: 2px;
position: absolute;
left: -18px;
top: 2px;
}
#submenu ul li a:hover:before,
#submenu ul li.selected > a:before {
background: red; /* put your colored arraw image here */
}
check this demo in js fiddle.make an image one pixel height with the grenadine shown on the picture , and replace #eee with that image.
I am creating a dropdown menu for a Wordpress template and I want the main menuitem to have the same color the subitems have when they are hovered. I found many similar questions here on stack overflow and tried their solutions but they don't seem to work in my case.
I think the solution must be:
parent:hover child { ... }
and it works for example here.
I tried to do the same with my code (please see last CSS selector) but it doesn't work here.
Update your CSS from:
#menu ul li a:hover {
background-color: #006699;
color: #FFFFFF;
}
To
#menu ul li:hover a {
background-color: #006699;
}
#menu ul li a:hover {
color: #FFFFFF;
}
Updated example on jsFiddle.
You can get the effect you'd like by replacing the last CSS declaration in your fiddle with this:
.menu ul li:hover > a {
background-color: #006699;
color: #fff !important;
}