2012-02-18 99 views

回答

1

向這兩個元素添加一個float:left。像:

#story-teller-head-contain img{ 
    float: left; 
    /* your other styling */ 
} 

#story-teller-head-contain h1 { 
    float: left; 
    /* your other styling */ 
} 
+1

你不需要'h1'上的'float:left':http://jsfiddle.net/FqW9d/19/ – 2012-02-18 16:34:02

0

添加留給形象和包含名稱的DIV的浮動,我已經更新在這裏你的jsfiddle http://jsfiddle.net/FqW9d/15/

+0

你也應該刪除多餘的'display:inline's。 – 2012-02-18 16:34:58

0

內嵌顯示器可以是有點疼痛。跨瀏覽器的方式是這樣的...

/* Older version of FF */ 
display: -moz-inline-stack; 

/* newer versions of FF and Webkit */ 
display: inline-block; 

/* trigger the correct behaviour in IE */ 
zoom:1; 

/* IE */ 
*display: inline; 

您需要聲明順序的樣式sin。

0

你有以下結構(我已經添加了圖片的網址,所以我們可以看到,元素):

<div id="story-teller-head-contain"> 
    <img src="http://www.gravatar.com/avatar/e1122386990776c6c39a08e9f5fe5648?s=128&d=identicon&r=PG"/> 
    <div id="client-name"> 
     <h1> Matt Morris </h1> 
    </div> 
</div> 

div元素和h1默認情況下所有的塊級元素。但是,您只需要float: leftimg#client-name元素,並且它們會左移到它們的寬度(您聲明的位置),而不會強制下一個元素在下面流動。

#story-teller-head-contain img { 
    float: left; 
    height: 50px; 
    width: 50px; 
} 

#client-name { 
    float: left; 
    height: 50px; 
    width: 200px; 
} 

#story-teller-head-contain h1 { 
    margin: 0px 0px 0px; 
    padding: 0px 0px 0px 0px; 
    font-family: 'helvetica neue', arial, sans-serif; 
    font-size: 12px; 
    color: #3B5998; 
} 

http://jsfiddle.net/FqW9d/21/

所以你沒有真正尋找display: inline,這將嘗試顯示元素的是「嵌入式文本」顯示(如本段文字);你想要的是img#client-name元素不是「在012之後強制clear」。你的display: inline是允許塊級元素h1破壞你的顯示的原因,因爲它重寫了父元素的display: inline。實際上,如果您使用Firebug或Chrome控制檯進行檢查,則會看到上述計算結果爲float: leftdisplay: block,即使display: block尚未明確聲明。

參見:

0
I feel its better to use - 

img{ 
    float:left; 
} 
#client-name{ 
    display: table-cell; 
    zoom:1;/*For IE only*/ 
} 

你不必像在浮法指定寬度。它會自動適應不同長度的文本。

我已經更新了你的代碼 - http://jsfiddle.net/FqW9d/27/

但我認爲你的結構& CSS可能會更加簡單。由於我不知道這個目的,所以不要動它。