在Html Div中,Overflow Hidden对我不起作用

时间:2012-12-30 11:57:23

标签: html css

我正在使用以下html,请参阅此jsfiddle         

        <div style="float: left;">
            <div style="padding-left: 3px; padding-top: 3px;">
                <div style="float: left;">
                    Title: 
                </div>
                <div style="float: left; padding-left: 12px">
                    ABC
                </div>
                <div style="clear: both"></div>
            </div>
            <div style="padding-left: 3px; padding-top: 3px;">
                <div style="float: left;">
                    Lyrics: 
                </div>
                <div style="float: left; padding-left: 3px">
                    <div style="overflow: hidden; width: 180px">
                        ABC DEF GHI JKl MNO dsa  dsa sddsa d s
                    </div>
                    <div style="overflow: hidden; width: 180px">
                        ABC DEF GHI JKl MNO MNO dsa  dsa sddsa d s
                    </div>
                </div>
                <div style="clear: both"></div>
            </div>
        </div>

        <div style="float: right; border-left: 1px solid black;">

            <img src="http://cdn1.iconfinder.com/data/icons/snowish/72x72/actions/gtk-media-play-ltr.png">
        </div>
    </div>

但我的文字溢出并未隐藏。 当我使用小文本而不是&#39;

  

ABC DEF GHI JKl MNO dsa dsa sddsa d s

&#39;一切都很好。

2 个答案:

答案 0 :(得分:4)

white-space: nowrap

    <div style="float: left;">
        <div style="padding-left: 3px; padding-top: 3px;">
            <div style="float: left;">
                Title: 
            </div>
            <div style="float: left; padding-left: 12px">
                ABC
            </div>
            <div style="clear: both"></div>
        </div>
        <div style="padding-left: 3px; padding-top: 3px;">
            <div style="float: left;">
                Lyrics: 
            </div>
            <div style="float: left; padding-left: 3px">
                <div style="overflow: hidden; white-space: nowrap; width: 180px; ">
                    ABC DEF GHI JKl MNO dsa  dsa sddsa d s
                </div>
                <div style="overflow: hidden; white-space: nowrap; width: 180px">
                    ABC DEF GHI JKl MNO MNO dsa  dsa sddsa d s
                </div>
            </div>
            <div style="clear: both"></div>
        </div>
    </div>

    <div style="float: right; border-left: 1px solid black;">

        <img src="http://cdn1.iconfinder.com/data/icons/snowish/72x72/actions/gtk-media-play-ltr.png">
    </div>
</div>

小提琴:http://jsfiddle.net/H3nXk/1/


或者如果您担心身高,则需要明确指定height

答案 1 :(得分:1)

您需要指定一个高度,以便容器知道溢出的开始位置。