css force a line to be displayed

To force text content to be displayed on a single line, this can be achieved using CSS white-spaceproperties and attributes.overflow

First, white-spaceset the property to nowrap, so the text content won't wrap. Then, overflowset the property to hidden, so that content beyond one line is hidden.

Here is sample code:

.one-line {
    
    
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* 可选,当内容超出一行时,用省略号表示 */
}

Apply the above code to an element that needs to be forced to display a row, such as an <div>element:

<div class="one-line">这是一段很长的文本内容,将被强制显示在一行中。</div>

In this way, the text content will be forced to be displayed on one line, and the part beyond one line will be hidden.

Tool collection: https://aiburgeon.com/siteCollection/

insert image description here

Guess you like

Origin blog.csdn.net/qq_25741071/article/details/132608744