简体   繁体   English

文本换行时消除项目之间的间隙

[英]Remove gap between items when text wraps

I want the dash to be vertically centered with the text on the right and I want them to be 10px apart.我希望破折号与右侧的文本垂直居中,并且我希望它们相距 10 像素。 But when I'm using flex, the text on the right wraps normally, but takes more than its content's actual size, and now the gap between the two spans is too wide.但是当我使用 flex 时,右侧的文本会正常换行,但占用的内容超过其内容的实际大小,现在两个跨度之间的差距太大了。 Is there an elegant solution to this ?有没有一个优雅的解决方案?

 ul { width: 300px; list-style: none; text-align: center; font-size: 20px; } li { display: flex; flex-direction: row; align-items: center; justify-content: center; } span.dash { margin-right: 10px; }
 <ul> <li><span class="dash">-</span><span>+ 10€ pour séance à domicile (déplacement inclus)</span></li> </ul>

I found a way to do it, but I'm not too happy with it.我找到了一种方法,但我对此不太满意。 Here it is :这里是 :

 ul { width: 300px; list-style: none; text-align: center; font-size: 20px; } li { position: relative; } span.dash { position: absolute; top: 50%; transform: translateX(-300%) translateY(-50%); }
 <ul> <li><span class="dash">-</span><span>+ 10€ pour séance à domicile (déplacement inclus)</span></li> </ul>

Use word-break: break-all;使用word-break: break-all; working fine工作正常

 ul { width: 300px; list-style: none; text-align: center; font-size: 20px; } li { position: relative; padding-left:15px; } span{ display: block; word-break: break-all; } span.dash { position: absolute; top: 50%; left: 0; transform: translateY(-50%); }
 <ul> <li><span class="dash">-</span><span>+ 10€ pour séance à domicile (déplacement inclus) 10€ pour séance à domicile (déplacement inclus) </span></li> </ul>

To align to the right you need to put the display: flex property on the parent element.要向右对齐,您需要将 display: flex 属性放在父元素上。

If I understand your question, the solution is: jsfiddle.net/gabrielpito/y6jog29x/如果我理解你的问题,解决方案是:jsfiddle.net/gabrielpito/y6jog29x/

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

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