<p><strong>这是进球海报</strong></p>
<p><strong>这是我的海报</strong></p>
<p>你能读一下我的代码并告诉我我做错了什么/是否有更简单的方法
该项目是制作一个励志海报网站。</p>
<blockquote>
<p>TODO:创建一个励志帖子网站。
随心所欲地设计风格。
查看目标图像以获取灵感。
但它必须具备以下特点:</p>
<ol>
<li>主要的 h1 文本应使用 Google Fonts 中的 Regular Libre Baskerville 字体:
https://fonts.google.com/specimen/Libre+Baskerville</li>
<li>文本应为白色,背景为黑色。</li>
<li>将您自己的图像添加到资源内的图像文件夹中。它应该有一个 5 像素的白色边框。</li>
<li>文本应居中对齐。</li>
<li>创建一个 div 来包含 h1、p 和 image 元素。调整页边距,使图像和文本位于页面中央。
提示:通过将 div 的宽度设置为 50%,将其左边距设置为 25%,从而将其水平居中。
提示:将图像宽度设置为 100%,以填充 div。</li>
<li>阅读 MDN 文档上的 text-transform 属性,以使用 CSS 将 h1 变为大写。
https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform</li>
</ol>
</blockquote>
<p>
<pre class="brush:css;toolbar:false;">h1 {
color: white;
font-family: 'Libre Baskerville', cursive;
}
p {
color: white
}
body {
background: black;
}
#texts {
text-transform: uppercase;
}
#box1 {
border: 5px solid;
text-align: center;
color: white;
width: 450px;
height: 500px;
padding-top: 50px;
}
div {
width: 50%;
height: 100%;
margin-left: 25%;
margin-top: 25%;
}</pre>
<pre class="brush:html;toolbar:false;"><!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 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="50%" />
<h1 id="texts">let's a go!!!</h1>
<p id="texts">we did it</p>
</div>
</body>
</html></pre>
</p>
<p>图片在最小化时应居中(占据屏幕的一半),看起来不错,但在充满时,其居中但位于底部。</p>
<p><em>我才刚刚开始学习,所以我只知道 html 和 CSS 的最基本的</em>*</p>
这就是你想要的吗?我已将 添加到
text-align: center;
添加到#texts
以使两个文本元素居中。我已将父级#box1
并添加display: flex; justify-content: center;
所以基本上我已经使用 Flexbox 水平居中#box1
。看起来就像你想要的。