【发布时间】:2022-11-18 02:53:24
【问题描述】:
我是 html/css 和 javascript 的新手。我希望按钮在同一行上,并且可以水平滚动……问题是两个
- 我无法将它们全部放在一行中,而是有些要到第二行..
- 我不明白我怎么能把它们全部放在一起,这样我就可以水平滚动它们了……
作为附加图像,我希望这些圆圈在同一条线上......我所做的如下所示。但问题是其中一些圆圈显示在下一行...... 我的代码在下面 网址:
<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); }我想要 this 或 these 这样的东西,这样我就可以水平滚动了……
最后,提前感谢您的帮助!
【问题讨论】:
-
div.topnav.circontain { overflow-x: auto; }话虽如此,水平滚动是您应该始终努力避免在网页中出现的情况,而是在 ViewPort 宽度不足以显示内容时使用 CSS 媒体查询来更改布局。
标签: javascript html css scroll responsive