css - 如何修复我的搜索栏和按钮,同时重新调整我的右侧菜单?
问题描述
我正在尝试修复我的导航栏。我试图在我的搜索栏居中添加一个按钮。这只是 html 和 css 的练习,但我无法弄清楚为什么我的搜索按钮如此之小,以及为什么我的右侧菜单现在与我的<hr>
. 它应该是一个简单的youtube复制品......
*{
margin: 0;
padding: 0;
}
body{
font-family: Arial;
}
ul{
text-decoration: none;
}
.menuOne {
float: left;
word-spacing: 12px;
margin-top: 10px;
margin-right:30px;
margin-left: 10px;
}
.menuTwo {
float: right;
word-spacing: 12px;
margin-top: 10px;
margin-right:30px;
}
li{
display: inline;
}
.topNav .searchContainer{
text-align: center;
}
.topNav input[type=text] {
padding: 6px;
margin-top: 8px;
font-size: 17px;
border: 1px solid gray;
}
.topNav .searchContainer button {
padding: 6px 10px;
margin-top: 8px;
margin-right: 16px;
background: #ddd;
font-size: 17px;
border: 1px solid gray;
cursor: pointer;
}
hr.style-one {
border: 0;
height: 0px;
background: #333;
background-image: linear-gradient(to right, #ccc, #333, #ccc);
}
<!DOCTYPE html>
<html>
<head>
<title>Youtube</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<!--This is the nav bar for youtube-->
<nav class="topNav">
<ul class="menuOne">
<li>Menu</li>
<li>YouTube</li>
</ul>
<div class="searchContainer">
<input type="text" placeholder="Search...">
<button type="submit" class="searchButton"></button>
</div>
<ul class="menuTwo">
<li>Upload</li>
<li>YouTubeApps</li>
<li>Messages</li>
<li>Notifications</li>
<li>Profile</li>
</ul>
</nav>
<br>
<!--this is to seperate the nav from the containers bellow-->
<hr>
<!--Container for the video-->
<div class="videoContainer">
</div>
<!--Container for the description of the video, to go below
video-->
<div class="videoDescription">
</div>
<!--Side container for recommended videos-->
<div class="sideBar">
</div>
</body>
</html>
我怎样才能解决这个问题?
解决方案
您可以使用absolute
对齐搜索框的中心。但是menutwo的s太多了li
,所以我用了更小的不重叠的字体。
*{
margin: 0;
padding: 0;
}
body{
font-family: Arial;
}
ul{
text-decoration: none;
}
.menuOne {
float:left;
word-spacing: 12px;
margin-top: 10px;
margin-right:30px;
margin-left: 10px;
}
.menuTwo {
float:right;
word-spacing: 12px;
margin-top: 10px;
margin-right:30px;
font-size:11px;
}
li{
display: inline;
}
.topNav {overflow:hidden;position:relative;height:50px}
.topNav .searchContainer{
position:absolute;
width:240px;
top:8px;
left:50%;
margin-left:-100px;
text-align: center;
}
.topNav input[type=text] {
float:left;
width:138px;
padding: 6px 0;
font-size: 17px;
border: 1px solid gray;
}
.topNav .searchContainer button {
width:98px;
padding: 6px 0;
background: #ddd;
font-size: 17px;
border: 1px solid gray;
cursor: pointer;
}
hr.style-one {
border: 0;
height: 0px;
background: #333;
background-image: linear-gradient(to right, #ccc, #333, #ccc);
}
<div style="min-width:1000px;margin:0 auto">
<nav class="topNav">
<ul class="menuOne">
<li>Menu</li>
<li>YouTube</li>
</ul>
<div class="searchContainer">
<input type="text" placeholder="Search...">
<button type="submit" class="searchButton">Search</button>
</div>
<ul class="menuTwo">
<li>Upload</li>
<li>YouTubeApps</li>
<li>Messages</li>
<li>Notifications</li>
<li>Profile</li>
</ul>
</nav>
<br>
<!--this is to seperate the nav from the containers bellow-->
<hr>
<!--Container for the video-->
<div class="videoContainer">
</div>
<!--Container for the description of the video, to go below
video-->
<div class="videoDescription">
</div>
<!--Side container for recommended videos-->
<div class="sideBar">
</div>
</div>
推荐阅读
- python - 如何通过错误分析深入了解文本分类?
- .htaccess - 尝试通过 .HTACCESS 将站点上的所有流量重定向到 HTTP(非安全),但我的规则总是导致“无法显示页面”
- python - Python3 Panda 的假期无法找到过去任意时期的日期
- python - 子进程检查当前目录的输出/运行问题
- android - 具有 mutablelivedata 支持属性的观察到的 livedata 如何知道在从未直接更新时触发观察者?
- cakebuild - 我可以在 Cake 脚本中定义可重用的子例程/函数/方法吗?
- python - 修改正 x 的直方图曲线
- php - 使用 multipart/form-data POST 请求时从 ConnectWise API 获得无效响应
- r - 如何从字符串列表中创建对出现的二元关系矩阵?
- graph - 首次访问的节点形成一棵在 BFS 和 DFS 中具有相同边数的生成树