简体   繁体   English

如何防止文本在插入的元素下换行?

[英]How to prevent text from wrapping under inserted element?

I am working with an existing markup little of which I can change (Scenario 1) 我正在使用现有的标记,但几乎不能更改(方案1)
JSFiddle . JSFiddle

 .container { width: 340px; border: 1px solid yellow; margin-bottom: 20px; } .title a { font: 32px/normal 'Segoe UI Light', Arial; line-height: 1.2em; text-decoration: none; color: #606060; } span.bb { border: 1px solid red; width: 30px; height: 30px; margin-right: 12px; display: inline-block; cursor: pointer; vertical-align: bottom; } 
 <div class="container"> <h2 class="title"> <!-- following span tag is added at runtime --> <span class="bb"></span> <a href="http://test.com" target="_blank"> Lorem ipsum dolor sit amet, consectetur adipisicing elit </a> </h2> </div> 

I want to insert a fixed sized span tag which works great as long the existing text fits on a single line (Scenario 2). 我想插入一个固定大小的span标签,只要现有文本适合在一行中,它就可以很好地工作(方案2)。 If the existing text spans multiple lines, it wraps under the span tag that I inserted (Scenario 3). 如果现有文本跨越多行,则将其包裹在我插入的span标签下(场景3)。

I want to prevent text from wrapping under the span tag and want the subsequent lines to align with the first word of the sentence. 我想防止文本在span标签下换行,并希望随后的行与句子的第一个单词对齐。

I tried couple of approaches, but didn't get the solution quite right without loosing the wrapping ability or breaking existing scenarios. 我尝试了几种方法,但是在不失去包装能力或破坏现有方案的情况下,解决方案并不正确。

I would prefer a CSS solution for fixing this layout problem. 我希望使用CSS解决方案来解决此布局问题。

I got this working by adding following additional styles 我通过添加以下其他样式来完成此工作

span.bb {
    float:left;
}

span.bb + a {
    display: block;
    margin-left: 42px;    
}

http://jsfiddle.net/anunay/3bqLq/ http://jsfiddle.net/anunay/3bqLq/

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

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