2014-09-30 39 views
0

我简单地使用内联块设计一个HTML页面以使其响应。我将所有块形式的图像和文本设置为内联块,但文本块被移动到图像块下,我如何设置CSS并将文本块放在图像块旁边?使用内联块的自适应设计

演示:http://jsfiddle.net/yckelvin/ar1f3uz5/

HTML代码

<div class="item-row"> 
<div class="item-li"><img src="https://3.bp.blogspot.com/-t9e7S8huhaQ/VBMVN6CbNGI/AAAAAAAAA14/02am46_jiJM/s1600/Big_smile.png" width="150" height="150" /></div> 
<div class="item-desc" ><h1>Item 1</h1> 
Description Description Description Description Description Description Description Description Description Description </div> 
</div> 

<div class="item-row item-indent-row"> 
<div class="item-li"><img src="https://3.bp.blogspot.com/-t9e7S8huhaQ/VBMVN6CbNGI/AAAAAAAAA14/02am46_jiJM/s1600/Big_smile.png" width="150" height="150" /></div> 
<div class="item-desc"><h1>Item 2</h1> 
Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description Description </div> 
</div> 

CSS代码

.item-row { display: block; width: 100%; padding: 30px; background-color: rgba(0,0,0,0.1); } 
.item-indent-row { padding-left: 150px; } 
.item-li {display: inline-block; width:50px; background-color: rgba(255,255,0,0.1); } 
.item-desc {display: inline-block; background-color: rgba(0,0,255,0.1); padding-left: 0px;} 

实际样品

项目1

描述描述描述描述描述描述描述描述描述描述


项目2

说明说明说明描述描述描述描述描述描述描述描述描述描述描述描述描述描述
+0

'float:left' ?? – timgavin 2014-09-30 04:00:51

+0

我尝试了浮动,但无法控制图像块旁边的文本块。 – Kelvin 2014-09-30 04:05:37

回答

0
.item-desc { 
    display:block; 
    width:200px; 
    /*Or whatever width you wanted the description 
     to be. Just make sure it's not too wide to fit on the same line 
    */ 
    float:left; 
    background-color: rgba(0,0,255,0.1); 
    padding-left: 0px; 
} 
0

使用white-space: nowrap;代替.item-rowwhite-space: normal;代替.item-desc