/    Sign up×
Community /Pin to ProfileBookmark

css image rollover menu

Following a previous request I was directed to the following tutorial to make a rollover menu using a css background image.

[url]http://www.tutorio.com/tutorial/pure-css-image-rollovers[/url]

I need a horizontal rather than vertical menu (the link with the tutorial is not working). Please could somebody help me with the necessary code changes.

Thanks.

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@ryanbutlerApr 25.2007 — You would need to float the entire list menu left, along with some other CSS code. Something like I describe in this article:

http://midwestwebdesign.net/tutorials/csstable/index.php
Copy linkTweet thisAlerts:
@CentauriApr 26.2007 — A css menu is much easier to manage (plus makes more sense semantically) when the links are an unordered list of links, plus it can get rid of a div. So the html can be [code=html]<ul id="nav">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Tutorial</a></li>
</ul>[/code]


To display this as a horizontal menu, style the <a> elements as blocks as per the original article. Here I did not use padding, and set the blocks to the image size (using the image in the original article), along with line height (sets the text in the centre vertically) and text align center. Any font declaration should be made [B]before[/B] the line-height size. The <li>s are then floated left to sit them side by side horizontally, and list-style set to none to get rid of the list bullets. Finally, the <ul> itself is given the appropriate width and positioned with margins. The overflow declaration makes sure the <ul> contains its floats.

css is:[CODE]* {
margin: 0;
padding: 0;
}
#nav {
display: block;
width: 380px;
overflow: hidden;
margin: 10px auto 0;
}
#nav li {
list-style: none;
float: left;
}
#nav a {
display: block;
font: bold 13px sans-serif;
width: 95px;
height: 35px;
line-height: 35px;
text-align: center;
color:#333;
background: url("rollover-image.gif") 0 0 no-repeat;
text-decoration: none;
}
#nav a:hover {
background-position: 0 -35px;
color: #049;
}
#nav a:active {
background-position: 0 -70px;
color:#fff;
}[/CODE]


Note the browser default margins and paddings are zeroed with the universal selector (*) at the start of the css - this should be used [B]before[/B] anything else in the css.

Cheers

Graeme
×

Success!

Help @martins spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...