当前位置:网站首页>两种块级元素居中的方式
两种块级元素居中的方式
2022-06-25 22:05:00 【妄想_wangx】
1、在没有设置绝对定位的情况下,给块级元素设置宽度后用margin:0 auto;居中
2、设置成绝对定位后,根据宽度调整距左边距的距离居中,
例:
position: absolute;
left: 25%;
width: 50%;
或
position: absolute;
left: 50%;
margin-left: -50px;
width: 100px;
这两种方式居中都没问题,但是使用了绝对定位后,再使用margin:0 auto九不可以居中了。具体原因不详,查了几篇资料,都说就是这样规定的,照着用就行了。后来因时间有限也就没有深究。知道原因的大佬麻烦在评论区留个言,先谢谢了,
边栏推荐
- Qt自定义实现的日历控件
- DPVS-FullNAT模式管理篇
- OpenJudge NOI 2.1 15:Counterfeit Dollar
- Analysis on the control condition and mode of go cooperation overtime exit
- QT custom implemented calendar control
- CSDN add on page Jump and off page specified paragraph jump
- phoenix索引
- DPVS-FullNAT模式部署篇
- Screen recording to GIF is an easy-to-use gadget, screentogif, which is free and easy to use!
- hiberate架构介绍及环境搭建(非常详细)
猜你喜欢

解析產品開發失敗的5個根本原因

Uni app -- listen for the exit of the return key

UE4 learning records create a role and control its movement

Anaconda一文入门笔记

How does excel translate Chinese words into English automatically? This formula teaches you

excel如何实现中文单词自动翻译成英文?这个公式教你了

jdbc常见异常及错误解决办法汇总

二叉排序树

Hibernate entity class curd, transaction operation summary

When are the three tools used for interface testing?
随机推荐
Audio basics and PCM to WAV
idea 查看单元测试覆盖率
关于go协程超时退出控制条件与方式分析
权限设计=功能权限+数据权限
A. Balance the Bits--Codeforces Round #712 (Div. 1)
Uniapp -- the use of document collation and push of unipush
C. Yet Another Card Deck-Educational Codeforces Round 107 (Rated for Div. 2)
Share a downloaded osgeo4w64 Library Based on qgis3.10
MySQL自定义函数实例
Summary of common JDBC exceptions and error solutions
Gradle的环境安装与配置
自定义QComboBox下拉框,右对齐显示,下拉列表滑动操作
Leetcode-1528- rearrange string - hash table - string
OpenResty篇01-入门简介和安装配置
Anaconda一文入门笔记
Run the dronekit flight control application on Shumei faction under px4-jmavsim software simulation environment
发送邮件工具类
How does excel translate Chinese words into English automatically? This formula teaches you
Spark日志分析
二进制、16进制、大端小端