div居中方法(共9种)

div居中方法(共9种)div 居中方法 共 8 种 水平居中行级元素 为该行级元素的父元素设置 text align center 配合 line height 样式 divstyle width 500px height 100px line height 100px border 1pxsolidgree text align center span 行级元素 span 块级元素 为其自身设置 margin auto 样式 divstyle width 500px height 100px line height 100px border 1pxsolidgree text align center

div居中方法(共9种)

<div style="width: 500px;height: 100px;line-height: 100px;border: 1px solid green;text-align:center;"> <span>行级元素 
     span>  
      div> 

块级元素:为其自身设置margin:auto样式

<div style="width: 500px;height: 100px;border: 1px solid red;"> <div style="line-height: 100px;text-align: center;margin:auto;width: 100px;height: 100px;border: 1px solid gold"> 块级元素  
     div>  
      div> 

),表格前后带有换行符.

display:table-cell;此元素会作为一个表格单元格显示(类似 和 )

<div style="display: table;width: 500px;height: 200px;border: 1px solid red;"> <div style="display: table-cell;vertical-align: middle;text-align:center;">块级元素 
     div>  
      div> 
<div style="display:flex;justify-content: center; align-items:center; width: 500px;height: 200px;border: 1px solid green;text-align:center;line-height:100px "> <div style="width: 100px;height: 100px;border: 1px solid gold">块级元素 
     div>  
      div> 
<div style="position:relative; width: 500px;height: 200px;border: 1px solid red;"> <div style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width: 100px;height: 100px;border: 1px solid gold;text-align:center;line-height:100px"> 块级元素  
     div>  
      div> 
<div style="position:relative; width: 500px;height: 200px;border: 1px solid red;"> <div style="position:absolute;top:50%;left:50%;margin-left: -50px;margin-top: -50px; width: 100px;height: 100px;border: 1px solid gold;text-align:center;line-height:100px"> 块级元素  
     div>  
      div> 
<div style="position:relative; width: 500px;height: 200px;border: 1px solid red;"> <div style="position:absolute;top: 0;left: 0;right: 0;bottom: 0;margin: auto; width: 100px;height: 100px;border: 1px solid gold;text-align:center;line-height:100px"> 块级元素  
     div>  
      div> 
<div style="position:fixed;top: 50%;left: 50%;margin-left: -50px;margin-top: -50px;z-index: 999; width: 100px;height: 100px;border: 1px solid gold;text-align:center;line-height:100px"> 块级元素  
     div> 
<div style="margin: 50vh auto 0;transform: translateY(-50%);line-height:100px width: 100px;height: 100px;border: 1px solid gold;text-align:center;"> 块级元素  
     div> 
<div style="display: flex;width: 500px;height: 200px;border: 1px solid red;"> <div style="margin: auto;width: 100px;height: 100px;border: 1px solid gold;text-align:center;line-height:100px"> 块级元素  
     div>  
      div> 
<div style="display: grid; place-items: center;"> <div> 块级元素  
     div>  
      div> // CSS // body { // display: grid; // place-items: center; // } 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/212104.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 下午8:49
下一篇 2026年3月18日 下午8:50


相关推荐

  • 胶南人才交流中心[通俗易懂]

    胶南人才交流中心[通俗易懂]电话:0532-86164282山东胶南珠海中路273号邮编:266400

    2022年7月3日
    34
  • SAE J1939 协议源代码分析(一)-程序结构框架

    SAE J1939 协议源代码分析(一)-程序结构框架文件组成概述文件名功能备注J1939.c协议源代码数据链路层,网络层实现j1939.h协议源代码数据链路层,网络层实现j1939_Config.h协议配置移植文件移植J1939,唯一改动文件函数组成结构函数大概分为4类:1.内部函数,J1939内部使用的函数。函数如下:文件名类型备注文件位置Compa

    2022年5月1日
    199
  • 数据库设计工具MySQLWorkBench[通俗易懂]

    数据库设计工具MySQLWorkBench[通俗易懂]  该工具为MySQL官方提供地址:http://dev.mysql.com/downloads/workbench/小伙伴们注意按自己的操作系统选择下载版本。·       注意事项:安装后将环境语言配置成简体中文,否则中文乱码工作步骤新建模型后,会进入此页面。 1./2.切换数据库表设计与ER图。3. 创建/管理ER图4. 创建/管理表结构1….

    2022年7月11日
    22
  • 大数据应用管理模式及内容

    大数据应用管理模式及内容通过调研,数据应用管理可总结为分散管理型、职能复用型、集中管理型三种模式,数据应用管理模式中重点关注组织管理、需求管理、建设管理、成果管理四大领域。(1)管理模式分散管理型:各部门分散开展数据应用,无集中管理,例如某某国有集团,公司各业务部门均设有业务数据部门,开展本部门数据应用相关事务。职能复用型:赋予现有部门数据应用管理职责,集中开展数据应用局部过程的管理事务,例如某工业公司,依托公司…

    2022年6月9日
    34
  • 怎么查看maven仓库地址_修改maven本地仓库

    怎么查看maven仓库地址_修改maven本地仓库Maven一般用来存放jar包的地方,有中央仓库和远程仓库1)找到下载的maven的路径,C:\Users\lqw\Documents\apache-maven-3.3.9\conf找到seting.xml文件,查看&lt;localRepository&gt;C:/repository&lt;/localRepository&gt;这里我改过默认地址了,可以自己设置2)找到自己的maven项目,…

    2025年5月24日
    6
  • idea如何查找替换_pycharm查找替换

    idea如何查找替换_pycharm查找替换在平时敲代码的时候经常碰到,咦,这个变量名好像不太合适,但又写了好多这时候可以怎么办呢?Pycharm里面给我们准备了替换功能————–windows电脑—————1.Ctrl+r替换2.Ctrl+Shift+F全局查3.Ctrl+Shift+R全局替换————–MAC电脑—————1.command+F全局查找2.command+R全局替换…

    2022年8月29日
    6

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号