css上下左右居中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
html,body{
width: 100%;
height: 100%;
font-size: 16px;
} *{margin: 0;padding: 0;} .box1{
width: 200px;height: 200px;
background: #eee;
margin-top: 10px; /*定位居中*/
position: relative; }
.box2{
width: 200px;height: 200px;
background: #eee;
margin-top: 10px; /*margin居中*/
position: relative;
}
.box3{
width: 200px;height: 200px;
background: #eee;
margin-top: 10px; /*inline居中*/
text-align: center; }
/*定位+transform居中*/
.box1 div{border: 1px solid #000;position: absolute;left: 50%;top: 50%;transform: translate(-50%,-50%)} /*margin居中*/
.box2 div{border: 1px solid #000;position: absolute;left: 0;top: 0;bottom: 0;right: 0;margin:auto;width: 100px;height: 50px} /*inline居中*/
.box3 div{border: 1px solid #000;display: inline-block;vertical-align: middle;}
.box3:before{content: ''; display: inline-block; height: 100%; vertical-align: middle;}
</style>
</head>
<body>
<div class="box1">
<div>我想居中</div>
</div>
<div class="box2">
<div>我想居中</div>
</div>
<div class="box3">
<div>我想居中</div>
</div>
</body>
</html>
demo:https://controllerone.github.io/test/
css上下左右居中的更多相关文章
- CSS上下左右居中对齐
上下左右居中对齐 display: inline/inline-block 将父元素(容器)设定 text-align: center: 即可左右置中. display: block 将元素本身的 ...
- CSS上下左右居中的几种方法
1.absolute,margin: auto .container { position: relative; } .content { position: absolute; margin: au ...
- css:子元素div 上下左右居中方法总结
最近在面试,不停地收到了知识冲击,尤其是对于一些基础的css.html.js问题居多,所以自我也在做反思,今天就css问题,如何让一个子元素div块元素上下左右居中 (以下总结方法,都已得到验证). ...
- 只用CSS实现容器内图片上下左右居中
一直以来,大家都知道,DIV容器内设置 text-align:center 即可让图片居中,但是DIV内默认的图片是上对齐,不会上下居中,如果想要实现这样的效果,JS判断是比较麻烦的,因为DIV容器内 ...
- css布局之块上下左右居中
以下方案的通用代码: HTML code: <div class="box"> <div class="content"> <!- ...
- 用CSS让DIV上下左右居中的方法
转载自喜欢JS的无名小站 例如 一个父div(w:100%;h:400px)中有一个子div(w:100px;100px;).让其上下左右居中. 方法一(varticle-align) 理念 利用表格 ...
- CSS 控制元素 上下左右居中
不说废话,直接 搞起..... 首先,我们将题目 <css控制元素上下左右居中> 分析一下哈,我是将其分成了4部分信息: 1.CSS控制: 只用 CSS 来达成目的 2.元素: 不只是d ...
- css div上下左右居中
相信大家都会遇到这样的问题,要求一个块上下左右居中,在这里我总结了几个好用的方法 1.已知要居中的块width height 假设 content 要在f里上下左右居中 <div class= ...
- div元素上下左右居中
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
随机推荐
- Java怎样对一个属性设置set或get方法的快捷键
具体步骤如下: 首页,在testApp.java 类中定义属性,例如:public Sting name; 其次,Alt+Shift+S, 选择Generate Getters and Setter ...
- 【JZOJ3400】旅行
description 从前有一位旅者,他想要游遍天下所有的景点.这一天他来到了一个神奇的王国:在这片土地上,有n个城市,从1到n进行编号.王国中有m条道路,第i条道路连接着两个城市ai,bi,由于年 ...
- CF1158F Density of subarrays
CF1158F Density of subarrays 首先可以发现,有值的p最大是n/c 对于密度为p,每个数至少出现c次,且其实是每出现c个数,就分成一段,这样贪心就得到了p %ywy n/c ...
- springMVC or response redirect https
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> < ...
- MySQL安全查询模式的问题
在学习mysql中的简单sql语句的执行.在用到update语句的时候,总提示如下错误: 15:08:00 update students t set t.tel="156626488 ...
- PAT甲级——A1091 Acute Stroke【30】
One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the re ...
- 从三层架构到Spring框架
首先是软件的应用分层架构 标准三层架构: 1:数据访问层:实现了数据的持久化 2:业务逻辑层:对逻辑的实现及处理,实际上不可能在表示层对数据不做任何处理,但是尽可能的将逻辑分为一层 3:表示层:数据的 ...
- MyBatis - sqlMapConfig.xml主配置文件
SqlMapConfig.xml配置文件的内容和配置顺序如下 ① properties(读取配置文件):定义配置,配置的属性可以在整个配置文件中其他位置进行引用: ② settings(全局配置参数) ...
- vue-cli# 项目结构
引自:https://segmentfault.com/a/1190000007880723 http://blog.csdn.net/hongchh/article/details/55113751 ...
- mybatis-环境配置-基本案例-和hibernate区别
Mybatis第一天 1. Mybatis介绍 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了goo ...