我正在尝试制作一些网页布局。到目前为止我所拥有的是这个。
我试图让按钮与导航栏位于同一水平线上。换句话说,我希望“显示日期”按钮直接位于“主页”导航按钮的右侧。我无法更改按钮上的边距 - 它会自行调整到导航栏的底部边框,例如,在边距为 0 时,它直接位于导航栏的底部边框下方(如您在屏幕截图中看到的那样)。
抱歉,如果代码混乱或难以阅读,我还处于初级阶段。
这是它的代码 -
<!DOCTYPE html>
<html>
<head>
<!-- *****CSS CODE START*****-->
<style type="text/css">
/*navigation bar*/
ul {
list-style-type:none;
margin:50;
padding:0;
}
a:link, a:visited {
display:block;
font-weight:bold;
color:#dd731c;
background-color:#473e36;
width:120px;
text-align:center;
padding:4px;
text-decoration:none;
text-transform:uppercase;
}
a:hover, a:active {
background-color:#bea792;
}
a:hover {
color:black;
}
a:active {
color:#dd731c;
}
/*button margins*/
button.button1 {
margin-top:0px;
margin-bottom:10px;
margin-right:50px;
margin-left:200px;
}
button.button2 {
margin-top:0px;
margin-bottom:10px;
margin-right:50px;
margin-left:200px;
}
button.button3 {
margin-top:0px;
margin-bottom:10px;
margin-right:50px;
margin-left:200px;
}
/*line*/
#middle hr.line {
height: 1px;
margin: 0 30px 5px 30px;
}
/*other*/
body {
background-color:#473e36;
}
h1 {
color:orange;
text-align:center;
}
p {
font-family:"Times New Roman";
font-size:20px;
}
</style>
<!-- *****CSS CODE END***** -->
</head>
<!-- *****HTML CODE START***** -->
<body>
<h1>title</h1>
<!-- line -->
<hr class="line">
<!-- navigation bar list -->
<ul>
<li>
<a href="#home">Home</a>
</li>
<li>
<a href="#news">News</a>
</li>
<li>
<a href="#contact">Contact</a>
</li>
<li>
<a href="http://www.google.com">About</a>
</li>
</ul>
<!-- buttons -->
<button type="button" button class="button1" onclick="displayDate()">Display Date</button>
<text id="demo">This is a paragraph.</text>
<br />
<button type="button" button class="button2" onclick="displayName()">Display Naaaame</button>
<br />
<button type="button" button class="button3" onclick="count()">count!</button>
<text id="counter">0</text>
</body>
<!-- *****HTML CODE END***** -->
</html>
<!-- *****JavaScript CODE START***** -->
<script type="text/javascript">
var currentNum = 1;
function displayDate() {
document.getElementById("demo").innerHTML = Date();
}
function displayName() {
document.getElementById("demo").innerHTML = "jim";
}
function count() {
document.getElementById("counter").innerHTML = currentNum;
currentNum = ++currentNum;
}
</script>
<!-- *****JavaScript CODE END***** -->