2010-08-26 70 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