Both the image and .whitebox
are inline-level boxes in the same line box.
Therefore, their vertical alignment is specified by the vertical-align
property:
This property affects the vertical positioning inside a line box of
the boxes generated by an inline-level element.
By default, its value is baseline
:
Align the baseline of the box with the baseline of the parent box. If
the box does not have a baseline, align the bottom margin edge with
the parent's baseline.
Since the image does not have a baseline, its bottom margin edge will be aligned with the baseline of .whitebox
. That baseline is calculated according to
The baseline of an 'inline-block' is the baseline of its last line box
in the normal flow, unless it has either no in-flow line boxes or if
its 'overflow' property has a computed value other than 'visible', in
which case the baseline is the bottom margin edge.
Therefore, you can
Change the vertical alignment of the image and .whitebox
, e.g.
img, .whitebox {
vertical-align: middle;
}
body {
background-color: #F2F2F2;
}
h3 {
font-family: sans-serif;
text-align: center;
color: #535353;
}
.forR {
width: 980px;
padding-left: 20px;
margin-left: auto;
margin-right: auto;
margin-bottom: 25px;
padding-left: 10px;
}
.inline {
display: inline;
position: relative;
}
.whitebox {
background-color: #fff;
height: 200px;
display: inline-block;
}
.box1 {
width: 737px;
}
img {
height: 200px;
width: 200px;
margin-right: 10px;
display: inline-block;
}
img, .whitebox {
vertical-align: middle;
}
<h3>Name</h3>
<div class="forR">
<img src="http://cumbrianrun.co.uk/wp-content/uploads/2014/02/default-placeholder.png">
<div class="whitebox box1">
<p class="inline">Name: Matthew</p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
</div>
</div>
Make sure .whitebox
has no in-flow line box, so that the baseline of .whitebox
will be its bottom margin edge. That is, the contents should be out of flow:
An element is called out of flow if it is floated, absolutely
positioned, or is the root element. An element is called in-flow if it
is not out-of-flow.
So for example you can use float: left
:
.whitebox > * {
float: left;
}
body {
background-color: #F2F2F2;
}
h3 {
font-family: sans-serif;
text-align: center;
color: #535353;
}
.forR {
width: 980px;
padding-left: 20px;
margin-left: auto;
margin-right: auto;
margin-bottom: 25px;
padding-left: 10px;
}
.inline {
display: inline;
position: relative;
}
.whitebox {
background-color: #fff;
height: 200px;
display: inline-block;
}
.box1 {
width: 737px;
}
img {
height: 200px;
width: 200px;
margin-right: 10px;
display: inline-block;
}
.whitebox > * {
float: left;
}
<h3>Name</h3>
<div class="forR">
<img src="http://cumbrianrun.co.uk/wp-content/uploads/2014/02/default-placeholder.png">
<div class="whitebox box1">
<p class="inline">Name: Matthew</p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
</div>
</div>
Set the overflow
of .whitebox
to something different than visible
, so that the baseline of .whitebox
will be its bottom margin edge.
For example, overflow: hidden
:
.whitebox {
overflow: hidden;
}
body {
background-color: #F2F2F2;
}
h3 {
font-family: sans-serif;
text-align: center;
color: #535353;
}
.forR {
width: 980px;
padding-left: 20px;
margin-left: auto;
margin-right: auto;
margin-bottom: 25px;
padding-left: 10px;
}
.inline {
display: inline;
position: relative;
}
.whitebox {
background-color: #fff;
height: 200px;
display: inline-block;
}
.box1 {
width: 737px;
}
img {
height: 200px;
width: 200px;
margin-right: 10px;
display: inline-block;
}
.whitebox {
overflow: hidden;
}
<h3>Name</h3>
<div class="forR">
<img src="http://cumbrianrun.co.uk/wp-content/uploads/2014/02/default-placeholder.png">
<div class="whitebox box1">
<p class="inline">Name: Matthew</p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
<p class="inline"></p>
</div>
</div>