【发布时间】:2017-03-25 19:10:35
【问题描述】:
我正在努力做到这一点,以便当我用户调整那里的窗口大小时,它不会在页面上移动任何东西,也不会调整任何东西的大小。但我仍然不希望该网站在不同的屏幕尺寸上看起来相同。因为现在网站会移动我的图像和按钮。按钮也会改变大小。
* {
box-sizing: border-box; }
#wrapper {
margin-left:auto;
margin-right:auto;
width:100%;
height: 100%;
}
body {
background-color: black;
font-family: "Source Sans Pro", sans-serif;
text-align: center;
color: #ccc;
}
div {
height: 100%;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
h3 {
position: absolute;
font-size: 100px;
font-weight: 100;
color: white;
margin-top: 70px;
margin-left: 80px;
}
img {
margin-top: 230px;
margin-right: 0px;
}
.home {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
font-size: 26px;
line-height: 60px;
width: 10%;
height: 60px;
margin-top: 180px;
margin-left: 500px;
}
.about {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
font-size: 26px;
line-height: 60px;
width: 10%;
height: 60px;
margin-top: 180px;
margin-left: 750px;
}
.projects {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
line-height: 60px;
width: 10%;
height: 60px;
font-size: 26px;
margin-top: 180px;
margin-left: 1000px;
}
.contact {
position: absolute;
border: 2px solid #CCCCCC;
text-align: center;
color: #ccc;
line-height: 60px;
font-size: 26px;
width: 10%;
height: 60px;
margin-top: 180px;
margin-left: 1250px;
}
.home:hover{
border-color: #0091FF;
color: #0091FF;
}
.about:hover{
border-color: #0091FF;
color: #0091FF;
}
.projects:hover{
border-color: #0091FF;
color: #0091FF;
}
.contact:hover{
border-color: #0091FF;
color: #0091FF;
}
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Play" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="styles.css" />
<script type="text/javascript" src="background.js"></script>
<title>Home</title>
</head>
<body>
<div id="wrapper">
<canvas class='connecting-dots'></canvas>
<h3>Title</h3>
<a href="#"><div class = "home">Home</div></a>
<a href="#"><div class = "about">About</div></a>
<a href="#"><div class = "projects">Projects</div></a>
<a href="#"><div class = "contact">Contact</div></a>
<img src="astronaut.png">
</div>
</body>
</html>
【问题讨论】:
-
为什么一切都是绝对位置?
-
Idk,我对 Web 开发有点陌生。
-
好的明白。所以你想要一个带有标题的标题菜单?但是为什么是那些画布和 img 呢?
-
画布使用 JavaScript 来创建浮动粒子,但我没有包含 JavaScript。我不认为这是造成问题的原因。
-
问题是你的 html 结构和 css 位置,margin-left 等。
标签: html css button resize responsive