gpt4 book ai didi

html - 如何用CSS使p元素和按钮水平对齐

转载 作者:行者123 更新时间:2023-12-03 08:26:15 26 4
gpt4 key购买 nike

我有一些文本(p 元素)和旁边的两个按钮。但是,这两个按钮看起来并不与文本(p 元素)在同一级别水平居中对齐。这些按钮似乎略低于文本。 enter image description here

如何让它们看起来水平在同一水平面上?

代码片段:

body {
background-color: rgb(44, 63, 83);
}

#timer {
margin-top: 1%;
}

#time-p {
color: white;
font-family: Helvetica, Arial, sans-serif;
font-size: 3rem;
display: inline-block;
color: black;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timer</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1b3bebea5a2a5a3b0a191e5ffe4ffe2" rel="noreferrer noopener nofollow">[email protected]</a>/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<!-- My own CSS -->
<link rel="stylesheet" href="style.css">
</head>

<body>
<div id="timer">
<p id="time-p">00:00:00</p>
<!-- Start and reset buttons -->
<button class="btn btn-success btn-lg">Start</button>
<button class="btn btn-danger btn-lg">Reset</button>
</div>

<!-- jQuery 3.5.1 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- BootStrap JS -->
<script src="https://cdn.jsdelivr.net/npm/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="23414c4c57505751425363170d160d10" rel="noreferrer noopener nofollow">[email protected]</a>/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx"
crossorigin="anonymous"></script>
</body>

</html>

最佳答案

使用“vertical-align”并调整“p”标签的默认“margin-bottom”。

body {
background-color: rgb(44, 63, 83);
}

#timer {
margin-top: 1%;
}

#time-p {
color: white;
font-family: Helvetica, Arial, sans-serif;
font-size: 3rem;
display: inline-block;
color: black;
vertical-align: middle;
margin-bottom: 0;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timer</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b1914140f080f091a0b3b4f554e5548" rel="noreferrer noopener nofollow">[email protected]</a>/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<!-- My own CSS -->
<link rel="stylesheet" href="style.css">
</head>

<body>
<div id="timer">
<p id="time-p">00:00:00</p>
<!-- Start and reset buttons -->
<button class="btn btn-success btn-lg">Start</button>
<button class="btn btn-danger btn-lg">Reset</button>
</div>

<!-- jQuery 3.5.1 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- BootStrap JS -->
<script src="https://cdn.jsdelivr.net/npm/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="37555858434443455647770319021904" rel="noreferrer noopener nofollow">[email protected]</a>/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx"
crossorigin="anonymous"></script>
</body>

</html>

关于html - 如何用CSS使p元素和按钮水平对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66560024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com