css - 文本和图像不会在我的页面上居中

标签 css web html

我正在制作我的第一个网页,我有我想要的元素 - 我似乎无法让它们在页面上居中。我试过 margin: auto, text-align: center, 还有很多其他的东西。没有任何效果。

我希望页眉、图像和页面末尾的按钮成为页面的中央书脊。如有任何建议,我们将不胜感激。

谢谢

这是我的代码:

HTML:

<div class="container">

  <h1 class="text-center"> My tribute to Ami Coxill Moore</h1>
</div>

<!-- picture of ami here -->
<div class="container">
  <div class="row">
     <div class="col-xs-4 col-xs-offset-4"></div>
          <a href="#add-fastrack"><img class="img-resize img-center img-zero image-border img-responsive" src="https://i.imgur.com/Lc5nBon.jpg" alt="Ami laughing at her 26th Birthday"> </a>
  </div>
</div>

CSS

body {margin-top: 100px;
background-color: #ff69b4;
font-family: "gerogia", serif;
 color: #0000ff;  }


h1 {
display: inline-block;
background-color: yellow;
font-size: 300%;
border: solid;
border-radius: 25px;
align: center;
padding-left: 40px;
padding-right: 40px;
float: center;
max width: 100%;
text-align: center;
marrgin: 0 auto;
float: center;}

div {
padding-bottom: 20px;
padding-right: 50px;
padding-left: 50px;}

.img-responsive {
margin: 0 auto;}

.img-resize {
max-width: 400px; 
max-height: auto;}

最佳答案

你需要添加容器text-align

<div class="container" style="text-align: center;">

包裹元素的 div 负责对齐元素。

关于css - 文本和图像不会在我的页面上居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46999638/

相关文章:

html - 选择仅使用 HTML + CSS 显示的行/列

android - Android : what to do with low devicePixelRatio devices: tablets, 智能手机等网站?

html - IE9 以较细的字体显示某些部分

html - 如何并排放置嵌套列表?

jquery - Bootstrap 导航栏折叠不起作用

html - 如何证明和居中我的垂直导航链接

javascript - 如何将javascript var注入(inject)css

php - 你如何在 php 中组织你的页面?

java - 我没有收到网页的回复

html - CSS 未正确对齐