简体   繁体   English

如何阻止CSS nowrap在渲染的文档中放置换行符?

[英]How do I stop CSS nowrap from putting a line break in my rendered document?

How do i stop white-space: nowrap; 我如何停止white-space: nowrap; within a <p> tag from putting a line break at the start of the span with CSS? <p>标记中使用CSS在跨度的开头放置换行符?

I want to put ellipses on the last line of a search result excerpt and have it look nice on desktop, mobile, etc. 我想将省略号放在搜索结果摘要的最后一行,并使其在台式机,移动设备等上看起来不错。

I've read about solutions that use line height calculations to do this, but it seems fragile and possibly hacky. 我已经读过有关使用线高计算来执行此操作的解决方案,但是它似乎很脆弱,而且可能很笨拙。

My thinking is if I do two areas of content and put the text-overflow: ellipsis; 我的想法是,如果我做两个方面的内容,并把text-overflow: ellipsis; on the second one I'll get the effect I want. 在第二个上,我会得到想要的效果。

My problem is when I put white-space: nowrap; 我的问题是当我放置white-space: nowrap; on it puts a linebreak at the start of the span. 它在跨度的开头放置了一个换行符。 :( :(

Hat tip to @DaniP for putting the issue in a fiddle ! 帽尖到@DaniP为把问题的小提琴

Here is my search result template: 这是我的搜索结果模板:

<a href="/some-url/" class="search-result">
    <div class="well">
        <h4>title</h4>
        <p>See All Selfies Taken with iPhone Camera
Ready to see every selfie taken with the iPhone camera on a device? Here’s all you need to do:
 1 Open the Pho<span>tos app as usual but tap on the “Albums” button
 2 From the “Albums” view (tap back to Albums if you’re in Camera Roll), scroll down to find the “Sel</span></p>
    </div>
</a>

Here is the sass 这是无礼

.search-result {    
    p {
        overflow: hidden;
        text-overflow: ellipsis;
        span {
            white-space: nowrap;
        }    
    }
}

And here is what it looks like: 这是它的样子:

title
See All Selfies Taken with iPhone Camera Ready to see every selfie taken with the iPhone camera on a device? Here’s all you need to do: 1 Open the Ph
tos app as usual but tap on the “Albums” button 2 From the “Albums” view (tap back to Albums if you’re in Camera Roll), scroll down to find the “Sel

Here is how I want it to look after the white-space: nowrap; 这是我希望它照看white-space: nowrap; (no line break) (无换行)

title
See All Selfies Taken with iPhone Camera Ready to see every selfie taken with the iPhone camera on a device? Here’s all you need to do: 1 Open the Photos app as usual but tap on the “Albums” button 2 From the “Albums” view (tap back to Albums if you’re in Camera Roll), scroll down to find the “Sel

It doesn't put line break. 它没有换行。 It creates long non-breakable text line like a "big word", so the previous text breaks. 它会创建较长的不易碎的文本行,例如“大字”,因此前面的文本会中断。 Put white-space: nowrap; 放在white-space: nowrap; for <p> element. 用于<p>元素。

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

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