Home > database >  Can I add horizontal scroll bar for nav bar? how?
Can I add horizontal scroll bar for nav bar? how?

Time:11-18

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 >
            <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!

CodePudding user response:

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);
 }

CodePudding user response:

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

  • Related