Background color on hover & padding - html

I'm having trouble with having a background color on hover, on a logo and also padding around some images.
For the background-color, it's for the logo that you see on the navigation bar on the left that is CAUL/CBUA. Its' hover state switches to this image and the background on hover should fill the whole block just like the links beside it.
For the padding of the images, it's on the same navigation bar, to the right. They are the social icons I'm sure it's not hard to see where the padding should be.
Here's the link to what I have so far. You can see the navigation bar here.
And here's my CSS:
/* Navigation bar */
#navi {
height: 40px;
background: #1e416f;
font-size: 14px;
color: white;
text-transform: uppercase;
margin: 0 0 20px 0;
}
#navi a:hover {
background: white;
color: #1e416f;
}
.logo {
margin: 5px;
padding: 0;
float: left;
}
.logo a {
float: left;
margin: 2px 10px;
width: 36px;
height: 26px;
background: url(/imgs/navi/caul_white_nav.png) left top no-repeat;
text-indent: -9999px;
}
.logo a:hover {
background: url(/imgs/navi-hover/caul_blue_nav.png) left top no-repeat;
}
#primary-nav, #tools-nav {
list-style: none;
margin: 0;
padding: 0;
}
#primary-nav li, #primary-nav a,
#tools-nav li, #tools-nav a { float: left; }
#primary-nav a, #tools-nav a {
color: white;
text-decoration: none;
padding: 0 10px;
border-right: 1px solid white;
line-height: 40px;
}
#primary-nav li:first-child a, #tools-nav li:first-child a {
border-left: 1px solid white;
}
#tools-nav {
float: right;
}
#tools-nav .icon a {
text-indent: -9999px;
}
#tools-nav .email a {
background: url(/imgs/navi/mail.png) no-repeat;
width: 20px;
}
#tools-nav .email a:hover {
background: url(/imgs/navi-hover/hover_mail.png) no-repeat;
width: 20px;
}
#tools-nav .twitter a {
background: url(/imgs/navi/twitter.png) no-repeat;
width: 20px;
}
#tools-nav .twitter a:hover {
background: url(/imgs/navi-hover/hover-twitter.png) no-repeat;
width: 20px;
}
#tools-nav .search a {
background: url(/imgs/navi/search.png) no-repeat;
width: 20px;
}
#tools-nav .search a:hover {
background: url(/imgs/navi-hover/hover_search.png) no-repeat;
width: 20px;
}
HTML:
<!-- NAVIGATION -->
<div id="navi">
<h1 class="logo">CAUL/CBUA</h1>
<ul id="primary-nav">
<li>Directories</li>
<li>Committees</li>
<li>Resources</li>
<li>About</li>
</ul>
<ul id="tools-nav">
<li class="login">Log In</li>
<li class="email icon">Email</li>
<li class="twitter icon">Twitter</li>
<li class="search icon">Search</li>
</ul>
</div>

May be this will help someone:
.menuItem:hover
and
.menuItem :hover
is not the same, take care!

try this method on active and hover. (background position center center).
#tools-nav .email a {
background: url("/imgs/navi/mail.png") no-repeat scroll center center transparent;
width: 20px;
}

Try this:
#navi.logo {
margin: 5px;
padding: 0;
float: left;
}
#navi .logo a {
float: left;
margin: 2px 10px;
width: 36px;
height: 26px;
background: url(/imgs/navi/caul_white_nav.png) left top no-repeat;
text-indent: -9999px;
}
#navi .logo a:hover {
background: url(/imgs/navi-hover/caul_blue_nav.png) left top no-repeat;
}

Your selector are being overwritten do to CSS Selector scope/order. The more specific overwrites those that are more general, in this case, #navi a:hover is overwriting, .logo a:hover making your hover affect not work. the property you are overwriting is background change it to background-color: white; and you'll be fine

Related

White box within banner image

