html - 使用 flexbox 将视频和输入框居中

标签 html css flexbox

我的视频、输入框和按钮在页面中央水平居中时遇到一点问题。我看到一些答案说我不需要 flexbox,实际上我已经尝试将边距设置为自动(将内容居中放置在视口(viewport)中间)但无济于事。当我尝试使用 chrome 开发人员工具检查代码时,它显示我的视频、内容和表单 div 占据了视口(viewport)宽度的 100%,所以这似乎是我无法将其居中的原因。当然,我可能是错的。我很难过。你们提供的任何帮助现在都会非常有用。如果不清楚请告诉我。这是我到目前为止所拥有的。 谢谢, 安娜

<div class="content">
<div class="video">
<h2>Want to read as fast as me? Follow the instructions below... 
</h2>
<iframe width="560" height="315" 
 src="https://www.youtube.com/embed/7SbJLfqPJgI" frameborder="0" 
 allow="accelerometer; autoplay; encrypted-media; gyroscope; 
 picture-in-picture" allowfullscreen></iframe>
 </div>
 <form>
<input type "text" placeholder="Tell us more about what books you 
like.">
<form>
</div>
<button type="submit" name="button">submit</button>
<footer>Anna Gibson @ 2018</footer>

最佳答案

好的,这就是我所做的。我这样做是为了让“内容 div”包含视频、输入框、按钮和页脚,并将它们全部对齐到“中心” . 下面是我的代码示例:

HTML:

  <div class="content">
    <div class="video">
      <h2>Want to read as fast as me? Follow the instructions below...</h2>
      <iframe width="560" height="315" src="https://www.youtube.com/embed/7SbJLfqPJgI" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    </div>
      <form>
    <input type "text" placeholder="Tell us more about what books you like.">
    <form>
     <button type="submit" name="button">submit</button>

     <footer>Anna Gibson @ 2018</footer>
      </div>

CSS:

.content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

form {
  width: 200px;
  margin: 0 auto;
}


input{
  margin: auto;
  width: 200px;
  height: 150px;
  margin-top: 20px;
  border: 2px solid black;
}

button {
  margin-top: 40px;
  font-size: 18px;
  padding: 10px;
  text-align: center;
  background-color: #7a420a;
  color: white;
  margin: auto;
}

关于html - 使用 flexbox 将视频和输入框居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53974425/

相关文章:

php - 如何替换文本 URL 并排除 HTML 标记中的 URL?

javascript - 如何在 Angular.js 中组合两个 Controller ?

jquery - 安装颜色选择器时遇到问题

javascript - 我使用 jquery 创建了一个 iframe 如何根据其中的内容设置它的高度

javascript - Vue.js中使用动态路由匹配时如何实现 "in-out mode"转场效果?

html - 使用 flexbox 将图像排成一行

css - 显示 :flex is not working

php - 从 EntityType Symfony 获取值

html - 如何让链接在导航栏中以图像为中心而不是在顶部?

css - Angular material flex layout - 行中的第二个容器在调整大小时不会移动