【发布时间】:2023-04-07 22:57:02
【问题描述】:
我正在尝试进行打字测试,但在尝试将 textarea 准确地设置在中心时遇到了麻烦。我试过 align-items、align-self、align-content,但没有任何效果。这是我的代码的样子:
*{
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: "Impact";
}
body{
background-color: grey;
}
.container{
width: 80vmin;
padding: 50px 30px;
background-color: white;
position: absolute;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
border-radius: 10px;
box-shadow: 0 20px 40px;
}
.stats{
text-align: right;
font-size: 18px;
margin-bottom: 30px;
}
textarea{
align-content: center;
resize: none;
width: 100%;
border-radius: 5px;
padding: 10px 5px;
font-size: 16px;
margin:20px
}
button{
float: right;
margin-top: 20px;
background-color: gold;
color: black;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 18px;
margin: 10px;
}
button:hover{
background-color:rgb(66, 154, 209)
}
button:active{
background:#003659
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width,
initial-scale=1.0" />
<title>My Typing Test</title>
<link rel="stylesheet" href="Test.css" />
</head>
<body>
<div class="container">
<div class="stats">
<p>Time: <span id="time">0s</span></p>
<p>WPM: <span id="wpm">0</span></p>
</div>
<div id="words" onmousedown="return false"
onselect="return false">
</div>
<textarea rows="3"></textarea>
<div class= "ButtonControl">
<button id= "Start Timer">Start Test</button>
<button id= "Reload Page">Reset Test</button>
</div>
</div>
<script src="Test.js"></script>
</body>
</html>
即使用户尝试调整窗口大小,我如何使文本区域居中?
【问题讨论】:
-
这看起来像是 this question 的副本。
-
使用 flexbox,我会在几分钟内发送 da 代码