我尝试有一个响应的网页设计,但当我缩小我的浏览器大小,按钮是重叠我的文本部分,有人知道如何解决这个问题吗?第一张图片是正常的屏幕大小,第二张图片是缩小屏幕大小。我想显示像第一张图片,即使缩小屏幕大小。
HTML代码为
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quote API</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="button">
<button onclick="getQuote()">Give me a quote!</button>
</div>
<div id="para">
<p id="quote"></p>
<p id="quoteauthor">test</p>
</div>
<script src="script.js"></script>
</body>
</html>
CSS文件代码是
body{
background:rgb(68, 142, 226);
}
#para {
margin-top: 30%;
}
p {
text-align: center;
color:white;
}
button{
background:white;
border: 4px solid white;
border-radius:1em;
font-size:24px;
padding:1em 3em;
/*CSS center element trick*/
position: absolute;
top: 50%;
left: 50%;
-webkit-transform:
translate(-50%, -50%);
transform:
translate(-50%, -50%);
-webkit-transition-property:
all;
-webkit-transition-duration:
1s;
-webkit-transition-timing-function:
ease-out;
transition-property:
all;
transition-duration:
1s;
transition-timing-function:
ease-out;
}
button:hover{
background:green;
color:white;
font-size:34px;
/*the previous padding:1em 3em; is what enlarges the element on hover ***note that the unit em translates to the size of your font. example: font=24px then 1em = 24px*/
}
1条答案
按热度按时间2ledvvac1#
你绝对定位了你的按钮,这就把它从元素流中去掉了。你只需要使用一些布局技巧:例如,Flex或Grid。请参见下面的示例: