html - 将要显示的部分文章与第三个元素居中对齐

标签 html css flexbox

我试图让我的部分的文章完全像这样显示(当扩展到更宽的浏览器宽度时,第三篇文章居中):https://www.screencast.com/t/vGdpZ91l

我探索了 CSS 的所有显示选项。当前 CSS 设置为 display: inline-flex;

这是我的 CSS/HTML。非常感谢您的帮助。

.places h1 {
  align-content: top-left;
  font-size: 30px;
}

.places article {
  display: inline-flex;
  width: 390px;
  border: #FF5A5F 1px solid;
  border-radius: 4px;
  padding: 20px;
  margin: 20px;
}

.places article h2 {
  font-size: 30px;
  text-align: center;
}
<!DOCTYPE html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="7-places.css" media="all">
  </head>
  <body>
    <header>
    </header>

    <div class="container">
      <section class="places">
        <h1>Places</h1>
        <article class="home">
        <h2>Home</h2>
        </article>
        <article class="apartment">
        <h2>Apartment</h2>
        </article>
        <article class="dorm">
        <h2>Dorm</h2>
        </article>
      </section>
    </div>

  </body>
</html>

最佳答案

在父级上使用 flex,并将其设置为 flex-wrap: wrap;证明内容:居中;

.places {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}
.places h1 {
  align-content: top-left;
  font-size: 30px;
  width: 100%;
}

.places article {
  width: 390px;
  border: #FF5A5F 1px solid;
  border-radius: 4px;
  padding: 20px;
  margin: 20px;
}

.places article h2 {
  font-size: 30px;
  text-align: center;
}
<div class="container">
  <section class="places">
    <h1>Places</h1>
    <article class="home">
      <h2>Home</h2>
    </article>
    <article class="apartment">
      <h2>Apartment</h2>
    </article>
    <article class="dorm">
      <h2>Dorm</h2>
    </article>
  </section>
</div>

关于html - 将要显示的部分文章与第三个元素居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42287260/

相关文章:

android - 带有视频源的 HTML5 Canvas drawImage 不适用于 Android

html - 在 IE9 中,h1 元素导致按钮文本对齐问题

java - Vaadin 网格表 : how to draw border for certain columns?

css - 我们如何仅使用 flex 来获得这样的布局?

html - 是否可以收缩包裹内部文本的 flex 元素?

html - 为什么我的红色边框没有环绕我的文本 div 和侧栏 div

html - 谷歌索引页面是否具有不透明度 :0 or hidden or display:none

javascript - 我的加载图标在 ie8 中没有淡出

html - 无法理解 flask 如何使用 url_for

html - CSS flex方向列和列跨度