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

JavaScript to achieve simple drag effect

This article shares the specific code of JavaScri...

A brief talk on responsive design

1. What is responsive design? Responsive design i...

Detailed installation tutorial of mysql 5.7 under CentOS 6 and 7

You always need data for development. As a server...

Summary of xhtml block level tags

* address - address * blockquote - block quote * c...

vue-element-admin global loading waiting

Recent requirements: Global loading, all interfac...

Implementation of Nginx forwarding matching rules

1. Regular expression matching ~ for case-sensiti...

How to monitor multiple JVM processes in Zabbix

1. Scenario description: Our environment uses mic...

Discussion on image path issues in css (same package/different package)

In CSS files, sometimes you need to use background...

Implementation of Docker deployment of Nuxt.js project

Docker official documentation: https://docs.docke...

JavaScript simulation calculator

This article shares the specific code of JavaScri...

Summary of Linux ps and pstree command knowledge points

The ps command in Linux is the abbreviation of Pr...

Solve the problem of combining AND and OR in MySQL

As shown below: SELECT prod_name,prod_price FROM ...

The new version of Chrome browser settings allows cross-domain implementation

Preface Currently, the front-end solves cross-dom...