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>