hover effect on navigation menu - border issue - html

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

Related

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

Center links in <li> menu vertically

I have this menu:
<div id="menu">
<ul>
<li>Home</li>
<li>Programm & Preise</li>
<li>Künstler</li>
<li>Rückblick</li>
<li>Team</li>
</ul>
</div> <!-- end of menu -->
And this is the css I have at the moment:
/* menu */
#menu {
clear: both;
width: 670px;
height: 64px;
background: url(images/menu_yellow.png) no-repeat bottom;
}
#menu ul {
margin: 0;
padding: 0;
list-style: none;
}
#menu ul li {
padding: 0;
margin: 0;
display: inline;
}
#menu ul li a{
float: left;
display: block;
width: 94px;
height: 55px;
padding: 7px 0 0 0;
margin-right: 5px;
text-align: center;
font-size: 13px;
text-decoration: none;
color: #000;
font-weight: normal;
outline: none;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
opacity: .7;
}
#menu li a:hover, #menu li .current{
color: #C30;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
opacity: 1;
}
The links are centered horizontally, but is it also possible to center it vertically inside the <li> that contain them?
I read about vertical-align: middle ; but just adding it to the links does not work.
Here is a fiddle: http://jsfiddle.net/gkpfL/
You are using float: left; so you won't need display: block;
So first, you don't need display: block; as when you float, even inline elements become floated blocks, as far as the vertical centering goes, instead of using float, use display: table-cell; along with vertical-align: middle;
Demo
#menu ul li a{
display: table-cell; /* Add this */
vertical-align: middle; /* Add this */
width: 94px;
height: 55px;
padding-bottom: 5px;
/* Use this for a spare bottom space for your background-image */
/* Rest of the properties goes here */
}
Also use display: inline-block; for the li element instead of display: inline; with vertical-align: top; (Not required but better to be safe than sorry)
#menu ul li {
padding: 0;
margin: 0;
display: inline-block;
vertical-align: top;
}
You can align them in the middle, but the arrow make them align lower than it should..you have to adjust it a little bit but it's something like:
#menu {
clear: both;
width: 670px;
height: 64px;
background: url(images/menu_yellow.png) no-repeat bottom;
}
#menu ul {
margin: 0;
padding: 0;
list-style: none;
}
#menu ul li {
padding: 0;
margin: 0;
float: left;
display: table;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
width: 94px;
height: 60px;
}
#menu ul li a{
display: table-cell;
vertical-align:middle;
margin-right: 5px;
text-align: center;
font-size: 13px;
text-decoration: none;
color: #000;
font-weight: normal;
outline: none;
opacity: .7;
}
#menu li a:hover, #menu li .current{
color: #C30;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
opacity: 1;
}
http://jsfiddle.net/gkpfL/8/
http://jsfiddle.net/gkpfL/7/
changed the li to display:inline-block;
removed float:left; and added display:table-cell; and vertical-align:middle;
#menu ul li {
padding: 0;
margin: 0;
display: inline-block;
}
#menu ul li a{
width: 94px;
height: 62px;
margin-right: 5px;
text-align: center;
font-size: 13px;
text-decoration: none;
color: #000;
font-weight: normal;
outline: none;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
opacity: .7;
display:table-cell;
vertical-align:middle;
}
DEMO
/* menu */
#menu {
clear: both;
width: 670px;
height: 64px;
background: url(images/menu_yellow.png) no-repeat bottom;
}
#menu ul {
margin: 0;
padding: 0;
list-style: none;
}
#menu ul li {
padding: 0;
margin: 0;
display: inline-block;
}
#menu ul li a {
display: table-cell;
vertical-align: middle;
width: 94px;
height: 55px;
margin-right: 5px;
text-align: center;
font-size: 13px;
text-decoration: none;
color: #000;
font-weight: normal;
outline: none;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
opacity: .7;
}
#menu li a:hover, #menu li .current {
color: #C30;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
opacity: 1;
}
vertical-align
The vertical-align property affects the vertical positioning inside a line box of the boxes generated by an inline-level element.
An easy attemp would be to just replace the height with some padding
#menu ul li a{
padding: 27.5px 0px;
height: auto;
}
vertical-align works for inline/inline-block elements. Also you can center Content in Table cells with it. But it was not designed to center content liked this.
Try the following CSS:
#menu {
clear: both;
width: 670px;
height: 64px;
background: url(images/menu_yellow.png) no-repeat bottom;
}
#menu ul {
margin: 0;
padding: 0;
list-style: none;
}
#menu ul li {
padding: 0;
margin: 0;
display: table-cell;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
vertical-align:middle;
height: 60px;
}
#menu ul li a{
float: left;
display: table-cell;
width: 94px;
padding: 7px 0 0 0;
margin-right: 5px;
text-align: center;
font-size: 13px;
text-decoration: none;
color: #000;
font-weight: normal;
outline: none;
opacity: .7;
margin-bottom: 18px;
}
#menu lihover, #menu li.current{
color: #C30;
background: url(http://i.imgur.com/JYsyCl6.png) repeat;
opacity: 1;
}
Also you could think about creating the pointer with CSS using :after pseudo element

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/

