如何在div框中心对齐溢出文本?

CHN*_*itz 1 html css html5 css3

这是我的问题:

我的标题词溢出了div框.原因是单词大小比div的宽度宽,我设置了"nowrap"规则.它显示如下:

图片

我希望单词"FORMAT CAMERA"在div框的中心轴对齐,所以它使F的一部分溢出到左边,A的一部分溢出到右边.我怎样才能做到这一点?这是我简单的CSS代码:

.content {
  text-align: center;
}

h1(FORMAT CAMERA) {
  color: white;
  font-size: 50px;
  font-family: "Rubik", sans-serif;
  line-height: 1.4;
  white-space: nowrap;
}
Run Code Online (Sandbox Code Playgroud)

Dua*_*nnx 5

只需添加display:flexjustify-content: center.content.
了解更多关于惊人的弹性盒子

.content {
  text-align: center;
  border: solid 1px #333;
  width: 300px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
}

h1 {
  color: black;
  font-size: 50px;
  font-family: "Rubik", sans-serif;
  line-height: 1.4;
  white-space: nowrap;
}
Run Code Online (Sandbox Code Playgroud)
<div class="content">
  <h1>FORMAT CAMERA</h1>
</div>
Run Code Online (Sandbox Code Playgroud)