Home > Web Front-end > CSS Tutorial > How to Create Responsive CSS-Only Separators for Horizontal Lists That Disappear on Line Breaks?

How to Create Responsive CSS-Only Separators for Horizontal Lists That Disappear on Line Breaks?

Mary-Kate Olsen
Release: 2024-12-16 10:43:10
Original
479 people have browsed it

How to Create Responsive CSS-Only Separators for Horizontal Lists That Disappear on Line Breaks?

CSS-Only Separator for Responsive Horizontal List

In the context of responsive navigation, how can separators between list items be removed at line breaks induced by varying viewport sizes?

Responsive Separators

Consider the following scenario:

  • Wide Viewport:

    -> Item 1 | Item 2 | Item 3 | Item 4 | Item 5 <-
    Copy after login
  • Small Viewport:

    -> Item 1 | Item 2 | Item 3 <-
    -> Item 4 | Item 5 <-
    Copy after login

However, in some cases, separators may persist at the line breaks, as demonstrated in this fiddle.

CSS-Only Solution

By exploiting the automatic collapse of trailing and line trailing white space, we can create responsive separators:

b {
    background: red;
    outline: 1px solid blue;
}
div {
    resize: both;
    overflow: hidden;
}
Copy after login
<div>
word<b> </b>.repeat(42)
</div>
Copy after login

The above is the detailed content of How to Create Responsive CSS-Only Separators for Horizontal Lists That Disappear on Line Breaks?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template