有谁知道如何防止“看直播”和“骰子游戏”那样移动吗?
HTML:
<!doctype html>
<html>
<head>
<meta charset="UTC-8">
<title>RLESSON85</title>
<link href="main.css" rel="stylesheet">
</head>
<body>
<h1 class="index"><a href="index.html">HOME</a></h1>
<h1 id="indextitle">RLEESON85</h1>
<h1 id="stream"><a href="http://www.twitch.tv/rleeson85">WATCH THE STREAM</a></div>
<h1 id="dice"><a href="dice.html">DICE GAME</a></h1>
</body>
</html>
CSS:
body {
background: #333;
}
footer {
}
.index {
font-family: bebas neue;
font-size: 33px;
font-style: inherit;
font-weight: inherit;
color: white;
letter-spacing: 3px;
float: left;
margin-left: 30px;
background: transparent;
height: 60px;
width: 140px;
line-height: 60px;
text-align: center;
border-style: solid;
border-width: 2px;
border-radius: 6px;
transition: all 0.3s ease 0s;
}
#indextitle {
font-family: bebas neue;
font-size: 190px;
font-style: inherit;
font-weight: inherit;
color: white;
letter-spacing: 5px;
position: absolute;
top: 30%;
left: 50%;
transform: translateX(-50%) translatey(-50%);
}
#dicetitle {
font-family: bebas neue;
font-size: 160px;
font-style: inherit;
font-weight: inherit;
color: white;
letter-spacing: 5px;
position: absolute;
top: 30%;
left: 50%;
transform: translateX(-50%) translatey(-50%);
}
#stream {
font-family: bebas neue;
font-size: 33px;
font-style: inherit;
font-weight: inherit;
color: white;
letter-spacing: 3px;
position: absolute;
top: 56%;
left: 50%;
transform: translateX(-50%) translatey(-50%);
background: transparent;
height: 60px;
width: 320px;
line-height: 60px;
text-align: center;
border: 0;
border-style: solid;
border-width: 2px;
border-radius: 6px;
transition: all 0.3s ease 0s;
}
#dice {
font-family: bebas neue;
font-size: 33px;
font-style: inherit;
font-weight: inherit;
color: white;
letter-spacing: 3px;
position: absolute;
top: 66%;
left: 50%;
transform: translateX(-50%) translatey(-50%);
background: transparent;
height: 60px;
width: 200px;
line-height: 60px;
text-align: center;
border: 0;
border-style: solid;
border-width: 2px;
border-radius: 6px;
transition: all 0.3s ease 0s;
}
.index:hover {
font-family: bebas neue;
font-size: 33px;
font-style: inherit;
font-weight: inherit;
color: white;
letter-spacing: 3px;
float: left;
margin-left: 40px;
background: #777;
height: 60px;
width: 120px;
line-height: 60px;
text-align: center;
border-style: solid;
border-width: 2px;
border-radius: 6px;
transition: all 0.3s ease 0s;
}
#stream:hover {
font-family: bebas neue;
font-size: 33px;
font-style: inherit;
font-weight: inherit;
color: white;
letter-spacing: 3px;
position: absolute;
top: 56%;
left: 50%;
transform: translateX(-50%) translatey(-50%);
background: #777;
height: 60px;
width: 300px;
line-height: 60px;
text-align: center;
border: 0;
border-style: solid;
border-width: 2px;
border-radius: 6px;
transition: all 0.3s ease 0s;
}
#dice:hover {
font-family: bebas neue;
font-size: 33px;
font-style: inherit;
font-weight: inherit;
color: white;
letter-spacing: 3px;
position: absolute;
top: 66%;
left: 50%;
transform: translateX(-50%) translatey(-50%);
background: #777;
height: 60px;
width: 180px;
line-height: 60px;
text-align: center;
border: 0;
border-style: solid;
border-width: 2px;
border-radius: 6px;
transition: all 0.3s ease 0s;
}
a:link {
text-decoration: none;
color: white;
}
a:visited {
text-decoration: none;
color: white;
}
最佳答案
不要单独定位每个元素,而是定位整个 block 。
另外,你不应该使用 <h1>
对于一切。
<head>
<meta charset="UTC-8">
<title>RLESSON85</title>
<link href="main.css" rel="stylesheet">
</head>
<body>
<div class="index"><a href="index.html">HOME</a></div>
<div class="maingroup">
<h1 id="indextitle">RLEESON85</h1>
<div id="stream"><a href="http://www.twitch.tv/rleeson85">WATCH THE STREAM</a></div>
<div id="dice"><a href="dice.html">DICE GAME</a></div>
</div>
</body>
CSS
.maingroup {
position: absolute;
top: 50%;
height: 450px;
margin-top: -225px;
text-align: center;
}
#stream, #dice {
margin: 0 auto 20px;
}
See the JSFiddle
关于html - 如何在调整页面大小时防止 div 移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28534328/