這是一個完整的解決方案:
HTML:
<div class="wrapper clearfix">
<div class="left">
<img src="img.png">
</div>
<div class="right">
<h3>text</h3>
<p>text text</p>
</div>
</div>
CSS:
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
* html .clearfix { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */
.wrapper {
box-sizing: border-box; /* makes padding go on the inside */
padding: 10px; /* gives interior padding */
width: 1170px; /* whatever width you want the container to be */
margin: 0 auto; /* center it */
background-color: #fff;
}
.left {
width: 20%; /* whatever width you want the left side to be, stick to percentages */
float: left;
}
.left img {
width: 100%;
height: auto;
}
.right {
width: 77%; /* whatever width you want the right side to be, stick to percentages, notice that 77% and 20% dont add up to 100%, this is to account for the small gap inbetween the divs */
float: right;
}
注:漂浮的東西左右,當 「clearfix」 一詞。它可以防止當div div被浮動時,div本身崩潰的常見錯誤。
工作的jsfiddle:here
你可以浮動圖像盒和修改BFC的容器和文本https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context例子從你的HTML http://codepen.io/gc-nomade/pen/yVLJPE –