最近心血来潮,想学习Html和CSS。 想在网页上显示一个横幅题头图像,然后在图像下方放上菜单,比如 “关于我们” “ 新闻”之类的,写了两行代码,竟然也工作了,可是在手机上看图像却只显示了一半。我心里想着做一个responsive 的网页的,在什么平台都可以看到网页内容。想着这里高手多,能不能帮我看一下我的代码,希望只是一两句的指点,不会耽误您太多时间
先谢谢大家了
我的css 文件
.bg-img {
/* The image used */
background-image: url("logo.png");
min-height: 160px;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/* Needed to position the navbar */
position: relative;
}
/* Position the navbar container inside the image */
.container {
position: absolute;
top:150px;
margin: 20px;
width: 1000px;
}
/* The navbar */
.topnav {
overflow: hidden;
background-color: blue;
}
/* Navbar links */
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
我的html文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="mystyle.css"></a>
</head>
<body>
<div class="bg-img">
<div class="container">
<div class="topnav">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
</div>
</div>
</body>
</html>