如果第二个具有长文本,如何保持两个div并排 [英] how to keep two div side by side if the second has a long text

查看:167
本文介绍了如果第二个具有长文本,如何保持两个div并排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,其中有两个div并排。外部div的宽度和内部左div的宽度是固定的。我使用display:inline-block并排显示两个div,但是如果右边的div的文本太长,右边的div将移动到第二行。我们如何使正确的div中的文本在div中改变线,而不是让整个div向下移动?

I have a div in which there are two divs side by side. The width of the outer div and the width of the inner left div are fixed. I use display:inline-block to show two divs side by side, but if the text in the right div is too long, the right div will move to the second line. How can we make the text in the right div changes line inside the div instead of making the whole div move down?

<div style="width:300px"><div style="width:100px; display:inline-block; background-color:green">the first div</div><div style="display:inline-block; background-color:yellow">the second div with a long text, some more</div></div>

推荐答案


$ b解决方案

解决方案

您可以给第一个< div> a float:left; CSS属性和第二个 overflow:hidden;

You could give the first <div> a float:left; CSS property and the second an overflow:hidden;:

<div style="width:300px"><div style="width:100px; float:left; background-color:green">the first div</div><div style="overflow:hidden; background-color:yellow">the second div with a long text, some more</div></div>

这篇关于如果第二个具有长文本,如何保持两个div并排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