我已经尝试学习css大约两个月了,但我偶然发现无法将这两个div放在同一行。我的标志出现在标题栏上,但我的登录按钮不会出现在上面?
另外,如果你能告诉我如何缩短我的css代码来做同样的事情,那也太棒了!
@import url(http://fonts.googleapis.com/css?family=Oswald:400,700);
*{
margin: 0px;
padding: 0px;
}
.headerMenu {
background-color: #00B9ED;
height: 60px;
border-bottom: 0px;
padding-left: auto;
padding-right: auto;
width: 100%;
-webkit-box-shadow: 0px 0px 8px 0px #000000;
-moz-box-shadow: 0px 0px 8px 0px #000000;
box-shadow: 0px 0px 8px 0px #000000;
}
#logo {
margin-left: 15%;
}
#logo a {
padding-top: 3px;
height: 38px;
font-size: 35px;
font-family: 'Oswald', sans-serif;
text-decoration: none;
color: #FFFFFF;
}
#nav {
width: 100px;
height: 40px;
background-color: #00B9ED;
moz-border-radius: 15px;
-webkit-border-radius: 15px;
border: 3px solid #e5e5e5;
padding: 5px;
font-family: 'Oswald', sans-serif;
color: white;
text-align: center;
margin-left: 60%;
}
#nav p {
margin-top: 8%;
}
#nav a {
color: white;
}
#nav a:link {text-decoration:none}
#nav a:visited { text-decoration:none}
#nav a:hover {text-decoration:none; opacity: 0.6;}
<!DOCTYPE html>
<html>
<head>
<title>Daily Quotes</title>
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<body>
<div class="headerMenu">
<div id="logo">
<h2><a href="#">Daily Quotes</a></h2>
</div>
<div id="nav">
<p><a href="#">login</a></p>
</div>
</div>
</body>
</html>
尝试放入float:left;在您的#徽标上
#logo {
margin-left: 15%;
float:left;
}
@import url(http://fonts.googleapis.com/css?family=Oswald:400,700);
*{
margin: 0px;
padding: 0px;
}
.headerMenu {
background-color: #00B9ED;
height: 60px;
border-bottom: 0px;
padding-left: auto;
padding-right: auto;
width: 100%;
-webkit-box-shadow: 0px 0px 8px 0px #000000;
-moz-box-shadow: 0px 0px 8px 0px #000000;
box-shadow: 0px 0px 8px 0px #000000;
}
#logo {
margin-left: 15%;
float:left;
}
#logo a {
padding-top: 3px;
height: 38px;
font-size: 35px;
font-family: 'Oswald', sans-serif;
text-decoration: none;
color: #FFFFFF;
}
#nav {
width: 100px;
height: 40px;
background-color: #00B9ED;
moz-border-radius: 15px;
-webkit-border-radius: 15px;
border: 3px solid #e5e5e5;
padding: 5px;
font-family: 'Oswald', sans-serif;
color: white;
text-align: center;
margin-left: 60%;
}
#nav p {
margin-top: 8%;
}
#nav a {
color: white;
}
#nav a:link {text-decoration:none}
#nav a:visited { text-decoration:none}
#nav a:hover {text-decoration:none; opacity: 0.6;}
<!DOCTYPE html>
<html>
<head>
<title>Daily Quotes</title>
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<body>
<div class="headerMenu">
<div id="logo">
<h2><a href="#">Daily Quotes</a></h2>
</div>
<div id="nav">
<p><a href="#">login</a></p>
</div>
</div>
</body>
</html>