gpt4 book ai didi

html - 在灵活的 div 中垂直和水平居中图像

转载 作者:行者123 更新时间:2023-11-28 08:33:49 25 4
gpt4 key购买 nike

我有一个包含图像 的div 和另一个div。我可以上传任何尺寸的图片,但有一些规则:1) 如果我上传相册图片(宽度>高度),图片会被裁剪为 246x246px 并居中;2)如果我上传一张人像图片(高度>宽度)并且高度超过328px,图片会被裁剪并居中;

我已经尝试了很多不同的方法来解决这些问题,但它不起作用,有时图片会与它下面的白色 div 重叠。谢谢;

<!DOCTYPE>
<html>
<head>
<style type="text/css">
body {
padding:0;
margin:0;
font-family: 'Helvetica', arial;
font-size:15px;
color:{color:Text};
background:orange;
}


#container {
margin: 20px 400px;

-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;

overflow: hidden;
padding: 17px;
position: fixed;

width: 280px;
height: 800px;

background: black;


}



#container #logo {
display: block;
width:246px;
max-height:328px;
min-height:246;


margin: 0 0 17px;
border: 3px solid red;
}

#white {
width: 246px;
height: 320px;
background: white;
}
</style>
</head>

<body>
<div id="container">
<center>

<img src="{image:Picture}" id="logo" />

<div id="white">
</div>

</center>
</div>
</body>
</html>

找到解决办法了!但这不仅仅是我要找的。仍然需要你的帮助,伙计们!这仅在高度固定时有效,但我需要的高度范围为 256px 到 328px!

#container {
width:246px;
height:328px;

background:url(absbsb.jpg) no-repeat center;
background-size: cover;
}

最佳答案

试试这个解决方案

    img {
background: #fff;
border: 1px solid #999;
height: 50px;
width: 100px;
}
html, body { height: 100%; box-sizing: border-box; }
.container {
width: 100%;
height: 100%;

background: #eee;

display: -webkit-box;
-webkit-box-orient: horizontal;
-webkit-box-pack: center;
-webkit-box-align: center;

display: -moz-box;
-moz-box-orient: horizontal;
-moz-box-pack: center;
-moz-box-align: center;

display: box;
box-orient: horizontal;
box-pack: center;
box-align: center;
}
<div class="container">
<img src="/logo.png"/>
</div>

关于html - 在灵活的 div 中垂直和水平居中图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28159697/

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