简体   繁体   English

文本溢出浮动div

[英]Text overflowing floated div

I have a problem with a fluid layout I am attempting to create. 我正在尝试创建流畅的布局时遇到问题。 I was wondering why I am not able to get overflow:hidden to work on the left menu text on this site. 我想知道为什么我不能溢出:隐藏在该站点的左侧菜单文本上工作。

As you can see here, I have labelled in blue, the text which I would like contained within the left menu div, although it overflows and pushes the rest of the site down with it. 正如您在此处看到的那样,我用蓝色标记了我想包含在左侧菜单div中的文本,尽管该文本溢出并用它向下推网站的其余部分。

Please see here for a JS Bin: http://jsbin.com/OcoJEpe/2/edit?html,css,output 请在此处查看JS Bin: http : //jsbin.com/OcoJEpe/2/edit?html,css,output

Thanks for your help. 谢谢你的帮助。

James. 詹姆士。

The reason that overflow:hidden; overflow:hidden;的原因overflow:hidden; is not working is because your left-menu div is expanding due to the size of the text. 不起作用是因为文本大小导致您的left-menu div正在扩展。 You have no code (css or html) that is restricting the height of your left-menu . 您没有限制left-menu高度的代码(css或html)。 There are a number of ways to solve this problem, but essentially you need to tell the div to only go to a certain height. 有很多方法可以解决此问题,但是从本质上讲,您需要告诉div仅达到特定高度。

Your height on that element is using its default value of auto so it will expand to accommodate its content. 您在该元素上的height正在使用其默认值auto因此它将扩展以容纳其内容。

You need to specify some height: 您需要指定一些高度:

  #left-menu{height:200px;} //OR SOME NON-AUTO HEIGHT

您需要在左侧菜单中增加高度,看看这个jsfiddle

This is a working example, you should just add a height for p and set overflow:hidden . 这是一个有效的示例,您应该为p 添加一个height设置 overflow:hidden

Here is html 这是html

<p id="height"><span>This text is overflowing parent div...</span>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse a odio ac nulla aliquet molestie. Cras aliquet metus eget vehicula vulputate. Donec eget nisl sit amet quam fringilla molestie. Vivamus elementum non justo quis consequat. Etiam quis quam eu nisi cursus aliquet eu et arcu.
    </p>

and css 和CSS

p#height{
      height:30px;
      background:red;
      overflow:hidden;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM