我正在尝试做一个小的网页布局。我到目前为止有什么is this。如何将内容与列表放在同一行上?
我试图让导航栏在同一水平线上的按钮。换句话说,我希望“显示日期”按钮直接位于“主页”导航按钮的右侧。我无法更改按钮的边距 - 它将自身调整为导航栏的底部边框,如边距为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***** -->
总是得到你的样品有无关的问题,摆脱所有代码。 –
您应该将导航栏(和其他部分)放在'div'标签中,以便在页面上创建部分。 – JSW189
对不起Seth,我不确定哪些部分对此很重要。 和JSW,我看到了div标签,但对它们的工作方式有点困惑 - 他们是否创建了一个“范围”,以便我可以在2个不同的div标签中使用相同的类名来引用不同的东西? – user1472747