Background color on hover & padding

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

drop down menu css

I have a menu with html and css horizantal and I want to add a vertical menu only for the last element of the menu "parameters"
here is the html code :
<div id="templatemo_menu">
<ul>
<li><span class="home">Acceuil</span></li>
<li><span class="commandes">Commandes</span></li>
<li><span class="users">Utilisateurs</span></li>
<li><span class="gallery">Message</span></li>
<li><span class="contact">Messages</span></li>
<li>
<span class="contact2">Paramétres</span>
<ul class="sousmenu">
<li>CSS</li>
<li>Graphic design</li>
<li>Development tools</li>
<li>Web design</li>
</ul>
</li>
</ul>
</div>
and here is the css code :
#templatemo_menu {
width: 980px;
height: 110px;
margin: 0 auto;
background: url(images/templatemo_menu.jpg) repeat-x;
}
#templatemo_menu ul {
margin: 0;
padding: 1px 40px 0 40px;
list-style: none;
}
#templatemo_menu ul li {
padding: 0px;
margin: 0px;
display: inline;
}
#templatemo_menu ul li a {
float: left;
display: block;
width: 120px;
height: 95px;
padding: 15px 0 0 0;
margin-right: 5px;
text-align: center;
font-size: 16px;
text-decoration: none;
color: #163142;
font-weight: bold;
outline: none;
background: url(images/templatemo_menu_item.jpg) no-repeat;
}
#templatemo_menu li a:hover, #templatemo_menu li .current {
color: #000000;
background: url(images/templatemo_menu_hover.jpg) no-repeat;
}
#templatemo_menu ul li a .home {
display: block;
height: 20px;
padding: 55px 0 0 0;
background: url(images/home_48.png) no-repeat center top;
}
#templatemo_menu ul li a .aboutus {
display: block;
height: 20px;
padding: 55px 0 0 0;
background: url(images/new_order2.png) no-repeat center top;
}
#templatemo_menu ul li a .commandes {
display: block;
height: 20px;
padding: 55px 0 0 0;
background: url(images/commandes_v1.png) no-repeat center top;
}
#templatemo_menu ul li a .users {
display: block;
height: 20px;
padding: 55px 0 0 0;
background: url(images/user.png) no-repeat center top;
}
#templatemo_menu ul li a .services {
display: block;
height: 20px;
padding: 55px 0 0 0;
background: url(images/historiqueCommandes2.png) no-repeat center top;
}
#templatemo_menu ul li a .news {
display: block;
height: 20px;
padding: 55px 0 0 0;
background: url(images/newspaper_48.png) no-repeat center top;
}
#templatemo_menu ul li a .gallery {
display: block;
height: 20px;
padding: 55px 0 0 0;
background: url(images/newMessage.png) no-repeat center top;
}
#templatemo_menu ul li a .contact {
display: block;
height: 20px;
padding: 55px 0 0 0;
background: url(images/mail_48.png) no-repeat center top;
}
(it seems a bit long because I made ​​a template of the website)
so I tried this code css (a drop-down menu) but it not work, I tried to add and delete attributes but no result:
#templatemo_menu .sousMenu
{
display: none;
list-style-type: none;
margin: 0;
padding: 0;
border: 0;
}
#templatemo_menu .sousMenu li
{
float: none;
margin: 0;
padding: 0;
border: 0;
width: 149px;
border-top: 1px solid transparent;
border-right: 1px solid transparent;
}
#templatemo_menu .sousMenu li a:link, #menuDeroulant .sousMenu li a:visited
{
display: block;
color: #FFF;
margin: 0;
border: 0;
text-decoration: none;
background: transparent url("fondTR.png") repeat;
}
#templatemo_menu .sousMenu li a:hover
{
background-image: none;
background-color: #F2462E;
}
#templatemo_menu li:hover > .sousMenu { display: block; }
do you have any idea,thanks
Either in your HTML replace <ul class="sousmenu"> with <ul class="sousMenu">
OR
In your css change .sousmenu with .sousMenu (Everywhere).
Do what you like, but make them equal in cases. And see the difference it makes.