CSS :Background color on hover State - html

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;
}

Related

How do I make my link hover background fill the entire background?

I made a simple navigation menu using a ul, but when you hover over it, the background color will not change the entire background. I think it may have to do with my padding elements. How do I fix this?
Here is a Fiddle of my code: https://jsfiddle.net/b8js8zkq/
I have looked at How do I make the hover background color fill the height of the link? and did not find a good answer there, so please don't mark this as a duplicate of that.
The problem with your code is, you have margin and padding on both <h3> and <li>. So remove them and add them as padding to the <a> tag. And you are done!
The padding and margin of each 15px constitute 30px of total padding to <a>. That's what I have done below:
.header li {
border-bottom: 1px solid #888;
font-size: 20px;
padding: 0;
}
ul h3 {
margin: 0;
padding: 0
}
.header a {
display: block;
padding: 30px;
}
Fiddle: https://jsfiddle.net/19r4a4ft/
I'd recommend changing your css from this
.header a:hover{
background-color: #f3e5d8;
}
to this
.header li:hover{
background-color: #f3e5d8;
}
This will make it so any list item within your header class will change its background colour when hovered.
https://jsfiddle.net/b8js8zkq/1/
Fixed fiddle.
You remove the padding on both <h3> and <li>, and add that same padding to the <a>-tag.
jsfiddle update
Old
.header a:hover {
background-color: #f3e5d8;
}
New
.header li:hover {
background-color: #f3e5d8;
}
You want to change the color of the li element rather than just the a tag

Dropdownlist disappears when mouse moves over hover

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

Navigation Bar Icon and Padding CSS issues

Hi I have a few issues with my navigation bar on my website www.thehungryeurasian.com
1) I've added icons onto my navigation bar, and managed to position those on the right with the CSS below. I positioned the home icon on the left by giving it an ID, then inserting the CSS on the bottom line. But this has meant the tabs next to the home icon have been moved down. How do I fix it so it is within the bar?
.navleft {float:left; } .navright {float:right;} .tabs-inner .widget ul {margin-right: 0px; margin-left: 0px;}
.tabs-inner .widget ul, .tabs-inner .widget li a, .tabs-inner .section:first-child ul { background: none; }
#navigationbar {width: 1060px; height: 40px; background-color: #326609; background: $(tabs.background.color) $(tabs.background.gradient) repeat-x scroll 0 -800px; _background-image: none; position: fixed; top: 0px; margin-left: 0px; z-index: 999; }
.navright li a { padding: 0px !important; }
#homeiconButton { padding-top: 5px !important; padding-bottom: 0px !important; padding-right: 10px !important; padding-left:10px !important; }
2) After adding the icons and the CSS above, my navigation bar lost it's background colour and went clear. I had to add
background-color: #326609;
to override this. Is there something blocking my CSS for this that I need to remove?
3) last question!
I have white dividers in between my tabs. However, there seems to be padding in between them. How would I remove this? Also, is it possible to just have the dividers on the left side of my navigation bar and not on the right side?
Thank you in advance! I know it's a lot of questions.
Answer 1 - Add style "vertical-align : top" to all the navigation li items (you can exclude for home icon).
Answer 2 - Question is not very much clear to me. But I can see a background color in your navigation bar.
Answer 3 - Remove the style - float: none; from "#cssnav li" selector styles. You may be giving both border-left and right to the li as white. Remove border-left and just give border-right.
Hope this helps.

Changing the style of leftmost menu item

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;
}

Show different 'height' for links on hover over with CSS

I want to do this with CSS only. I have an unordered list and some hyperlinked list items and I want to limit the width and height of the links (list items) to width:300px and height:1.5em. So, no matter what the length of the links are, only up to 300px of the links will be showing and the rest will be hidden because of height limit and overflow:hidden. I want to show the rest of the link on mouse hover.
I can partially do this and hover over links shows the rest of the content BUT it also pushes down the content below it.
Is it possible, to show the rest of the content on mouseover WITHOUT pushing down the content below it?
Please see this fiddle 'http://jsfiddle.net/3VyaC/'
Looks a little clunky, but it's close to the effect you're shooting for. Only changed your CSS:
body {font-family: arial; font-size: 0.8em;}
.news-entry ul {
list-style-type: none;
padding: 0;
margin: 0 0 0 8px;
width: 300px;
}
.news-entry li {
border-top: 1px solid #dcdcdc;
width:300px;
height:1.5em;
overflow:hidden;
position:relative;
}
.news-entry li a.itemtitle {
display: block;
width: 100%;
padding: 4px 0 3px 0;
line-height: 1.5em;
text-decoration: none;
}
.news-entry li:hover {
color: #333;
background-color: #fafafa;
overflow:visible;
z-index:10;
}
.news-entry li:hover a{
position:absolute;
width:100%;
background-color:#fafafa;
border:1px solid #555;
}
Fiddle: http://jsfiddle.net/y3Vkt/
Might need to tweak the margins when the link changes to absolute position, there's a 1-2px glitch.
Hope this helps!
There would not be a way to do this. The only way you could actually do that is by setting position: absolute; but that would make the link sit on top of the next one. So to basically answer your question, there is not a way to do this with the width set as you have it.