I am trying to add a border-top with 2px on my fixed navbar however on the a href hover it pushes all of the nav items down by 2px, I am trying to make it so it's static, any help is appreciated.
.fixed-nav-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 9999;
width: 100%;
height: 70px;
background-color: #3f3f3f;
}
.fixed-nav-bar li, .fixed-nav-bar a {
height: 0 auto;
line-height: 50px;
width: 100px;
overflow: hidden;
}
.menu {
width: 90%;
max-width: 960px;
margin: 0 auto;
text-align: center;
}
.menu a, .menu a:visited {
color: #ffffff;
overflow: hidden;
}
.menu a:hover, .menu a:target {
display: block;
border-top: 2px solid #72BCD4;
color: #72BCD4;
}
.menu-items { display: inline-block; }
.menu-items li {
display: inline-block;
margin-right: 10px;
margin-left: 10px;
}
.menu-items a {
text-decoration: none;
}
.show, .hide {
display: none;
padding-left: 15px;
background-color: transparent;
background-repeat: no-repeat;
background-position: center left;
color: #dde1e2;
}
.show {
background-image: url(../assets/down-arrow-icon.png);
}
.hide {
background-image: url(../assets/up-arrow-icon.png);
}
<nav class="fixed-nav-bar">
<div id="menu" class="menu">
<!-- Example responsive navigation menu -->
<a class="show" href="#menu">Menu</a><a class="hide" href="#hidemenu">Menu</a>
<ul class="menu-items">
<li>HOME</li>
<li>ABOUT</li>
<li>DESIGNS</li>
<li>CONTACT</li>
</ul>
</div>
</nav>
It's because of no border. Either give a transparent border with the same width or use the colour of the border. But in your case, it's screwed up. So I changed the overflow: hidden and used margin-top: -2px:
.fixed-nav-bar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 9999;
width: 100%;
height: 70px;
background-color: #3f3f3f;
}
.fixed-nav-bar li, .fixed-nav-bar a {
height: 0 auto;
line-height: 50px;
width: 100px;
}
.menu {
width: 90%;
max-width: 960px;
margin: 0 auto;
text-align: center;
}
.menu a, .menu a:visited {
color: #ffffff;
}
.menu a:hover, .menu a:target {
display: block;
border-top: 2px solid #72BCD4;
color: #72BCD4;
margin-top: -2px;
}
.menu-items {
display: inline-block;
}
.menu-items li {
display: inline-block;
margin-right: 10px;
margin-left: 10px;
}
.menu-items a {
text-decoration: none;
}
.show, .hide {
display: none;
padding-left: 15px;
background-color: transparent;
background-repeat: no-repeat;
background-position: center left;
color: #dde1e2;
}
.show {
background-image: url(../assets/down-arrow-icon.png);
}
.hide {
background-image: url(../assets/up-arrow-icon.png);
}
<nav class="fixed-nav-bar">
<div id="menu" class="menu">
<!-- Example responsive navigation menu -->
<a class="show" href="#menu">Menu</a><a class="hide" href="#hidemenu">Menu</a>
<ul class="menu-items">
<li>HOME</li>
<li>ABOUT</li>
<li>DESIGNS</li>
<li>CONTACT</li>
</ul>
</div>
</nav>
That's all because of box-sizing property. by default it adds value of paddings/margins/borders outside of content area, so element becomes bigger. Just define globally * {box-sizing: border-box;} it will make elements to fixed sizes. That means if element had no border, and then it adds, the element's area for content will be smaller, but the whole size will be the same. However, I strongly recommend you to use border at the beginning, otherwise, it will jump inside the element. You can set the color 'transparent' and it won't be visible. Then just by changing border-color it will be nicer.
I have created a little fiddler:
https://jsfiddle.net/marco_rensch/0hva2241/
this could be a possible solution
checkout CSS Code Changes between row 31 and 51
the key is to add a default border 2px transparent to the li's and change it by hover:
.menu-items li:hover{border-top: 2px solid #72BCD4;}

Menu - Style ul / li to be width depend on text lenght

i am trying to style my menu. I had a working code but notied that parent div is smaller then child div. I am pretty sure its not right so i try to edit it a bit but now i have a problem with it. It looks like:
As you can see last part of menu "FLASHOVKY" is on another line, and all li is same width dispite the fact text is different lenght.
CSS:
#menu {
background-image: url('images/menubg.png');
background-repeat: repeat-x;
height: 44px;
width: 983px;
font-family: Arial;
margin-left: 22px;
}
#menu ul{
list-style: none;
margin: 0;
padding: 0;
}
#menu ul li {
color: #f7f7f7;
height: 44px;
display: inline-block;
min-width: 100px;
}
#menu ul li a {
background-image: url('images/menu_spacer.png');
background-repeat: no-repeat;
background-position: top right;
color: #f7f7f7;
float: left;
padding: 14px 15px; /* Disadvantage: you will have to adjust this padding MANUALLY */
text-decoration: none;
text-align: center;
min-width: 85px;
}
#menu ul li:last-child a {
background: none;
}
#menu ul li a:after {
background-image: url('images/sipka.png');
content: '';
width: 10px;
height: 8px;
margin-left: 8px;
display: inline-block;
}
HTML:
<nav id="menu">
<ul>
<li>GAMESITES</li>
<li>HRY</li>
<li>SERVERY</li>
<li>CLANKY</li>
<li>FORUM</li>
<li>DOWNLOADS</li>
<li>BLOGY</li>
<li>FLASHOVKY</li>
</ul>
</nav>
Can somebody help me with that guys?
p.s. Live demo : http://funedit.com/andurit/try11/
1] You can fix this by setting box-sizing:border-box;. The issue is the padding on your <a> tags, it's causing the content to overflow because the padding and border are placed outside of the content box.
2] To fix the spacing issue, you need to add a float: left; to #menu ul li. The reason for this is because the <a> tags nested in #menu ul li are floated left. That's why the links were offset.
Change this:
#menu ul li {
color: #f7f7f7;
height: 44px;
display: inline-block;
min-width: 100px;
}
#menu ul li a {
background-image: url('images/menu_spacer.png');
background-repeat: no-repeat;
background-position: top right;
color: #f7f7f7;
float: left;
padding: 14px 15px; /* Disadvantage: you will have to adjust this padding MANUALLY */
text-decoration: none;
text-align: center;
min-width: 85px;
}
To this:
#menu ul li {
color: #f7f7f7;
height: 44px;
display: inline-block;
min-width: 100px;
float:left; /* Add this float to remove extra space */
}
#menu ul li a {
-webkit-box-sizing: border-box; /* Safari, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
background-image: url('images/menu_spacer.png');
background-repeat: no-repeat;
background-position: top right;
color: #f7f7f7;
float: left;
padding: 14px 15px; /* Disadvantage: you will have to adjust this padding MANUALLY */
text-decoration: none;
text-align: center;
min-width: 85px;
}
Try playing around with the min-width values in your css.
#menu {
background-image: url('images/menubg.png');
background-repeat: repeat-x;
height: 44px;
width: 983px;
font-family: Arial;
margin-left: 22px;
}
#menu ul{
list-style: none;
margin: 0;
padding: 0;
}
#menu ul li {
color: #f7f7f7;
height: 44px;
display: inline-block;
min-width: 100px; // this property causing you to make all box of same size and it occupie the 100px wether text is small or large
}
#menu ul li a {
background-image: url('images/menu_spacer.png');
background-repeat: no-repeat;
background-position: top right;
color: #f7f7f7;
float: left;
padding: 14px 15px; /* Disadvantage: you will have to adjust this padding MANUALLY */
text-decoration: none;
text-align: center;
min-width: 85px; // dont fix width
}
#menu ul li:last-child a {
background: none;
}
#menu ul li a:after {
background-image: url('images/sipka.png');
content: '';
width: 10px;
height: 8px;
margin-left: 8px;
display: inline-block;
}
Use float:left instead of display block..and only use height if you need..yes inline and float:left has for different use..but may be you will like..
#menu {
background-image: url('images/menubg.png');
background-repeat: repeat-x;
height: 44px;
width: 983px;
font-family: Arial;
border:1px solid;
margin-left: 22px;
}
#menu ul{
list-style: none;
margin: 0;
padding: 0;
width:100%;
}
#menu ul li {
color: #000;
height: 44px;
float:left;
min-width: 100px;
}
#menu ul li a {
background-image: url('images/menu_spacer.png');
background-repeat: no-repeat;
background-position: top right;
color: #000;
float: left;
padding: 14px 15px; /* Disadvantage: you will have to adjust this padding MANUALLY */
text-decoration: none;
text-align: center;
min-width: 85px;
}
#menu ul li:last-child a {
background: none;
}
#menu ul li a:after {
background-image: url('images/sipka.png');
content: '';
width: 10px;
margin-left: 8px;
display: block;
}

