2013-03-28 34 views
0

努力試圖讓下面這個圖片:CSS的float:左不在這裏

Text on right of image

但這裏是我所代替:

Problem with float: left here

我使用這個代碼如下:

HTML:

<div class="floatright" style="width: 50%;"> 
    <div class="floatleft" style="width: 35%;"> 
     <img src="images/exhibitingopportunities.png" alt="Exhibiting Opportunities" style="border: none; width: auto; max-width: 100%;" /> 
    </div> 
    <div class="floatleft sidespadding" style="width: 65%;"> 
     <h4>Exhibiting Opportunities</h4> 
     <p class="desc">The Opportunity Finance Network Conference is a great place to connect with decision makers across the industry. Reserve your booth space now&mdash;contact Katie Kirchner for more information.</p> 
    </div> 
</div> 
<div style="width: 50%;"> 
    <div class="floatleft" style="width: 35%;"> 
     <img src="images/sponsorship_opportunities.png" alt="Sponsorship Opportunities" style="border: none; width: auto; max-width: 100%;" /> 
    </div> 
    <div class="floatleft sidespadding" style="width: 65%;"> 
     <h4>Sponsorship Opportunities</h4> 
     <p class="desc">Reserve your slot now to be a part of the CDFI industry's premier event! The OFN Conference provides our partners with an unparalleled platform to connect with CDFIs, increase awareness of their organizations' work, and support and strengthen the practice of opportunity finance.</p> 
    </div> 
</div> 

CSS:

.floatleft 
{ 
    float: left; 
} 

.floatright 
{ 
    float: right; 
} 

.sidespadding 
{ 
    padding-left: 1.2em; 
    padding-right: 1.2em; 
} 

.clear 
{ 
    clear: both; 
} 

無法獲取文字浮到實際圖像的左側,就像第一張圖的圖像。 OMG,我在這裏錯過了什麼?網頁在這裏:http://opportunityfinance.net/Test/2013conf/index.html

回答

2

擺脫你的填充,你的%大於100%填充。 或者你可以申請箱上漿http://www.w3schools.com/cssref/css3_pr_box-sizing.asp

如果你想空間,你可以隨時添加保證金左或右,但要確保你的百分比在結束

所以

1區30%計算爲100%寬度與例如5%的保證金右 2區65%的寬度

所以總= 100%

還有其他的方法來做到這一點,但你的想法,現在

+0

謝謝,這非常有幫助! –

0

填充增加了總寬度,使其65%+ 2.4em 如果使用舊版本的IE瀏覽器的向後兼容性不是一個問題,您可以使用CSS calc

否則,您必須包裝一些DIV以創建填充你想要的元素。