簡體   English   中英

我可以為導航欄添加水平滾動條嗎? 如何?

[英]Can I add horizontal scroll bar for nav bar? how?

我是 html/css 和 javascript 的新手。我希望按鈕在同一行上,並且可以水平滾動……問題是兩個

  1. 我無法將它們全部放在一條線上,而是有些會進入第二線......
  2. 我不明白我怎么能把它們放在一起,這樣我就可以水平滾動它們了……

作為附加圖像,我希望這些圓圈在同一條線上......我所做的如下所示。 但問題是這些圓圈中的一些顯示在下一行......我的代碼在 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);
  }

我想要這樣這些的東西,以便我可以水平滾動......

最后,高級謝謝你的幫助!

使用 -webit-box 示例:

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

您也可以從此代碼中獲取幫助

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

您可以將溢出自動和滾動行為設置為頂部導航或導航。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM