*{ padding: 0px; margin: 0px; } #box{ width: 1500px; height: 500px; background-color: black; } #timer { width: 300px; height: 300px; border-radius: 50%; border: 5px dashed #2fa4e4; position: relative; color: aliceblue; } #timer #Tim { position: absolute; left: 60px; top: 30px; text-align: center; font-size: 80px; color: darkgrey; } #timer #m { position: absolute; top: 120px; left: 60px; font-size: 90px; font-weight: bold; } #timer #s { position: absolute; top: 120px; right: 60px; font-size: 90px; font-weight: bold; } #m-s #s1{ position: absolute; top: 110px; left: 110px; font-size: 30px; font-weight: bold; } #m-s #s2{ position: absolute; top: 110px; right: 75px; font-size: 30px; font-weight: bold; } #timer #ms { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); font-size: 70px; font-weight: bold; } #buttons { display: flex; justify-content: center; margin-top: 20px; } #buttons button { background-color: orange; color: black; font-size: 16px; padding: 10px 20px; margin: 0 10px; border-radius: 5px; border: none; cursor: pointer; } </style> </head> <body> <div id="box"> <div id="timer"> <div id="Tim">Timer</div> <div id="m-s"><span id="s1">m</span><span id="s2">s</span></div> <div id="m">00</div> <div id="s">00</div> <div id="ms">00</div> </div> <div id="buttons"> <button id="start">开始</button> <button id="pause">暂停</button> <button id="reset">复位</button> </div> </div>更改样式使秒表位于画布的水平垂直中心,按钮位于秒表的整下放一次排列
时间: 2023-09-22 08:07:39 浏览: 177
可以使用flex布局来实现秒表和按钮的居中和底部排列。具体的样式代码如下:
```
#box {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100%;
height: 100%;
background-color: black;
position: relative;
}
#timer {
width: 300px;
height: 300px;
border-radius: 50%;
border: 5px dashed #2fa4e4;
position: relative;
color: aliceblue;
}
#buttons {
display: flex;
justify-content: center;
align-items: flex-end;
position: absolute;
bottom: 0;
margin-bottom: 20px;
}
#buttons button {
background-color: orange;
color: black;
font-size: 16px;
padding: 10px 20px;
margin: 0 10px;
border-radius: 5px;
border: none;
cursor: pointer;
}
```
需要注意的是,需要给父容器#box设置flex布局,并设置justify-content和align-items属性为center,使其水平垂直居中。同时,需要给#buttons设置position: absolute和bottom: 0属性,使其位于父容器的底部。
阅读全文