首页 技术 正文
技术 2022年11月14日
0 收藏 457 点赞 4,341 浏览 2243 个字

css参考文档        http://css.doyoe.com/

两篇很好的文章:(下面的css官方英文说明链接 有时间可以研究下

1 http://www.ituring.com.cn/article/64581

无论padding 还是margin参照物都是 包含元素(父元素)的宽度

2 http://www.ituring.com.cn/article/64580

纵向auto为0,横向auto为可用的剩余空间

3 div 在另一个div里垂直居中的方法:

方法1:原理,利用绝对定位和margin。当子div设置了absolute,并且top 和 bottom(必须上下或左右同时设置值才可以)设置了值之后,margin=auto在纵向上的值不再是0而是纵向剩余空间(可用空间)

.parent {

          width:800px;          height:500px;

          border:2px solid #000;

          position:relative;(此设置是为了让子div以此为定位参照物)} .child {

            width:200px;

            height:200px;

            marginauto;  

            positionabsolute;  

            top0left0bottom0right0

            background-colorred;

}         方法二:利用display:table-cell模拟表格,然后设置vertical-align:middle(CSS中的确是有vertical-align属性,但是它只对(X)HTML元素中拥有valign特性的元素才生效,例如表格元素中的<td>、<th>、<caption>等,而像<div>、<span>这样的元素是没有valign特性的,因此使用vertical-align对它们不起作用。)

.parent {

            width:800px;

            height:500px;

            border:2px solid #000;

            display:table-cell;(垂直居中)

            vertical-align:middle;(垂直居中)

            text-aligncenter;(水平居中)

        }        .child {

            width:200px;

            height:200px;

            display:inline-block;(水平居中)

            background-colorred;

        } 方法三:原理: display:flex;            .parent {

            width:800px;            height:500px;            border:2px solid #000;            display:flex;            justify-content:center点击查看justify-content的详解            align-items:center点击查看align-items详情
                                                                     点击查看align-items和align-content的区别
                                                                    说明:1:align-content只针对有多行的子元素,只有一行则没有效果 2:多行的align-content:space-around和多行的align-items:center效果一样。
                                                                     点击查看align-self的详情        }        .child {            width:200px;            height:200px;            background-colorred;        }方法四:浅谈display:flex    (父元素:display:flex,           子元素:margin:auto;  即可上下左右居中,通过margin可以调控位置)

.parent {

            width:800px;            height:500px;            border:2px solid #000;            display:flex;        }        .child {            width:200px;            height:200px;            background-colorred;                          margin: auto;        }

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919