我正在为学校开展一个网络项目,这让我现在走到了尽头。我目前正在为我的页面构建导航栏,我希望将徽标图像嵌套到导航栏的左侧部分。任何建议都会很棒!
注意:我提前道歉,我无法弄清楚jsfiddle。太多的错误。
body {
font-family: 'Roboto', sans-serif;
padding: 0;
margin: 0;
background: lightblue;
}
small {
font-size: 12px;
color: rgba(0, 0, 0, 0.4);
}
h1 {
text-align: center;
padding: 50px 0;
font-weight: 800;
margin: 0;
letter-spacing: -1px;
color: inherit;
font-size: 40px;
}
h2 {
text-align: center;
font-size: 30px;
margin: 0;
font-weight: 300;
color: inherit;
padding: 50px;
}
.center {
text-align: center;
}
section {
height: 50vh;
}
/* NAVIGATION */
nav {
width: 60%;
margin: 0 auto;
background: #d67ca8;
padding: .25px 0;
box-shadow: 0px 5px 0px #dedede;
}
nav ul {
list-style: none;
text-align: center;
}
nav ul li {
display: inline-block;
}
nav ul li a {
display: block;
padding: 15px;
text-decoration: none;
color: black;
font-weight: 800;
text-transform: uppercase;
margin: 0 1px;
}
nav ul li a,
nav ul li a:after,
nav ul li a:before {
transition: all .5s;
}
nav ul li a:hover {
color: #555;
}
/* stroke */
nav.stroke ul li a,
nav.fill ul li a {
position: relative;
}
nav.stroke ul li a:after,
nav.fill ul li a:after {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0%;
content: '.';
color: transparent;
background: #aaa;
height: 1px;
}
nav.stroke ul li a:hover:after,
nav.stroke ul li a.active:after {
width: 100%;
}
nav.fill ul li a {
transition: all 2s;
}
nav.fill ul li a:after {
text-align: left;
content: '.';
margin: 0;
opacity: 0;
}
nav.fill ul li a:hover,
nav.fill ul li a.active {
color: #fff;
z-index: 1;
}
nav.fill ul li a:hover:after,
nav.fill ul li a.active:after {
z-index: -10;
animation: fill 1s forwards;
-webkit-animation: fill 1s forwards;
-moz-animation: fill 1s forwards;
opacity: 1;
}
/* Keyframes */
@-webkit-keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #333;
}
}
/* IMAGES */
#navlogo {}

<html>
<head>
<title>Title | Home</title>
<link href='http://fonts.googleapis.com/css?family=Roboto:500,900,100,300,700,400' rel='stylesheet' type='text/css'>
<link rel="icon" type="text/css" sizes="32x32" href="images/favicon1-32x32.png" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<meta charset="utf-8" />
</head>
<body>
<nav class="fill">
<ul>
<li>
<img id="navlogo" src="images/logo-72x72.png"></img>
<li><a href="index.html" class="active">Home</a>
</li>
<li><a href="#">About</a>
</li>
<li><a href="#">Downloads</a>
</li>
<li><a href="#">More</a>
</li>
<li><a href="#">Contact</a>
</li>
</ul>
</nav>
</body>
</html>
&#13;
答案 0 :(得分:1)
您好,我更改了一些不合适的HTML代码,并准备了一些样式 你想要的。
我希望这段代码可以帮到你。
body {
font-family: 'Roboto', sans-serif;
padding: 0;
margin: 0;
background: lightblue;
}
small {
font-size: 12px;
color: rgba(0, 0, 0, 0.4);
}
h1 {
text-align: center;
padding: 50px 0;
font-weight: 800;
margin: 0;
letter-spacing: -1px;
color: inherit;
font-size: 40px;
}
h2 {
text-align: center;
font-size: 30px;
margin: 0;
font-weight: 300;
color: inherit;
padding: 50px;
}
.center {
text-align: center;
}
section {
height: 50vh;
}
/* NAVIGATION */
.logo{
float: left;
max-width: 50px;
width: 100%;
height:50px;
display: inline-block;
}
.logo a{
max-width: 100%;
width: 100%;
display: block;
}
.logo a img{
max-width: 100%;
height: auto;
}
nav {
width: 60%;
margin: 0 auto;
background: #d67ca8;
padding: .25px 0;
box-shadow: 0px 5px 0px #dedede;
}
nav ul {
list-style: none;
text-align: center;
}
nav ul li {
display: inline-block;
}
nav ul li a {
display: block;
padding: 15px;
text-decoration: none;
color: black;
font-weight: 800;
text-transform: uppercase;
margin: 0 1px;
}
nav ul li a,
nav ul li a:after,
nav ul li a:before {
transition: all .5s;
}
nav ul li a:hover {
color: #555;
}
/* stroke */
nav.stroke ul li a,
nav.fill ul li a {
position: relative;
}
nav.stroke ul li a:after,
nav.fill ul li a:after {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0%;
content: '.';
color: transparent;
background: #aaa;
height: 1px;
}
nav.stroke ul li a:hover:after,
nav.stroke ul li a.active:after {
width: 100%;
}
nav.fill ul li a {
transition: all 2s;
}
nav.fill ul li a:after {
text-align: left;
content: '.';
margin: 0;
opacity: 0;
}
nav.fill ul li a:hover,
nav.fill ul li a.active {
color: #fff;
z-index: 1;
}
nav.fill ul li a:hover:after,
nav.fill ul li a.active:after {
z-index: -10;
animation: fill 1s forwards;
-webkit-animation: fill 1s forwards;
-moz-animation: fill 1s forwards;
opacity: 1;
}
/* Keyframes */
@-webkit-keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #333;
}
}
<html>
<head>
<title>Title | Home</title>
<link href='http://fonts.googleapis.com/css?family=Roboto:500,900,100,300,700,400' rel='stylesheet' type='text/css'>
<link rel="icon" type="text/css" sizes="32x32" href="images/favicon1-32x32.png" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<meta charset="utf-8" />
</head>
<body>
<nav class="fill">
<ul>
<div class="logo"><a href="index.html"><img src="images/logo-72x72.png"></a></div>
<li><a href="index.html" class="active">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">More</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</body>
</html>
答案 1 :(得分:0)
不太可能解决你的问题 - 但是为了教学 - 你试图在另一个里面嵌入一系列的李 - 这是不正确的 - 你需要在里面嵌入一个UL。 - img标签也是自我关闭所以你我们/&gt;您还应该为所有图像添加ALT文本(以及尺寸属性..
请注意,我不建议这样做 - 但是要回答关于嵌套的问题 - 将li与li一起嵌入li中是好的 - 但不能单独使用它们。
<nav class="fill">
<ul>
<li>
<img id="navlogo" src="images/logo-72x72.png" alt ="logo" width="72" height ="72"/>
<ul>
<li><a href="index.html" class="active">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">More</a></li>
<li><a href="#">Contact</a></li>
</ul>
</li>
</ul>
</nav>
答案 2 :(得分:0)
<img id="navlogo" class = "brand" src="images/logo-72x72.png"></img>
为类添加名称,例如:品牌,并尝试此
.brand {height: 25px;}