以居中为中心后的div余量(Offseting div margin after centering it)

编程入门 行业动态 更新时间:2024-10-28 15:19:13
以居中为中心后的div余量(Offseting div margin after centering it)

我有一个以另一个div为中心的div:

<div id="align" style = "width: 420px; margin:auto; ">

div始终位于中心,这很好,但是,

如何将它偏移60px(或任何其他距离)到右边?

I have a div centered in another div with:

<div id="align" style = "width: 420px; margin:auto; ">

The div stays always in the center and that's fine but,

how do I offset it 60px (or any other distance) to the right?

最满意答案

您可以移动div并使用position:relative使其居中

#align {
    width: 420px; 
    margin:auto;
    position:relative;
    left:60px;
} 
 
<div id="align"></div>

You can move the div and still have it centered using position:relative

#align {
    width: 420px; 
    margin:auto;
    position:relative;
    left:60px;
} 
 
<div id="align"></div>

                    
                     
          

更多推荐

本文发布于:2023-07-31 14:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1345308.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:余量   中心   div   centering   Offseting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!