Reputation: 26756
I've got a CSS menu something like this...
<ul>
<li><img src="...">Menu item</li>
<li><img src="...">Menu item2</li>
</ul>
My CSS currently gives me this...
What I want is something like this...
I've tried to trim down the CSS to the relevant bits - let me know if I've omitted anything crucial...
ul#menu li ul li {
position: relative;
display: block;
background-color: #fff;
border-top: solid 1px #808080;
}
ul#menu li ul li:first-child {
border-top: none;
}
ul#menu li ul li img {
position: relative;
left: 0px;
}
The problem is that the image is a child of the <li>
which is not the full width of the <ul>
, so the position: relative; left: 0px;
relates to the li
not the ul
.
How can I position the image relative to the ul
?
Upvotes: 2
Views: 2626
Reputation: 261
Since these images are not actually part of the content, remove the img
elements from the html and add one line to your CSS:
ul#menu li ul li {
background: url(/Content/images/nav/Left.png) 5px center no-repeat;
}
This will set the arrow as a background image that is always 5px from the left edge and automatically centered, even if the menu item spans two lines, as a couple of them do.
Upvotes: 3
Reputation: 1984
Set your
ul#menu li ul li
width to 100%
ul#menu li ul li {
width: 100%; //Make sure you have a set px width somewhere else in the menu hierarchy
position: relative;
display: block;
background-color: #fff;
border-top: solid 1px #808080;
}
Then set the img as absolute
ul#menu li ul li img {
position: absolute;
left: 0px;
}
Upvotes: 1
Reputation: 15382
One simple solution
ul#menu li ul li img {
float: left;
margin-top: 7px;
}
Upvotes: 1