Reputation: 5962
I am working on my college project, for which I have to add vertical menu bar in my project. I have searched a lot on Google, but could not find a code for creating a vertical menu with images. Can you please tell me how I can create this type of menu?
I want to create my menu like this:
i am trying like this , but text is getting placed at the bottom. i want it in middle.
<ul class="menu">
<li>
<a href="#"><p><img src="images/sys.png" width="30" height="30">Home</p></a>
</li>
</ul>
Upvotes: 0
Views: 85
Reputation: 2878
The basic idea is that you can vertical align the text and the image using display: inline-block and vertical-align: middle.
<ul class="nav">
<li class="roadster"><a href="#"><span class="brand">Roadster</span><span class="image"><img src="http://png-3.findicons.com/files/icons/1012/racing_cars/128/mitsubishi_lancer.png" alt=""></span></a></li>
<li class="roadster"><a href="#"><span class="brand">Roadster</span><span class="image"><img src="http://png-3.findicons.com/files/icons/1012/racing_cars/128/mitsubishi_lancer.png" alt=""></span></a></li>
</ul>
http://jsfiddle.net/YVp8E/11/
http://jsfiddle.net/YVp8E/11/show
.nav {
width: 25em;
}
.nav li {
display: block;
}
.nav li a {
color: #686868;
display: block;
padding: 10px 0;
}
.nav li {
background: url(https://cdn2.iconfinder.com/data/icons/ios-7-icons/50/forward-128.png) no-repeat 100% 50%;
}
.nav li {
border-top: 1px solid #ccc;
}
.nav li:first-child {
border-top: none;
}
.nav span {
display: inline-block;
vertical-align: middle;
}
.nav .image {
padding-left: 60px;
}
Upvotes: 2
Reputation: 10285
you can use :after
pseudo element to achieve desire effect. Check the Demo.
<ul class="menu">
<li><a href="#">Boxter</a></li>
<li><a href="#">Cayman</a></li>
<li><a href="#">911</a></li>
</ul>
/--Here is the CSS----*/
ul{margin:0; padding:0; list-style-type:none;}
li a
{
display:block;
border-bottom:1px solid grey;
padding:25px 0;
}
li{ position:relative;}
li a:after
{
content:">";
position:absolute;
right:20px;
top:30px;
vertical-align:middle;
}
li:nth-child(1):after
{
content:" ";
position:absolute;
right:50px;
top:0;
background:url("http://lorempixel.com/70/70") 0 20px no-repeat;
width:70px;
height:70px;
vertical-align:middle;
}
li:nth-child(2):after
{
content:" ";
position:absolute;
right:50px;
top:0;
background:url("http://placehold.it/70x70") 5px 20px no-repeat;
width:70px;
height:70px;
vertical-align:middle;
}
Upvotes: 0