您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

CSS具有自动保证金的固定位置

CSS具有自动保证金的固定位置

您无法使用来做到这一点margin:auto,但是您可以执行以下操作:

#css-SELECTOR-YOU-ARE-USING{
    background:#FF0000; // Just so you can see whats going on
    position:fixed; // Position the element
    right:50%; // Move it to the right for 50% of parent element
    margin-right:-250px; // You need here to put 1/2 of what you have below in width
    width:500px;
}

这样,您可以将元素向右移动50%,然后向后移动其宽度的一半。这样,您将获得居中的元素position:fixed

CSS 2022/1/1 18:14:38 有515人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