HTML/CSS - How to make text-overflow in line with each other?

I have a vertical menu and some overflowing text and i'd like to make the text inline with each other. How would i do this?
For example:
http://i754.photobucket.com/albums/xx182/rache_R/text_zpsbd15aa0d.png
HTML:
<div id="sideMenu">
<ul class="top-level">
<li>Back</li>
<li>Accessories & Merchandise</li>
<li>Accident & Roadside Assistance</li>
<li>Customer Relations</li>
<li>E10 Petrol Compatibility</li>
<li>Insurance</li>
<li>Quality & Safety Actions</li>
<li>Shop</li>
<li>Servicing & Maintenance</li>
<li>Servicing Offers</li>
<li>Warranty</li>
</ul>
</div>
CSS:
#sideMenu {
font-size: 11px;
width: 185px;
padding-top: 35px;
padding-left: 15px;
}
#sideMenu ul {
margin: 0;
padding: 0;
}
#sideMenu li {
list-style: none;
padding: 9px;
padding-left: 25px;
}
ul.top-level {
background: #eceeef;
}
ul.top-level li {
border-bottom: 1px solid #FFF;
border-top: 1px solid #FFF;
}
#sideMenu a {
color: #000;
curser: pointer;
display: block;
height: auto;
text-indent: 10px;
text-decoration: none;
width: 100%;
background-image: url(leftMenuArrowBlack.gif);
background-repeat: no-repeat;
background-position: left;
padding-left: 0px;
}
#sideMenu a:hover {
}
#sideMenu li:hover {
background: #fac026;
position: relative;
}
Is this what you want..
Then make your width 200px for #slidemenu..
you can specify text-align:left/right/center in your css to align the text in the vertical menu
Update
you can remove the text-indent and padding-left on the li item and just add text-align:left
#sideMenu a {
color: #000;
curser: pointer;
display: block;
height: auto;
text-align: left;
text-decoration: none;
width: 100%;
background-image: url(leftMenuArrowBlack.gif);
background-repeat: no-repeat;
background-position: left;
padding-left: 0px;
}
checkout the jsfiddle http://jsfiddle.net/8U2H5/1/

