VIEW DEMO:
Sample HTML:
<div id="profile-grid">
<img src="http://example.com/profile-pic.jpg"/>
<ul id="listed">
<li class="item"><a href="#"> Profile </a></li>
<li class="item"><a href="#"> About </a></li>
<li class="item"><a href="#"> Photos </a></li>
<li class="item"><a href="#"> Albumlist </a></li>
</ul>
</div>
CSS Styling:
#profile-grid {
height: 302px;
width: 330px;
}
#profile-grid img {
display: block;
width: 100%;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
}
#listed {
height: 50px;
border: 1px solid #ddd;
overflow: hidden;
}
li.item {
margin: 0px;
display: inline;
float: left;
height: 50px;
border-left: 1px solid #ddd;
display: inline;
}
#listed li a {
display: block;
font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
font-size: 15px;
color: #123454;
line-height: 50px;
padding: 0px 15px 0;
text-align: center;
text-decoration: none;
vertical-align: baseline;
}
#listed li a:hover{
font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
font-size: 15px;
color: white;
background-color: #123454;
text-align: center;
text-decoration: none;
}
Important Details:
<ul>
automatically expands to the width of its parent element. If the parent is 330px wide, the <ul>
will also be 330px wide.
If no width is specified for a block element, its 100% width includes borders. Therefore, if the parent is 330px wide, the block element (in this case <ul>
) will be 298px wide plus 1px left border and 1px right border.
Specifying width for an element excludes borders from the count, causing overflow in some cases.
Using display:block
and width:100%
for images maintains their ratio without distortion.