css 如何在页面中间对齐div内的内容[复制]

wztqucjr  于 2023-02-01  发布在  其他
关注(0)|答案(2)|浏览(131)
    • 此问题在此处已有答案**:

(133个答案)
How can I vertically center a div element for all browsers using CSS?(48个答案)
How can I center text (horizontally and vertically) inside a div block?(27个答案)
9小时前关门了。
我有这一点html,我不知道该怎么做才能让它居中对齐。我试过所有的方法,但我真的不知道我在用CSS做什么,这没有帮助。我目前的解决方案是一个40%边距的创可贴解决方案。我想让它像我的html的其他部分一样居中对齐,但不知道在. timedisplay CSS中写什么。非常感谢您的帮助。

.timedisplay {
  display: inline-flex;
  margin-left: 40.8%;
}

.input1 {
  border-style: hidden;
  font-size: 150px;
  margin-top: none;
  padding: 0px;
  max-width: fit-content;
  font-family: "Times New Roman", Times, serif;
  width: 150px;
  height: fit-content;
  color: #940e0e;
  background-color: #0f2f5f;
}

.colon {
  font-size: 150px;
  color: #940e0e;
  margin-top: 0px;
  margin-bottom: 0px;
}
input[type="text"]:disabled {
  background: none;
  user-select: none;
  margin-top: none;
}
<div class="timedisplay">
      <input
        class="input1"
        id="input1"
        type="text"
        onfocus="clearInput(this)"
        onblur="unclearInput2(this)"
        id="minuter"
        autocomplete="off"
        maxlength="2"
        value="00"
        onkeypress="return event.charCode >= 48 && event.charCode <= 57"
      />

      <p class="colon">:</p>

      <input
        class="input1"
        id="input2"
        type="text"
        onfocus="clearInput(this)"
        onblur="unclearInput(this)"
        id="sekunder"
        autocomplete="off"
        maxlength="2"
        value="00"
        onkeypress="return event.charCode >= 48 && event.charCode <= 57"
      />
</div>

尝试了各种对齐中心变量和边距自动,但div的内容总是一直停留在左侧。

toe95027

toe950271#

下面是你如何做到这一点,如果你需要你的输入以不同的方式排列,你总是可以把他们放在另一个div和应用风格,因为你想。

.timedisplay {
      display: flex;
      align-items: center;
      justify-content: center;
    }
odopli94

odopli942#

Css至中心含量

.timedisplay {
    display: flex;
    justify-content: center;
}

相关问题