gpt4 book ai didi

css - 简单的 div css 将内容居中

转载 作者:太空宇宙 更新时间:2023-11-04 05:24:03 24 4
gpt4 key购买 nike

嘿,我是一个 CSS 新手,但我知道这应该很容易。如果有人能很快地帮助我,这样我就可以不再为了弄清楚这个问题而伤脑筋了,那就太好了。

我只有 2 件元素需要帮助放置。

一个 400x200px 的图像,我总是希望它位于中心(垂直和水平),这将是内容。和我希望在底部居中的一行文本将作为页脚。

提前致谢。

最佳答案

如果我理解您的要求,我认为您应该尝试在 css 中使用边距,这确实是可行的方法。 ;)

<html>
<head>
<title>Center</title>
<style type="text/css">
IMG.image1 {
position: absolute;
left: 50%;
top: 50%;
margin-left: -200px;
margin-top: -100px
}
#footer {
position: fixed;
bottom: 0;
text-align: center;
width: 100%;
}
</style>

</head>
<body>
<div id="Centeredcontent">
<img class="image1" width="400px" height="200px"></img>
</div>
<div id="footer">Footer</div>
</body>
</html>

将您的总图像高度和宽度减半并使其为负数,因此宽度为 (margin-left: -200px;) 顶部为 (margin-right: -100px;)

关于css - 简单的 div css 将内容居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5644321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com