gpt4 book ai didi

css - DFP 背景皮肤 - 无法使其居中

转载 作者:行者123 更新时间:2023-11-28 09:29:44 25 4
gpt4 key购买 nike

我正在加载 Google DFP 背景皮肤广告单元。我已经正确显示了它,但是一旦网络浏览器缩小到比图像宽度本身更小的宽度,我就无法让背景图像保持居中。相反,图像会固定在浏览器的左侧并从右向左折叠,导致中心内容面板不再以背景图像为中心。

我的 html 代码是:

<div id="background-skin" class="desktop-ad">
<div id='div-gpt-ad-XXXXXXXXXXX-X'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-XXXXXXXXXXX-X'); });
</script>
</div>
</div>

我使用的css是:

#background-skin {
position: fixed;
z-index: 1;
width: 100%;
height: 1600px;
margin-left: auto;
margin-right: auto;
top: 0px;
text-align: center;
}

最佳答案

达到预期效果的一种方法是将 fixed 包装器水平设置为 50%,left,并且不需要宽度。让它随着内容一起成长:

#background-skin {
position: fixed;
z-index: 1;
height: 1600px;
top: 0px;
left: 50%;
}

然后,使用 leftposition: relative; 将它的 child 错放 -50%。像这样的东西:

#background-skin > div {
position: relative;
left: -50%;
...

这样,容器将位于页面的正中间,内容将位于容器的正中间。

See this example fiddle

关于css - DFP 背景皮肤 - 无法使其居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25771719/

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