简体   繁体   English

带有内联块的div上的文本溢出

[英]Text overflowing on div with inline block

I have a inline block within a div that has some text contents. 我在具有某些文本内容的div中有一个内联块。 The text contents are overflowing if the display is set to inline... 如果显示设置为嵌入式,则文本内容溢出...

http://jsfiddle.net/76d9twoy/ http://jsfiddle.net/76d9twoy/

HTML & CSS HTML和CSS

<div id="leftdiv">
</div>
<div id="rightdiv">
       <div id="nametag">Simba Animated Plush Battery Operated Sitting Talking Tom, Multi Color (9-inch)<div>
       <div id="pricetag">10.00$<div>
       <div id="quantitytag">10<div>
</div>



#leftdiv{
    float:left;
    width:100px;
    height:100px;
    background-color:blue

}

#rightdiv{
    float:left;
    width:400px;
    height:100px;
    background-color:yellow
}
#nametag{
    width:200px;
    display:inline;

}

Question: How do I text wrap the nametag contents? 问题:如何文本包装名称标签内容?

But what is the problem? 但是有什么问题呢? if you want it inline-block than can you do this to fix it: 如果您希望将其内联,则可以执行以下操作来修复它:
css: CSS:

#nametag{
width:200px;
display:inline-block; //set to inline-block
}

#rightdiv{
float:left;
width:400px;
height:auto; //set to auto
background-color:yellow
}

than at this Jquery code to the page to set the leftdiv height the same as the rightdiv 而不是在此Jquery代码中将页面的leftdiv高度设置为与rightdiv相同

Jquery: jQuery:

$('#leftdiv').css( 'height', $('#rightdiv').height());

than you get this a result http://jsfiddle.net/76d9twoy/1/ 比你得到这个结果http://jsfiddle.net/76d9twoy/1/

You have to switch from inline to inline-block if you want them to fit next to each other. 如果要使它们彼此相邻,则必须从内联切换为内联块。 In addition, be careful with your tags. 此外,请注意标签。 Your divs were not closed. 您的div未关闭。 You must use: 您必须使用:

</div>

To fix the single line, use white-space property. 要固定单行,请使用空白属性。

white-space:nowrap;

Here is the jsfiddle: http://jsfiddle.net/76d9twoy/2/ 这是jsfiddle: http : //jsfiddle.net/76d9twoy/2/

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

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