hover effect on navigation menu - border issue

I need to create a menu same as this image
My problem is the hover state where i need to change the vertical image on both sides.
So far i've come to this point: http://jsfiddle.net/cgEab/
How can i change both left and right images on hover state?
The code for css is
#topmenu{
float: right;
position: relative;
}
ul#topnav {
right: 0px;
margin: 0;
padding: 0;
list-style: none;
font-size: 1em;
background-color: #ccc;
}
ul#topnav li {
float: left;
margin: 0; padding: 0;
}
ul#topnav li a {
padding: 10px 22px;
display: block;
color: #777777;
text-decoration: none;
background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
background-position: right;
background-repeat: no-repeat;
display: block;
}
ul#topnav li a.lastitem {
background-image:none;
}
ul#topnav li a:hover {
color: red;
background-image: url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg');
}
and the html
<link href='http://fonts.googleapis.com/css?family=Dosis:400,700' rel='stylesheet' type='text/css'>
<div id="topmenu">
<ul id="topnav">
<li>HOME</li>
<li>SERVICES</li>
<li>CUSTOMERS</li>
<li>ABOUT US</li>
<li><a class="lastitem" href="#">CONTACT</a></li>
</ul>
I changed the border image to double on both sides and subtracted the margin to correct for position.
http://jsfiddle.net/Q3pQx/
ul#topnav li a {
margin-left:-2px; <-- FIX
padding: 10px 22px;
display: block;
color: #777777;
text-decoration: none;
background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
background-position: right;
background-repeat: no-repeat;
display: block; /* make the link background clickable */
}
ul#topnav li a:hover {
color: red;
background: url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg'), url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg'); <-- FIX
background-position: left top, right top; <-- FIX
background-repeat: no-repeat, no-repeat; <-- FIX
}
Edited the fiddle made some fine tuning http://jsfiddle.net/LhFkf/
'background-image' can take more than one image. So you could try something like this:
background-image: url(...), url(...);
background-position: left, right;
may i sure try this
http://jsfiddle.net/cgEab/7/
CSS
#topmenu{
float: right;
position: relative;
}
ul#topnav {
/* position: absolute;*/
right: 0px;
margin: 0;
padding: 0;
/*width: 640px;*/
list-style: none;
font-size: 1em;
background-color: #ccc;
}
ul#topnav li {
float: left;
margin: 0; padding: 0;
/*border-right: 1px solid #555;*/
}
ul#topnav li a {
padding: 10px 22px;
display: block;
margin-left:-2px;
color: #777777;
text-decoration: none;
background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
background-position: right;
background-repeat: no-repeat;
display: block; /* make the link background clickable */
}
ul#topnav li a.lastitem {
background-image:none;
}
ul#topnav li a:hover {
color: red;
background: url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg'), url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg');
background-position: left top, right top;
background-repeat: no-repeat, no-repeat;
}
I've put the image to the li, before it was on the li a.
This is a css3 hack. I hope you don't have to use IE lower than 8.
#topmenu{
float: right;
position: relative;
}
ul#topnav {
/* position: absolute;*/
right: 0px;
margin: 0;
padding: 0;
/*width: 640px;*/
list-style: none;
font-size: 1em;
background-color: #ccc;
}
ul#topnav li {
float: left;
margin: 0; padding: 0;
background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
background-position: left;
background-repeat: no-repeat;
}
ul#topnav li:hover,
ul#topnav li:hover + li {
background-image: url('http://s11.postimg.org/xch0azru7/menu_bar_vertical_hover.jpg')
/*border-right: 1px solid #555;*/
}
ul#topnav li a {
padding: 10px 22px;
display: block;
color: #777777;
text-decoration: none;
/*background-image: url('http://s11.postimg.org/az4oag1in/menu_bar_vertical.jpg');
background-position: left;
background-repeat: no-repeat;*/
display: block; /* make the link background clickable */
}
ul#topnav li:first-child {
background-image:none;
}
ul#topnav li a:hover{
color: red;
}
Fiddle

