css水平居中的小小探讨
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>不定宽度水平居中</title>
<style>
body{
background-color: #e5da31;
}
.container{
position: absolute; /*脱离文档流,其宽度将由子元素的宽度决定*/
left:50%;
}
.content{
position: absolute;
left:-50%;
background-color: #2ecc71;
}
</style>
</head>
<body>
<div class="container">
<div class="content">标签嵌套</div>
</div>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>不定宽度水平居中</title>
<style>
body {
background-color: #e5da31;
}
.container {
display: flex; /*定义一个flex容器*/
justify-content: center; /*定义容器的空间没有被全部占用时,内容的对其方式*/
}
.content{
background-color: #2ecc71;
}
</style>
</head>
<body>
<div class="container">
<div class="content">标签嵌套</div>
</div>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>不定宽度水平居中</title>
<style>
body{
background-color: #e5da31;
}
.container{
text-align:center;
}
.content{
display: inline;
background-color: #2ecc71;
}
</style>
</head>
<body>
<div class="container">
<div class="content">标签嵌套</div>
</div>
</body>
</html>

css水平居中的小小探讨的更多相关文章
- css水平居中那点事
昨晚深夜写了css垂直居中那点事,今晚该写他的兄弟篇:css水平居中那点事了..…^^ 其实本来这两个可以连在一起写,可是为了不要搞混,为了让思路更清晰,最后决定还是分开来些比较好...这样以后也有利 ...
- CSS水平居中
三种情况:1.行内元素(文本.图片等) 给父元素设置text-align:center;来实现 2.定宽块状元素 <style> div{ border:1px solid blue; w ...
- css水平居中,竖直居中技巧(二)
css水平居中,竖直居中技巧(二)===### 1.效果 ### 2.代码#### 2.1.index.html <!DOCTYPE html> <html lang="z ...
- css水平居中,竖直居中技巧(一)
css水平居中,竖直居中技巧(一)===### 1.效果 ### 2.代码#### 2.1.index.html <!DOCTYPE html> <html lang="z ...
- css水平居中的各种方法
说到水平居中,大家可能觉得很简单啊,text-align:center 就OK了. 但是,有时候会发现这样写了也没出效果.原因是什么呢? 请往下看. 水平居中:分为块级元素居中和行元素居中 行内元素 ...
- CSS水平居中/垂直居中的N个方法
我看最近微博流行CSS居中技术,老外码农争相写相关的文章,一篇赛一篇的长啊,我把几篇归纳总结了一下,算是笔记. 孔乙己曾说:"茴香豆的回字有四种写法",万一哪天有个面试官问你:&q ...
- CSS水平居中和垂直居中解决方案
一.CSS 居中 — 水平居中 DIV等标签本身没有定义自己居中的属性,网上很多的方法都是介绍用上级的text-align: center,然后嵌套一层DIV来解决问题. 可是这个方法有时候完全不起作 ...
- CSS 水平居中
一.水平居中:行内元素解决方案 居中元素:文字.链接以及其它行内元素(inline或inline-*类型的元素,如inline-block,inline-table,inline-flex)解决方案: ...
- css水平居中和垂直居中
水平居中:内联元素:text-align:center;相对于父级居中显示块级元素:margin:0 auto;但是需要同时width,否则无法看到效果多个块级元素居中:在此想要探讨一下display ...
随机推荐
- QMapControl介绍
QMapControl是Qt开发的基于LGPL协议开源的显示OpenStreetMap(下简称osm)Tile数据和基于wms-server服务的数据,这里做简单介绍并列出相关资源. QMapCont ...
- Church encoding
In mathematics, Church encoding is a means of representing data and operators in the lambda calculus ...
- 把CSV文件导入到SQL Server表中
保存数据库数据直接查询select * from tableName 在数据表格的左上角右击——将结果另存为选择路劲保存好的就是.csv格式的数据 有时候我们可能会把CSV中的数据导入到某个数据库的表 ...
- 【ZOJ】3430 Detect the Virus
动态建树MLE.模仿别人的代码模板各种原因wa后,终于AC. #include <iostream> #include <cstdio> #include <cstrin ...
- Microsoft Office 2013 激活方法
Microsoft Office 2013 激活方法 Microsoft Office 2013是微软的新一代Office办公软件,全面采用Metro界面,包括Word.PowerPoint.Ex ...
- -_-#setTimeout与setInterval
你真的了解setTimeout和setInterval吗? 存在一个最小的时钟间隔 有关零秒延迟,此回调将会放到一个能立即执行的时段进行触发.JavaScript 代码大体上是自顶向下执行,但中间穿插 ...
- 搜索(三分):HDU 3400 Line belt
Line belt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- [Locked] Binary Tree Upside Down
Binary Tree Upside Down Given a binary tree where all the right nodes are either leaf nodes with a s ...
- Linux内存寻址之分段机制
前言 最近在学习Linux内核,读到<深入理解Linux内核>的内存寻址一章.原本以为自己对分段分页机制已经理解了,结果发现其实是一知半解.于是,查找了很多资料,最终理顺了内存寻址的知识. ...
- POJ - 1170 Shopping Offers (五维DP)
题目大意:有一个人要买b件商品,给出每件商品的编号,价格和数量,恰逢商店打折.有s种打折方式.问怎么才干使买的价格达到最低 解题思路:最多仅仅有五种商品.且每件商品最多仅仅有5个,所以能够用5维dp来 ...