简体   繁体   中英

Can I add horizontal scroll bar for nav bar? how?

I'm new to html/css and javascript. I want Buttons to be on the same line and they can be scrolled through horizontally... The problem is two

  1. I can't get them all in one line rather some are going to second line..
  2. I can't understand how can I have them all in one so I can scroll them horizontally...

As attached images I want these circles to be on same line... What I have done is given below. But the problem is some of these circles are shown in next line... My code is Below Html:

<html>
    <head>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Areeba Textile</title>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"></link>
        <link rel="stylesheet" href="style.css"></link>
    </head>
    <body>
        <h1>Unstitch Cloth</h1>
        <p>Category of Unstitch Cloth available</p>
        <div class="topnav circontain">
            <a href="" >Silk</a>
            <a href="">Cotton</a> 
            <a href="">Lawn</a>
            <a href="">Khadder</a>
            <a href="">Linen</a>
            <a href="">Shafoon</a>   
            <a href="">Chiffon</a>
            <a href="">1 piece</a>
            <a href="">2 piece</a>
            <a href="">3 piece</a>
            <a href="">Winter</a>
        </div>
    </body>
</html>

CSS:

@import url("https://fonts.googleapis.com/css2?family=Sriracha&display=swap");

body {
  background-size: cover;
  background-repeat: no-repeat;
  color: #585858;
  margin: 0;
  padding: 0;
  font-family: 'Yaldevi', sans-serif;
  margin-top: 30px;
  box-sizing: border-box;
}

h1, p, h3 {
    text-align: center;
    color: black;
}
a {
    text-decoration: none;
}

.circontain a{
    color: black;
    display: inline;
    height: 100px;
    width: 100px;
    line-height: 200px;
    background-color: pink;
    border-radius: 50%;
    margin-left: 50px;
    text-align: center;
    margin-top: 100px;
    padding: 18px;
    border: none;
    cursor: pointer; 
} 
.topnav {
    overflow-x: scroll;
    height: 150px;

  } 
.topnav a{
    float: left;
    text-decoration: none;
    font-size: 17px;
  }
  
  /* Change the color of links on hover */
.topnav a:hover {
    background: rgba(255,0,0,0.5) ;
    color: black
  }
  
  /* Add a color to the active/current link */
.topnav a.active {
    background-color: #04AA6D;
    color: rgb(15, 13, 13,0.5);
  }

I want something like this or these so that I can scroll horizontally...

Lastly, Advanced Thankyou for help!

use -webit-box example:

body {
 background-size: cover;
 background-repeat: no-repeat;
 color: #585858;
 margin: 0;
 padding: 0;
 font-family: 'Yaldevi', sans-serif;
 margin-top: 30px;
 box-sizing: border-box;
}


 h1, p, h3 {
  text-align: center;
   color: black;
 }
 a {
  text-decoration: none;
}

.circontain a{
  color: black;
  /* display: inline; */
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100px;
  width: 100px;
  /* line-height: 200px; */ 
  background-color: pink;
  border-radius: 50%;
  margin-left: 50px;
  text-align: center;
  margin-top: 100px;
  padding: 18px;
  border: none;
  cursor: pointer; 
} 
.topnav {
  height: auto;
  display: -webkit-box;
  overflow: auto;

 } 
 .topnav a{
  float: left;
  text-decoration: none;
  font-size: 17px;
 }

 /* Change the color of links on hover */
.topnav a:hover {
  background: rgba(255,0,0,0.5) ;
  color: black
 }

 /* Add a color to the active/current link */
.topnav a.active {
  background-color: #04AA6D;
  color: rgb(15, 13, 13,0.5);
 }

You can also take help from this code

<!DOCTYPE html>   
<html>
<head>
<meta name="viewport"   content="width=device-width, initial-scale=1">
<style>
div.scrollmenu {
  background-color: #333;
  overflow: auto;
  white-space: nowrap;
}

div.scrollmenu a {
  display: inline-block;
  color: white;
  text-align: center;
  padding: 14px;
  text-decoration: none;
}

div.scrollmenu a:hover {
  background-color: #777;
}
</style>
</head>
<body>

<div class="scrollmenu">
  <a href="#home">Home</a>
  <a href="#news">News</a>
  <a href="#contact">Contact</a>
  <a href="#about">About</a>
  <a href="#support">Support</a>
  <a href="#blog">Blog</a>
  <a href="#tools">Tools</a>  
  <a href="#base">Base</a>
  <a href="#custom">Custom</a>
  <a href="#more">More</a>
  <a href="#logo">Logo</a>
  <a href="#friends">Friends</a>
  <a href="#partners">Partners</a>
  <a href="#people">People</a>
  <a href="#work">Work</a>
</div>

<h2>Horizontal Scrollable Menu</h2>
<p>Resize the browser window to see the    effect.</p>

</body>
</html>

You can make overflow auto and scroll behaviour to the topnav or the navigation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM