css 居中布局方案
position(transform css3 有些浏览器不兼容)
<article id="one">
<section id="section"></section>
</article> <style>
#one {
position: relative; //此处不设置的话 会一直往上找 找到body
width: 300px;
height: 300px;
background: lightskyblue;
}
#section {
position: absolute;
left: 50%;
top: 50%;
width: 100px;
height: 100px;
background: aliceblue;
transform: translate(-50%, -50%);
}
</style>
2.margin-top(需要知道具体尺寸计算)
<article id="one">
<section id="section"></section>
</article> <style>
#one {
position: relative;
width: 300px;
height: 300px;
background: lightskyblue;
}
#section {
position: absolute;
left: 50%;
top: 50%;
width: 100px;
height: 100px;
margin-left: -50px; // 需要通过 计算 但是兼容性好
margin-top: -50px;
background: aliceblue;
}
</style>
3.flex(简单,兼容问题)
<article id="one">
<section id="section"></section>
</article> <style>
#one {
display: flex;
width: 300px;
height: 300px;
background: lightskyblue;
justify-content: center;
align-items: center;
}
#section {
width: 100px;
height: 100px;
background: aliceblue;
}
</style>
4.gred
<article id="one">
<section id="section"></section>
</article> <style>
#one {
display: grid; //和flex就一点不同 ????
width: 300px;
height: 300px;
background: lightskyblue;
justify-content: center;
align-items: center;
}
#section {
width: 100px;
height: 100px;
background: aliceblue;
}
</style>
css 居中布局方案的更多相关文章
- CSS居中布局方案
基本结构 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- CSS居中布局总结【转】
居中布局 <div class="parent"> <div class="child">demo</div> </d ...
- CSS居中布局总结
居中布局 <div class="parent"> <div class="child">demo</div> </d ...
- 详解 CSS 居中布局技巧
水平居中元素: 通用方法,元素的宽高未知 方式一:CSS3 transform .parent { position: relative; } .child { position: absolute; ...
- 详解CSS居中布局技巧
本文转自:https://zhuanlan.zhihu.com/p/25068655#showWechatShareTip一.水平居中元素: 1.通用方法,元素的宽高未知方式一:CSS3 transf ...
- CSS 居中布局
来源:http://www.cnblogs.com/QianBoy/p/8539077.html 水平居中 1)使用inline-block+text-align 原理:先将子框由块级元素改变为行内块 ...
- CSS居中布局
一:水平居中方案: 1.行内元素 设置 text-align:center 2.定宽块状元素 设置 左右 margin 值为 auto 3.不定宽块状元素 a:在元素外加入 table 标签(完整的, ...
- css居中布局的几种方式
一.水平居中 若是行内元素,则直接给其父元素设置text-align: center即可 若是块级元素,则直接给该元素设置margin: 0 auto即可 若子元素包含浮动元素,则给父元素设置widt ...
- 【基础】这15种CSS居中的方式,你都用过哪几种?
简言 CSS居中是前端工程师经常要面对的问题,也是基本技能之一.今天有时间把CSS居中的方案汇编整理了一下,目前包括水平居中,垂直居中及水平垂直居中方案共15种.如有漏掉的,还会陆续的补充进来,算做是 ...
随机推荐
- Golang函数-递归函数
Golang函数-递归函数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.
- $.ajax方法提交数组参数
springmvc框架 var param = new Object(); var arr = new Array(); arr.push(1,2,3); param.ids=JSON.stringi ...
- springboot的maven多模块项目架构微服务搭建——依赖方式的多模块演化为微服务项目
在上一篇依赖方式多模块的基础上对项目进行改造.主要改造user-service项目,service要配置mapper.mybatis及数据库相关的东西,后面的接口消费方user就不再需要了 注意:以下 ...
- 文本处理三剑客与shell正则表达式
文本处理三剑客 提到对于文本的处理上,除了vim这个强大的编辑器之外,还有使用命令的形式去处理你要处理的文本,而不需要手动打开文本再去编辑.这样做的好处是能够以shell命令的形式将编辑和处理文本的工 ...
- java api 远程连接 hdfs
IDEA中新建Maven工程,添加POM依赖, 在IDE的提示中, 点击 Import Changes 等待自动下载完成相关的依赖包. <?xml version="1.0" ...
- Kubernetes v1.17.3 CentOS8 基于kuberadm安装
1.机器配置: IP 主机名 节点类型 配置 192.168.31.32 node32 master 4核16G 192.168.31.33 node33 worker 4核16G 192.168.3 ...
- Codeforces Round #611 (Div. 3)
原题面:https://codeforces.com/contest/1283 A.Minutes Before the New Year 题目大意:给定时间,问距离零点零分还有多久? 分析:注意一下 ...
- 重装系统,新安装IDEA启动项目后,classnotfound:com.mysql.jdbc.Driver
我最后解决是:这个Test connection会自动帮你下载的,但是如果中途一直叫你try again,甚至到后面点这个test connection有弹窗,但是单窗里面的选项你点击后没反应,我是直 ...
- C++ MySQL封装类
#ifndef MYSQL_MANAGER_H #define MYSQL_MANAGER_H #include <Winsock2.h> #include "mysql.h&q ...
- node.js - 定义全局变量
1,定义全局变量 app.set('name','八戒') 2,获取全局变量 app.get('name')