programing

어떻게 하면 텍스트가 한 줄 이상 차지하는 것을 막을 수 있습니까?

newstyles 2023. 8. 17. 20:58

어떻게 하면 텍스트가 한 줄 이상 차지하는 것을 막을 수 있습니까?

텍스트를 래핑하지 못하게 하는 단어 래핑이나 다른 속성이 있습니까?저는 키가 크고,overflow:hidden텍스트는 여전히 깨져 있습니다.

CSS3 이전의 모든 브라우저에서 작동해야 합니다.

div {
  white-space: nowrap;
  overflow: hidden;
}
<div>testing quite a lot of text that just doesn't wrap because it is too long a run-on sentance with so many useless words for you to not read today despite every effort you make to do so including stretching your browser width to the maximum length unless however you utilized your browser's zooming out feature or manually modifying the CSS in which case you are definitely cheating and ruining this fun little game of me typing out as many words as can be fitted into one ridiculously long run-on sentence of the twenty-first century anno domini using my traditional keyboard and two monitors at 1080p while going through every effort to painstakingly ramble on and on but just not exactly repeating myself short of reusing a couple of words in multiple places throughout this HTML even though that would be about a thousand times easier than what I'm currently doing on this day to pointlessly avoid work regardless of its futility given that it'll only create consequences for myself in having to work harder to catch up later of course all of that notwithstanding moderation efforts to tone back my extensive efforts to make this somewhat enjoyable to read while making it as long as possible who may or may not revert this edit in spite of its usefulness since the previous edit only contained four words that could not possibly wrap even without the CSS changes due to their short nature which is invariably going to create more questions than it answers such as can be found in the comments section which is exactly why I created this effort in order to address one of those about the purpose of the overflow attribute which if you have modified you will now see lets you read the entirety of this text through the benefits of horizontal scrolling features but on the other hand if only overflow was used and text-wrap was left out then you will continue to see a vertical scrollbar unless you set a fixed height for this div in which case you certainly should see that vertical overflow is hidden though that would only happen if you did not put this example into fullscreen short of having your viewport set to a small enough height which can actually be further defined to a designated number of lines as opposed to one by using a height set to a multiple of the CSS property defined by line-height which could be a percentage of white-space and that would indeed hide the vertical overflow of this mountain of text which I'm really quite surprised that you managed to linger on here to read through its frivolous nature on the famed site known by programmers as Stack Overflow and for that I congratulate you for potentially wasting your time</div>

참고: 이것은 블록 요소에서만 작동합니다.테이블 셀에 대해 이 작업을 수행해야 하는 경우(예: 테이블 셀에 차단 안 함 표시 테이블 셀이 있으므로 테이블 셀 내부에 div를 배치해야 합니다.

CSS3에서 이것은 테이블 셀에도 지원됩니다.

를 위해 CSS 속성을 사용할 수 있습니다.

white-space: nowrap;

사용.text-overflow: ellipsis마지막에 ...을 추가합니다.

div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

때때로 사용하기&nbsp;공간 대신에 작동합니다.하지만 분명히 단점이 있습니다.

확실히 하기 위해, 이것은 문단과 머리글 등과 잘 작동합니다.지정하기만 하면 됩니다.display: block.

예를 들어:

<h5 style="display: block; text-overflow: ellipsis; white-space: nowrap; overflow: hidden">
  This is a really long title, but it won't exceed the parent width
</h5>

(인라인 스타일 변경)

언급URL : https://stackoverflow.com/questions/572298/how-to-stop-text-from-taking-up-more-than-1-line