html - 无法在页面上居中对齐两个 div

标签 html css alignment center

我在对齐页面中心的两个 div 时遇到一些困难。相反,它仍然保留。我浏览了这个网站和其他网站,并尝试了其中的一些建议。我在想,也许我把几个不同的例子放在一个例子中,把它放在一个例子上,搞砸了,有些东西否定了另一个例子? div 只是没有在页面上居中对齐。我将 mask gif 放在一个 div 中,将文字放在另一个 div 中,并将这两个 div 放在一个容器中。

body {
  background-color: #000;
  color: white;
  font-family: "Cutive One", monospace;
  font-size: 13px;
  text-align: justify;
  line-height: 1.5;
}

.container {
  margin: 70px;
  width: auto;
}

.one {
  width: 35%;
  max-width: 300px;
  min-width: 300px;
  padding: 5px;
  text-align: center;
  float: left;
}

.two {
  width: 35%;
  padding: 5%;
  max-width: 300px;
  min-width: 300px;
  float: left;
  background: black;
  font-family: "Cutive One", monospace;
  font-size: 13px;
  text-align: justify;
  line-height: 1.5;
}

.gif {
  background: url("http://78.media.tumblr.com/072a9aee9e56415e20ffd06c3260c49d/tumblr_n85ga7OASY1qmxnvuo2_500.gif") repeat;
  background-position: 10px;
  -webkit-background-clip: text;
  color: transparent;
  font-size: 200px;
  font-family: Fjalla One;
  font-weight: bold;
  text-align: center;
  letter-spacing: 3;
  background-position-x: 50%;
  background-position-y: 50%;
}
<div class="container">
  <div class="one">
    <div class="gif">TXT</div>
  </div>

  <div class="two">
    <h3>Test //</h3>

    <ul>
      <li>Test</li>
      <li>Test</li>
      <li>Test</li>
    </ul>
  </div>
</div>

最佳答案

像这样更改您的container类(使用Flex):

.container {

      display: flex;
      justify-content: center;
      align-items: center; 
    }

body {
  background-color: #000;
  color: white;
  font-family: "Cutive One", monospace;
  font-size: 13px;
  text-align: justify;
  line-height: 1.5;
}

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

.one {
  width: 35%;
  max-width: 300px;
  min-width: 300px;
  padding: 5px;
  text-align: center;
  float: left;
}

.two {
  width: 35%;
  padding: 5%;
  max-width: 300px;
  min-width: 300px;
  float: left;
  background: black;
  font-family: "Cutive One", monospace;
  font-size: 13px;
  text-align: justify;
  line-height: 1.5;
}

.gif {
  background: url("http://78.media.tumblr.com/072a9aee9e56415e20ffd06c3260c49d/tumblr_n85ga7OASY1qmxnvuo2_500.gif") repeat;
  background-position: 10px;
  -webkit-background-clip: text;
  color: transparent;
  font-size: 200px;
  font-family: Fjalla One;
  font-weight: bold;
  text-align: center;
  letter-spacing: 3;
  background-position-x: 50%;
  background-position-y: 50%;
}
<div class="container">
  <div class="one">
    <div class="gif">TXT</div>
  </div>

  <div class="two">
    <h3>Test //</h3>

    <ul>
      <li>Test</li>
      <li>Test</li>
      <li>Test</li>
    </ul>
  </div>
</div>

关于html - 无法在页面上居中对齐两个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50990343/

相关文章:

html - 两个div,一个滚动,另一个静态

python - 关于python中字符串格式化的几个问题。结盟

javascript - 如何防止 HTML 表单提交空白

javascript - 表单文件上传,添加加载微调器,放置错误,完成后不删除

css - 为什么我的动画关键帧不在悬停时触发?

arrays - Delphi中数组和压缩数组有什么区别?

html - CSS - 当第一个 div 溢出时如何强制第二个 div 到另一行

javascript - JavaScript 中的 2048 : updating the canvas

html - 单击按钮将输入数据保存到 localStorage

java - 如何在servlet中获取一个td的内容