Trying to find why these floated LIs don't align in IE7

Here is the page in question: [redacted]
The menu looks great in Firefox, Safari, Chrome, and IE8+. But in IE7, the LIs are stacked vertically. You can download IETester if you don't already have it to see what I mean.
Here's my HTML:
<ul id="menu">
<li class="you">You</li>
<li class="us">Us</li>
<li class="contact">Contact</li>
<li class="insurance">Insurance</li>
<li class="services">Services</li>
<li class="blog">Blog</li>
</ul>
And the corresponding CSS:
#header #menu {
position: absolute;
bottom: 40px;
right: 22px;
float: right;
}
#menu,
#menu li {
list-style-type: none;
padding: 0;
margin: 0;
}
#menu li {
float: left;
}
#menu a {
display: block;
float: right;
width: 76px;
height: 25px;
padding: 45px 0 5px 0;
text-align: center;
text-decoration: none;
color: #555;
font-size: 90%;
border: 1px solid #fff;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
#menu .you a {
background: url(img/icon_you.gif) center 9px no-repeat;
}
#menu .blog a {
background: url(img/icon_blog.gif) center 9px no-repeat;
}
#menu .us a {
background: url(img/icon_us.gif) center 9px no-repeat;
}
#menu .insurance a {
background: url(img/icon_insurance.gif) center 9px no-repeat;
}
#menu .contact a {
background: url(img/icon_contact.gif) center 9px no-repeat;
}
#menu .services a {
background: url(img/icon_services.gif) center 9px no-repeat;
}
#menu a:hover {
background-color: #f6f5f3;
border: 1px solid #e5e2dd;
color: #2871ad;
}
Any insights greatly appreciated.
Define a width for each li element.
Don't float your A-tags. You're already floating the LI wrapper. Also, don't forget to clear your floats at the end of your list.