gpt4 book ai didi

css - 如何将 DIV 位置设置为中心左侧 200 像素

转载 作者:技术小花猫 更新时间:2023-10-29 10:28:06 25 4
gpt4 key购买 nike

我想将 DIV 放置在中心左侧 200 像素处。

我目前正在使用以下代码,但在更高分辨率的显示器上(例如 1920×1080),DIV 会滑出位置:

.hsonuc {
position: absolute;
top: 20px;
margin:auto;
margin-left:200px;
display:none;
}

我想要实现的目标:

Illustrating a div that is positioned 200px to the left of the center of the page

最佳答案

只需定位它 50%从右边 ( right:50%; ),然后使用 margin-right:200px; 把它推过去(example)。

HTML

<div class="hsonuc">DIV</div>

CSS

.hsonuc {
position:absolute;
top:20px;
right:50%; /* Positions 50% from right (right edge will be at center) */
margin-right:200px; /* Positions 200px to the left of center */
}

关于css - 如何将 DIV 位置设置为中心左侧 200 像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11127120/

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