在div内的css中将内容对齐?

时间:2017-10-17 08:20:59

标签: html css

如何将<span id="milliseconds">00</span>对齐?

请参阅以下工作代码:

@font-face {
  font-family: "Digi";
  src: url("fonts/ds-digib.ttf");
}

body {
  font-family: Arial;
  font-size: 80px;
  font-weight: bold;
  padding: 40px 0;
}

#container {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

#splits {
  font-size: 40px;
  padding: 0px;
  font-weight: normal;
}

#clock {
  border: 2px solid #000;
  border-radius: 20px;
  box-sizing: border-box;
  height: 250px;
  margin: 0 auto;
  padding: 18px 0;
  width: 245px;
}

#sphere {
  border: 2px solid #000;
  border-radius: 20px;
  box-sizing: border-box;
  font-family: "Digi";
  font-size: 80px;
  height: 210px;
  margin: 0 auto;
  padding: 35px 0 0 5px;
  position: relative;
  width: 220px;
}

#digits {
  display: flex;
  flex-direction: column;
}
#digits-milliseconds {
  font-size: 35px;
}
.leash {
  background: rgb(204, 84, 87);
  border: 2px solid rgb(134, 59, 61);
  height: 50px;
  margin: 0 auto;
  width: 120px;
}

.leash-top {
  border-bottom: 0;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.leash-bottom {
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  border-top: 0;
  height: 270px;
  padding-top: 50px;
}

.hole {
  background: #fff;
  border: 2px solid rgb(134, 59, 61);
  border-radius: 100%;
  height: 20px;
  margin: 0 auto 50px;
  width: 20px;
}

.number {
  display: inline-block;
  width: 16px;
  margin-right: 8px;
}

.btn {
  border: 0;
  border-radius: 100%;
  bottom: 10px;
  color: #fff;
  cursor: pointer;
  height: 50px;
  outline: 0;
  position: absolute;
  width: 50px;
}

.btn.start,
.btn.stop {
  left: 10px;
}

.btn.reset,
.btn.split {
  right: 10px;
}

.btn.start {
  background: #5fca5f;
}
.btn.stop {
  background: #f14949;
}
.btn.reset {
  background: #908e8e;
}
.btn.split {
  background: #0851ab;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Chronometer</title>
  <link rel="stylesheet" href="styles.css">
</head>

<body>
  <div id="container">
    <div id="splits">
      <strong>Splits</strong>
      <ol id="split-times">
      </ol>
    </div>
    <div class="watch">
      <div class="leash leash-top"></div>
      <section id="clock">
        <div id="sphere">
          <div id="digits">
            <div>
              <span id="minDec" class="number">0</span>
              <span id="minCen" class="number">0</span>
              <span>:</span>
              <span id="secDec" class="number">0</span>
              <span id="secCen" class="number">0</span>
            </div>
            <div id="digits-milliseconds">
              <span id="milliseconds">00</span>
            </div>
          </div>
          <button id="btnLeft" class="btn start">START</button>
          <button id="btnRight" class="btn reset">RESET</button>
        </div>
      </section>
      <div class="leash leash-bottom">
        <div class="hole"></div>
        <div class="hole"></div>
        <div class="hole"></div>
      </div>
    </div>
  </div>

  <script src="chronometer.js" type="text/javascript"></script>
  <script src="main.js" type="text/javascript"></script>

</body>

</html>

3 个答案:

答案 0 :(得分:1)

#milliseconds{
    display: block;
    text-align: right;
}

答案 1 :(得分:0)

内联元素中的

<span>并且它不应该对齐。 只需对齐父div。

我无法看到更广泛的画面,但为什么不将毫秒与其他跨度一起放置?你写的结构的目的是什么?它只是关于字体大小?为什么毫秒不应该是flex?

答案 2 :(得分:0)

这样做:

#digits-milliseconds {
 text-align: right;
}
相关问题