Reputation: 3669
I want to do something like the following, but I can't figure out how to align the logout link just above the navigation bar, without specifying an explicit padding
or line-height
which breaks the layout if the size of the image changes.
<img src="logo.png" />
<a> logout link </a>
<div> navigation bar </div>
I am using bootstrap, but I am also fine with a non-bootstrap solution.
Upvotes: 1
Views: 206
Reputation: 106
As Thanix says, you can combine relative and absolute positioning to achieve this. Make a containing div for the image and the logout link so that the logout link can be set at the bottom of this.
<div class="header">
<img class="logo_image" src="logo.png" width="40" height="40" />
<a class="logout_link"> logout link </a>
<div class="clear"></div>
</div>
<div class="nav_bar">navigation bar</div>
Then make the containing div position:relative and the logo position:absolute. The trick here is that "an absolute position element is positioned relative to the first parent element that has a position other than static." (www.w3schools.com). This means you can use bottom:0px and right:0px to position it at the bottom right of the containing div.
.header {position:relative;}
.logout_link {
position:absolute;
bottom:0px;
right:0px;
}
.logo_image {
float:left;
}
.clear {clear:both;}
The class="clear" div at the end of the containing div is to make sure the containing div fills the space of its child components.
Upvotes: 2
Reputation: 980
<a>
inside the navigation bar <div>
.position
to relative
.position
to absolute
, right
to 0
and top
to -1em
;Upvotes: 1