gpt4 book ai didi

html - 无法让 CSS 菜单正确对齐

转载 作者:太空宇宙 更新时间:2023-11-04 13:24:09 24 4
gpt4 key购买 nike

所以下面是制作您在底部看到的图片的所有代码。我正在尽最大努力让这个网站响应,但现在的主要问题是菜单栏没有居中(垂直), Logo 在左边。我怎样才能让它在那里居中?我尝试将顶部设置为 50%,但它保持原样。现在由于某种原因背景颜色红色只包含菜单栏,即使 Logo 应该在其中。感谢您的帮助。

HTML:

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bond Solutions | Home</title>
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="menubar.css" />
<script type="text/javascript">
var video;
window.onload = function () {
window.video = document.getElementById("video");
window.video.addEventListener('ended',myHandler,false);
window.video.volume=0.5;
}
function myHandler() {
window.video.currentTime = 7;
window.video.volume=0;
window.video.play();
}
</script>
</head>

<body>
<center>
<div id="site">
<div id="header">
<img class="logo" src="images/logo.svg" />
<div id="menu">
<ul id="menu-bar">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="#">Products</a>
<ul>
<li><a href="#">Stock Photos</a></li>
<li><a href="#">Stock Videos</a></li>
</ul>
</li>
<li><a href="#">Services</a>
<ul>
<li><a href="#">Web Design</a></li>
<li><a href="#">Graphic Design</a></li>
<li><a href="#">Computer Repair</a></li>
<li><a href="#">Computer Cleaning</a></li>
<li><a href="#">Custom Computers</a></li>
<li><a href="#">Retro Console Refurbishing</a></li>
</ul>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
</div>
</center>
</body>
</html>

CSS:

body {
background-color: #000;
}
#site {
background-color:#0F0;
width:75%;
}
#header {
position:relative;
background-color:red;
height:50%;
width:100%;
}
.logo {
width:auto;
max-width:100%;
height:auto;
float:left;
}
#menu {
top:50%;
}
#menu ul ul {
display: none;
}

#menu ul li:hover > ul {
display: block;
}
#menu ul{
background: #AC2828;
background: linear-gradient(top, #AC2828 0%, #A31010 100%);
background: -moz-linear-gradient(top, #AC2828 0%, #A31010 100%);
background: -webkit-linear-gradient(top, #AC2828 0%,#A31010 100%);
box-shadow: 0px 0px 8px #A31010;
padding: 0 20px;
border-radius: 10px;
list-style: none;
position: relative;
display: inline-table;
}
#menu ul li {
float: left;
border-right:1px solid #8A0000;
}
#menu ul li:last-child{
border-right:none;
}

#menu ul li:hover {
background: #4b545f;
background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
background: -webkit-linear-gradient(top, #811919 0%,#680000 40%);
}

#menu ul li:hover a {
color: #fff;
}

#menu ul li a {
font-family: 'Pathway Gothic One', sans-serif;
font-size:14px;
display: block;

padding: 14px 40px;
color: #fff; text-decoration: none;
}
#menu ul ul {
background: #811919; border-radius: 0px; padding: 0;
position: absolute;
}
#menu ul ul li {
float: none;
border-top: 1px solid #680000;
border-bottom: 1px solid #8F3333;
position: relative;
}
#menu ul ul li a {
padding: 14px 40px;
color: #fff;
}

#menu ul ul li a:hover {

background: #AC2828;
}

图片: Failure

最佳答案

要使 Logo 正确适合标题,您需要向标题添加 clearfix。

 <div style="clear:both;"></div>

在结尾 </div> 之前添加它标题。

然后让它居中对齐:

#header {
position:relative;
background-color:red;
height:50%;
display: table;
width:100%;
}

#menu {
display: table-cell;
vertical-align: middle;
}

DEMO

关于html - 无法让 CSS 菜单正确对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23840909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com