CSS implements horizontal scrolling navigation bar on mobile devices (also applicable to PC devices)

CSS implements horizontal scrolling navigation bar on mobile devices (also applicable to PC devices)

Function Origin

I was recently working on an H5 that required a horizontal scroll bar. After reading some documents, I finally decided to write one myself, one that is compatible with both Mobile and PC.

HTML

<body>
    <div class="nav">
        <a href="#">Nav1</a>
        <a href="#">Nav2</a>
        <a href="#">Nav3</a>
        <a href="#">Nav4</a>
        <a href="#">Nav5</a>
        <a href="#">Nav6</a>
        <a href="#">Nav7</a>
        <a href="#">Nav8</a>
        <a href="#">Nav9</a>
        <a href="#">Nav10</a>
        <a href="#">Nav11</a>
        <a href="#">Nav12</a>
        <a href="#">Nav13</a>
        <a href="#">Nav14</a>
        <a href="#">Nav15</a>
    </div>
    <div>
        Content area</div>
</body>

CSS

.nav {
    width: 100%;
    height: 50px;
    line-height: 50px;
    /*No line breaks in paragraphs*/
    white-space: nowrap;
    /*shadow*/
    box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
    /*Set horizontal scrolling*/
    overflow-x: scroll;
    /*Disable vertical scrolling*/
    overflow-y: hidden;
    /*Text tiling*/
    text-align: justify;
    /*Background color*/
    background: #F4F5F6;
    padding: 0px 5px;
    margin-bottom: 10px;
    /*Set the margin change effect to indent*/
    box-sizing: border-box;
}
.nav a {
    color: #505050;
    /*Cancel the underline of the hyperlink*/
    text-decoration: none;
    margin: auto 10px;
}
.nav::-webkit-scrollbar {
    /*Hide scrollbar*/
    display: none;
}

This way, we can achieve horizontal scrolling navigation. Isn’t it very simple?

This concludes this article about how to use CSS to implement a horizontal scrolling navigation bar on mobile devices (also applicable to PC). For more information about CSS horizontal scrolling navigation bars, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Example code of html formatting json

>>:  Special effects of Bootstrap 3.0 study notes (display and hide, eliminate floating, close button, etc.)

Recommend

How to set up virtual directories and configure virtual paths in Tomcat 7.0

Tomcat7.0 sets virtual directory (1) Currently, o...

Vue+axios sample code for uploading pictures and recognizing faces

Table of contents Axios Request Qs processing dat...

Use of LRU algorithm in Vue built-in component keep-alive

Table of contents The use of Vue's keep-alive...

Basic usage examples of listeners in Vue

Table of contents Preface 1. Basic usage of liste...

HTML marquee tag usage examples

This tag is not part of HTML3.2 and only supports ...

How to use the vue timeline component

This article example shares the specific implemen...

How to extract string elements from non-fixed positions in MySQL

Preface Note: The test database version is MySQL ...

MySQL database Shell import_table data import

Table of contents MySQL Shell import_table data i...

A Brief Discussion on the Navigation Window in Iframe Web Pages

A Brief Discussion on the Navigation Window in If...

Difference between MySQL btree index and hash index

In MySQL, most indexes (such as PRIMARY KEY, UNIQ...

Detailed explanation of MySql view trigger stored procedure

view: When a temporary table is used repeatedly, ...

Native JS to implement login box email prompt

This article shares a native JS implementation of...

HTML Form Tag Tutorial (4):

Suppose now you want to add an item like this to ...