【问题标题】:Can't center Footer with text-align or margin:auto. Small text also won't work无法使用 text-align 或 margin:auto 居中页脚。小文字也不行
【发布时间】:2017-01-26 15:01:29
【问题描述】:

我无法使用 text-align 或 margin:auto 使页脚居中。小文本也不行。

我是 HTML 和 CSS 的新手,因此非常感谢任何帮助 :)

代码:

/* Footer */
footer {
	text-align: center;
	font-size: 0.7em;
	border-top: 1px dotted #E8DFAC;
	padding-top: 1em;
	margin: 0 auto;
}

footer a,
footer a:visited {
	color: #636363;
}

footer a:hover,
footer a:focus {
	color: green;
}
<!-- Footer -->
	<footer>
		<small>Made by Hannah Hawkins</small>
	</footer>

::: 更新 ::: 我发现我可以使用页脚标签中的样式属性来修复它。谢谢!

【问题讨论】:

  • 这里似乎工作正常...尝试在您的应用中为 footer 添加宽度 100%...
  • @kukkuz 绝对。她只需要声明页脚的 with。
  • 我尝试添加 (margin: auto 0) 和 (width: 100%),但它仍然无法在 Chrome 中正确显示。我的 CSS 样式表的其他部分也开始出现类似问题。

标签: html css margin footer text-align


【解决方案1】:

您希望页脚居中对齐。不仅仅是现在正确的文本?

要使您的页脚居中,您需要为其设置宽度,margin:0 auto 才能正常工作。

页脚是块元素,因此如果您不想应用固定宽度,请更改display:inline-block,然后将父级更改为text-align:center。

body {text-align: center;}
footer {display:inline-block}

【讨论】:

    猜你喜欢
    • 2021-04-15
    • 2013-11-04
    • 1970-01-01
    • 2018-02-17
    • 2018-01-26
    • 2014-10-02
    • 1970-01-01
    • 2021-07-01
    • 2016-02-15
    相关资源
    最近更新 更多