html (+css): denoting a preferred place for a line break

前端 未结 9 1583
南旧
南旧 2020-11-28 03:08

Let\'s say I have this text that I want to display in an HTML table cell:

Honey Nut Cheerios, Wheat Chex, Grape-Nuts, Rice Krispies, Some random cereal with          


        
相关标签:
9条回答
  • 2020-11-28 03:57

    There’s an HTML element for that™: the (now standardized) <wbr> element.

    I’d advise you to use that. It may not work everywhere, but it’s the best you can do without going through hoops.

    0 讨论(0)
  • 2020-11-28 03:58

    There's a very neat RWD-solution from Dan Mall that I prefer. I'm going to add it here because some other questions regarding responsive line breaks are marked as duplicates of this one.
    In your case you'd have:

    <span>Honey Nut Cheerios, <br class="rwd-break">Wheat Chex, etc.</span>
    

    And one line of CSS in you media query:

    @media screen and (min-width: 768px) {
        .rwd-break { display: none; }
    }
    
    0 讨论(0)
  • 2020-11-28 03:59

    Use <div> instead of <span>, or specify a class for SPAN and give it the display:block attribute.

    0 讨论(0)
提交回复
热议问题