2010-08-26 239 views
2

我可以發誓我已經看過關於這個問題的文章,但是我無法爲了我的生活再次找到它們! 基本上,如果我有div的內容不受div寬度限制

<div style="width: 250px;">The width of this div should be no less than 250px wide</div> 

在下面的代碼,在div內容不限制它的寬度與寬度指定引起溢出的問題:

 <div class="PostIt"> 
      <div id="tags"><span class="qExtraLarge"><a href="Team/Default.aspx#lucky">Lucky Khumalo</a></span> 
      <span class="qLarge"><a href="Investments/Social/School/Default.aspx">School</a></span> 
      a;orghaepoht8aegae[hgi'aehg[ahgiha[e8gjaerghuoaeir'ghu;dsOsgh;vrwi/jbvh?URbnIRWhb'a[985h[qygherionhbdl</div> 

     </div> 

.PostIt { display: block; text-align: left; padding: 30px 30px 30px 30px; height: 240px !important; width: 190px !important; background: transparent url("Images/PostIt.png"); } 
.PostIf #tags { width: 250px !important; } 

任何建議將是巨大的!

在此先感謝。

回答

1

設置單獨的塊元件上的寬度不會停止了比從溢出元件的界限寬度更寬的任何內容。要做到這一點,你還需要設置「溢出」屬性。將其設置爲「隱藏」將簡單地隱藏界限外的任何內容,但您也可以將其設置爲其他值以自動顯示滾動條等。

請參閱http://reference.sitepoint.com/css/overflow瞭解溢出CSS屬性的一個很好的解釋。

+0

既不隱藏溢出或滾動條是不夠好,我需要基本上爲內容設置文字換行 – 2010-08-26 16:37:15

+0

是的,不間斷的「單詞」總是會破壞你的佈局。 word-wrap屬性在CSS 3中,但已經得到很好的支持(實際上是由MS發明的)。 – 2010-08-26 17:01:05

0

隱藏你的溢出。

或者更確切地說

.myclass { overflow: hidden; } 
3

如果你想隱藏任何溢出的內容,使用overflow:hidden;

如果你要顯示的內容,只是強制換行,使用word-wrap:break-word;

+0

看起來似乎是「單詞包裝:瑣碎的單詞;」並沒有幫助。我根本沒有看到任何區別(使用Google Chrome),但是當我將邊距設置爲塊時,我確實發現有變化... – 2010-08-27 08:11:50

+0

爲我工作。謝謝! – MyCah 2016-01-12 05:32:22