gpt4 book ai didi

html - 带有图像的水平导航栏; CSS 不显示 "inline"

转载 作者:行者123 更新时间:2023-11-28 08:02:06 25 4
gpt4 key购买 nike

我是 html 和 css 的新手。我试图让我的导航栏水平显示,并在文本链接上方显示背景图像。

这是我失败/尝试的代码:

CSS:

#aside_sect_mm {
margin: 0px;
background-position: 0%;
background-color: #004E27;
max-width: 704px;
max-height: 100px;
background-repeat: no-repeat;
position: relative;
}

#aside_sect_mm nav {
text-align: justify;
max-width: 704px;
width: 100%;
max-height: 100px;
margin-top: 0%;
padding: 0px;
display: inline-block;
position: relative;
}

#aside_sect_mm nav ul {
padding: 0px 0px 0px 0px;
max-height: 100px;
max-width: 704px;
position: relative;
display: inline-block;
}
#aside_sect_mm nav ul li {
font-size: 1.1em;
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-weight: lighter;
text-align: justify;
list-style: none;
line-height: 3.5em;
position: relative;
padding: 30px 0px 0px 0px;
margin-left: 4.5em;
max-height: 100px;
color: #FCE011;
display: inline-block;
position: relative;
}

#aside_sect_mm nav ul li.bio_icon, #aside_sect_mm nav ul li.stat_icon, #aside_sect_mm nav ul li.img_icon, #aside_sect_mm nav ul li.vid_icon, #aside_sect_mm nav ul li.fut_icon {
position: relative;
max-height: 100px;
max-width: 50%;
background-repeat: no-repeat;
background-position: 50% 0%;
display: block;
}


#aside_sect_mm nav ul li.bio_icon {
background-image: url(../svg/bio_ore_ylw.svg);
}

#aside_sect_mm nav ul li.stat_icon {
background-image: url(../svg/stats_ore_ylw.svg);
}

#aside_sect_mm nav ul li.img_icon {
background-image: url(../svg/img_ore_ylw.svg);
}

#aside_sect_mm nav ul li.vid_icon {
background-image: url(../svg/vids_ore_ylw.svg);
}

#aside_sect_mm nav ul li.fut_icon {
background-image: url(../svg/fut_ore_ylw.svg);
}

#aside_sect_mm nav ul li.bio_icon a, #aside_sect_mm nav ul li.stat_icon a, #aside_sect_mm nav ul li.img_icon a, #aside_sect_mm nav ul li.vid_icon a, #aside_sect_mm nav ul li.fut_icon a {
position: relative;
display: block;
max-height: 100px;
max-width: 50%;
text-decoration: none;
color: #F6EF1B;
}

#aside_sect_mm nav ul li.bio_icon a:hover, #aside_sect_mm nav ul li.stat_icon a:hover, #aside_sect_mm nav ul li.img_icon a:hover, #aside_sect_mm nav ul li.vid_icon a:hover, #aside_sect_mm nav ul li.fut_icon a:hover {
position: relative;
max-height: 100px;
max-width: 50%;
display: block;
background-color: #F6EF1B;
background-repeat: no-repeat;
background-position: -26px 0%;
text-decoration: none;
color: #004E27;
}

#aside_sect_mm nav ul li.bio_icon a:hover {
background-image: url(../svg/bio_ore_grn.svg);
}

#aside_sect_mm nav ul li.stat_icon a:hover {
background-image: url(../svg/stats_ore_grn.svg);
}

#aside_sect_mm nav ul li.img_icon a:hover {
background-image: url(../svg/img_ore_grn.svg);
}

#aside_sect_mm nav ul li.vid_icon a:hover {
background-image: url(../svg/vids_ore_grn.svg);
}

#aside_sect_mm nav ul li.fut_icon a:hover {
background-image: url(../svg/fut_ore_grn.svg);
}

And the HTML:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="css/test.css">
</head>

<body>
<section id="aside_sect_mm">
<nav>
<ul>
<li class="bio_icon"><a href="#bio">Bio</a></li>
<li class="stat_icon"><a href="#stats">Stats</a></li>
<li class="img_icon"><a href="#images">Images</a></li>
<li class="vid_icon"><a href="#videos">Videos</a></li>
<li class="fut_icon"><a href="#future">Future</a>
</ul>
</nav>
</section>

</body>
</html>

如果有人的专业知识可以为我指明正确的方向,我将不胜感激。

最佳答案

这里确实有很多需要更改的地方,但我将从研究“水平对齐”开始。在这种情况下,您需要将这些元素 (nav ul li) 显示设置为“inline-block”。关于背景图像,您遗漏了引号 ("../svg/..."),我相信您希望图像出现在“li”上,而不是“a”上。我为您创建了一个 jsfiddle 来尝试一些新事物,从您正在寻找的开始:http://jsfiddle.net/keddkyz5/1/ .关键的 CSS 更改是:

#aside_sect_mm nav ul li.bio_icon 
{
background-image: url("http://static.guim.co.uk/sys-images/Guardian/Pix/pictures/2014/4/11/1397210130748/Spring-Lamb.-Image-shot-2-011.jpg");
width: 100px;
}

#aside_sect_mm nav ul li
{
display: inline-block !important;
}

我必须添加 !important 来强制使用 css...您可能希望避免这种情况,并简单地深入了解 css 特异性的细节(这里很酷的文章:http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/)。

关于html - 带有图像的水平导航栏; CSS 不显示 "inline",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29704892/

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