Heim > Fragen und Antworten > Hauptteil
P粉1555517282023-09-06 00:39:04
这就是你想要的吗?我已将 text-align: center;
添加到 #texts
以使两个文本元素居中。我已将父级 #box1
并添加 display: flex; justify-content: center;
所以基本上我已经使用 Flexbox 水平居中 #box1
。看起来就像你想要的。
h1 {
color: white;
font-family: "Libre Baskerville", cursive;
}
p {
color: white;
}
body {
background: black;
}
#texts {
text-transform: uppercase;
text-align: center;
}
#box1 {
border: 5px solid;
color: white;
width: 450px;
}
.container {
display: flex;
justify-content: center;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Libre+Baskerville&display=swap" rel="stylesheet" />
</head>
<body>
<div class="container">
<div id="box1">
<!-- <img src="max-harlynking-UdCNVHNgHdI-unsplash.jpg" alt="" width="100%" height="50%" /> -->
<img src="https://picsum.photos/640/480" alt="" width="100%" height="100%" />
</div>
</div>
<h1 id="texts">let's a go!!!</h1>
<p id="texts">we did it</p>
</body>
</html>