gpt4 book ai didi

html - Logo 图像不会完全对齐中心

转载 作者:行者123 更新时间:2023-11-28 01:14:57 25 4
gpt4 key购买 nike

我已经尝试了所有方法,但没有任何效果!变换:翻译(50%);似乎有效,但它没有将其对齐到确切的中心。我什至试过 left: 50%;用它。

我花了一个星期的时间弄明白了,但我还是做不到。

我要对齐的图像是一个尺寸为 660 X 150 的 Logo 。

<div id="rectangle"> </div>

<img class="logo" src="Untitled.png">

<style>

.logo {
position: fixed;
width: 35%;
top: -5px;
height: auto;

}

#rectangle {
width: 100%;
height:100px;
background:#101010;
position: fixed;
top: 0;

}


</style>

编辑:不,我想将 Logo 与页面中心对齐。矩形 div 是 Logo 的背景颜色。

此外,这些答案均无效。 :(

最佳答案

试试这个:-

使用display: flex; justify-content: center; 元素将 img 居中对齐。

<div id="rectangle" style="display: flex; justify-content: center;"> 

<img class="logo" src="Untitled.png">
</div>
<style>

.logo {
position: relative;
width: 35%;
top: -5px;
height: auto;
text-align:center;
}

#rectangle {

width: 100%;
height:100px;
background:#101010;
position: fixed;
top: 0;

}


</style>

关于html - Logo 图像不会完全对齐中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51905456/

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