gpt4 book ai didi

css - 无法在CSS中居中图像

转载 作者:行者123 更新时间:2023-11-28 00:11:26 24 4
gpt4 key购买 nike

我的图片不会在我的页面上居中。它们仅以智能手机为中心,而不以笔记本电脑为中心。我该如何解决这个问题?

@media only screen and (MIN-width:240px) {

img {
display: block;
width: 100%;
margin-left: auto 0;
margin-right: auto 0;
}
@media only screen and (min-width: 769px) {
img {
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;

}
.main-container {
min-height: 100vh;
/* will cover the 100% of viewport */
overflow: hidden;
display: block;
position: relative;
padding-bottom: 100px;
text-align: center;
/* height of your footer */

最佳答案

您的 CSS 代码中存在一些语法错误。试试这个:

@media only screen and (min-width:240px) {
img {
display: block;
width: 100%;
margin-left: auto 0;
margin-right: auto 0;
}
}

@media only screen and (min-width: 769px) {
img {
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;
}

.main-container {
min-height: 100vh;
overflow: hidden;
display: block;
position: relative;
padding-bottom: 100px;
text-align: center;
}
}
 <html lang="da">  
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="main-container">
<img src="https://via.placeholder.com/150" alt=forside>
</div>
</html>

关于css - 无法在CSS中居中图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55372933/

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