如何将篮球记分牌的得分文本居中?

问题描述 投票:0回答:1

我正在制作篮球记分板,我想知道如何将记分板容器内的得分文本居中?

虽然主 div 已设置为 Flex 容器,但记分板容器内的 p 分数文本不受对齐内容或对齐项目的影响。

我尝试使用 margin 0 auto 并使用 padding 将其居中,但这看起来一点都不好。

我将不胜感激任何帮助!

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
    <title>Home</title>
  </head>
  <body>
    <section class="container">
      <div>
        <h3>HOME</h3>
        <div class="scoreboard">
          <p>10</p>
        </div>
      </div>
      <div>
        <h3>GUEST</h3>
        <div class="scoreboard">
          <p>20</p>
        </div>
      </div>
    </section>
  </body>
</html>


body {
  margin: 0;
}

@font-face {
  font-family: cursed-timer;
  src: url(cursed-timer.ttf);
}

.container {
  margin: 100px auto;
  width: 600px;
  height: 425px;
  background-color: #150400;
  display: flex;
  justify-content: space-evenly;
  border-radius: 2px;
}

h3 {
  margin-top: 75px;
  color: #ffffff;
  font-size: 48px;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  letter-spacing: 1px;
}

.scoreboard {
  margin-top: -40px;
  width: 150px;
  height: 125px;
  border: 1px solid #ffffff;
  border-radius: 2px;
}

p {
  color: #ffa500;
  font-family: cursed-timer;
  font-size: 72px;
  margin: 0 auto;
  padding: 25px;
}
html css flexbox responsive-design centering
1个回答
0
投票

试试这个:

我只是将

text-align: center;
添加到包含乐谱文本的
<p>
中。

body {
  margin: 0;
}

@font-face {
  font-family: cursed-timer;
  src: url(cursed-timer.ttf);
}

.container {
  margin: 100px auto;
  width: 600px;
  height: 425px;
  background-color: #150400;
  display: flex;
  justify-content: space-evenly;
  border-radius: 2px;
}

h3 {
  margin-top: 75px;
  color: #ffffff;
  font-size: 48px;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  letter-spacing: 1px;
}

.scoreboard {
  margin-top: -40px;
  width: 150px;
  height: 125px;
  border: 1px solid #ffffff;
  border-radius: 2px;
}

p {
  text-align: center;
  color: #ffa500;
  font-family: cursed-timer;
  font-size: 72px;
  margin: 0 auto;
  padding: 25px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
  <title>Home</title>
</head>

<body>
  <section class="container">
    <div>
      <h3>HOME</h3>
      <div class="scoreboard">
        <p>10</p>
      </div>
    </div>
    <div>
      <h3>GUEST</h3>
      <div class="scoreboard">
        <p>20</p>
      </div>
    </div>
  </section>
</body>

</html>

© www.soinside.com 2019 - 2024. All rights reserved.