Reputation: 3120
Instead of Figure 1, I would like Figure 2. In Figure 1, the menu and image are aligned to the top, but I would like them to be aligned to bottom.
Here is my CSS:
<div id="branding">
<div class="brand-left"></div>
<div class="brand-right"></div>
</div>
#branding {
display: inline-block;
width: 100%;
}
.brand-left {
position: relative;
float: left;
width: 730px;
}
.brand-right {
text-align: right;
width: 222px;
float: left;
}
Upvotes: 1
Views: 2745
Reputation: 4987
You can achieve this behavior using display: flex
. All you have to do is add this rules to your branding
div:
#branding {
display: flex; /* ADDED */
align-items: flex-end; /* ADDED */
width: 100%;
border: 1px solid green;
}
Here is a snippet
#branding {
display: flex;
width: 100%;
border: 1px solid green;
align-items: flex-end;
}
#branding > div{
border: 1px solid blue;
}
.brand-left {
position: relative;
float: left;
width: 730px;
}
.brand-right {
text-align: right;
width: 222px;
float: left;
}
<div id="branding">
<div class="brand-left">content</div>
<div class="brand-right">
<img src="http://senda-arcoiris.info/images/100x100.gif"/>
</div>
</div>
Another solution without using flex
would be removing the floats
from child divs and position them absolute. Please see the snippet below:
#branding {
position: absolute; /* ADDED */
width: 100%;
border: 1px solid green;
}
#branding > div{
position: relative; /* ADDED */
display: inline-block; /* ADDED */
border: 1px solid blue;
bottom: 0;
}
.brand-left {
width: 330px; /* I changed the width in order to fit in the snippet */
}
.brand-right {
text-align: right;
width: 222px;
}
<div id="branding">
<div class="brand-left">content</div>
<div class="brand-right">
<img src="http://senda-arcoiris.info/images/100x100.gif"/>
</div>
</div>
Upvotes: 4
Reputation: 726
Just in case interested in without display: flex
#branding {
width: 100%;
}
.brand-left {
position: relative;
float: left;
width: 750px;
background: #f00;
min-height: 250px;
}
.brand-left .nav {
position: absolute;
bottom: 0px;
right: 15px;
}
.brand-left .nav li {
display: inline;
}
.brand-right {
text-align: right;
width: 222px;
float: left;
background: #ff0;
min-height: 250px;
}
<div id="branding">
<div class="brand-left">
<ul class="nav">
<li><a href="#">Registration</a>
</li>
<li><a href="#">Log In</a>
</li>
</ul>
</div>
<div class="brand-right"></div>
</div>
Upvotes: 0
Reputation: 460
There are a number of ways to do this and ultimately it depends on what you're trying to accomplish and what your project requirements are (e.g. browser support). That said, one way is to position the element you want bottom aligned absolutely.
position: relative;
property and valueposition: absolute;
property and valueHere is a working example: http://codepen.io/mjoanisse/pen/grvBwE
Upvotes: 1
Reputation: 856
you can try it with flexbox
#branding{
width:100%;
display:flex;
height:250px;
background-color:green;
align-items:flex-end;
}
.brand-left {
position: relative;
width: 730px;
height:150px;
background-color:pink;
}
.brand-right {
text-align: right;
width: 222px;
background-color:blue;
height:250px;
}
<div id="branding">
<div class="brand-left"></div>
<div class="brand-right"></div>
</div>
Upvotes: 1
Reputation: 8375
You can try using display: flex;
.bottom {
display: flex;
bottom: 0;
left: 0;
position: fixed;
width:100%;
}
.right {
margin-left: auto;
}
<div class="bottom">
<div class="left">
left
</div>
<div class="right">
right
</div>
</div>
Upvotes: 0