<div class="parent" style="width:300px;height:300px;">
    <div class="child">居中布局</div>
</div>1.inline-block + text-align
.child{
    display:inline-block;  /*变成行内块元素,让元素宽度自适应,不继承父元素宽度;*/
}
.parent{
    text-align: center;
}2.table + margin
.child{
    display: table;   /*变成table元素,可以让元素宽度自适应,不继承父元素宽度;*/
    margin: 0 auto;  
}3.absolute + transform
.parent{
    position: relative;
}
.child{
    position: absolute;   /*定位,可以让元素宽度自适应,不继承父元素宽度;*/
    transform: translateX(-50%);  
    left: 50%;
}4.flex + justify-content
.parent{
    display: flex;
    justify-content: center;
}
/*或者*/
.parent{
    display: flex;
}
.child{
    margin: 0 auto;
}1.table-cell + vertical-align
.parent{
    display: table-cell;  /*变成类似td元素*/
    vertical-align: middle;
}2.absolute + transform
.parent{
    position: relative;
}
.child{
    position: absolute;   /*定位,可以让元素宽度自适应,不继承父元素宽度;*/
    top: 50%;
    transform: translateY(-50%);
}3.flex + align-items
.parent{
    display: flex;
    align-items: center;
}1.inline-block + text-align + table-cell + vertical-align
.parent{
    text-align: center;
    display: table-cell;
    vertical-align: middle;
}
.child{
    display: inline-block;   
}2.absolute + transform
.parent{
    position: relative;
}
.child{
    position: absolute;   /*定位,可以让元素宽度自适应,不继承父元素宽度;*/
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}3.flex + align-items + justify-content
.parent{
    display: flex;
    align-items: center;
    justify-content: center;
}<div class="parent">
    <div class="left">
        <p>left</p>
    </div>
    <div class="right">
        <p>right</p>
        <p>right</p>
    </div>
</div>float + margin
.left{
    width: 100px;
    float: left;
}
.right{
    margin-left: 120px;
}float + overflow
/*和1方法表现的效果一样*/
.left{
    width: 100px;
    float: left;
}
.right{
    margin-left: 20px;
    overflow: hidden;
}table
.parent{
    display: table;
    width: 100%;
    table-layout: fixed;
}
.left,.right{
    display: table-cell;
}
.left{
    width: 100px;
    padding-right: 20px;
}flex
.parent{
    display: flex;
}
.right{
    flex: 1;
}
.left{
    width: 100px;
}absolute
.parent{
    position: relative;
}
.right{
    position: absolute;
    left: 100px;
    right: 0;
}
.left{
    width: 100px;
}float + overflow
.left{
    float: left;
}
.right{
    margin-left: 20px;
    overflow: hidden;
}table
.parent{
    display: table;
    width: 100%;
}
.left,.right{
    display: table-cell;
}
.left{
    width: 0.1%;
}
.left{
    padding-left: 10px;
}flex
.parent{
    display: flex;
}
.right{
    flex: 1;
}
.left{
    margin-right: 20px;
}//假如是n个child
<div class="parent-fix">
    <div class="parent">
        <div class="child"><p>1</p></div>
        <div class="child"><p>2</p></div>
        <div class="child"><p>3</p></div>
        <div class="child"><p>4</p></div>
    </div>
</div>table
.parent-fix{
    margin-left: -20px;
}
.parent{
    display: table;
    width: 100%;
    table-layout: fixed;
}
.child{
    display: table-cell;
    padding-left: 20px;
}flex
.parent{
    display: flex;
}
.child{
    flex: 1;
}
.child+.child {
    margin-left: 20px;
}<div class="parent"  style="background: black;">
    <div class="left" style="background: red;">
        <p>left</p>
    </div>
    <div class="right" style="background: green;">
        <p>right</p>
        <p>right</p>
    </div>
</div>table
.parent{
    display: table;
    width: 100%;
    table-layout: fixed;
}
.left,.right{
    display: table-cell;
}
.left{
    width: 100px;
    border-right: 20px solid transparent;
    background-clip: padding-box;
}flex
.parent{
    display: flex;
}
.right{
    flex: 1;
}
.left{
    width: 100px;
    margin-right: 20px;
}float
//部分UI框架采用的就是这种方式,
.parent{
    overflow: hidden;
}
.left{
    float: left;
    margin-right: 20px;
}
.right{
    overflow: hidden;
}
.left,.right{
    padding-bottom: 9999px;
    margin-bottom: -9999px;
}本文内容仅供个人学习/研究/参考使用,不构成任何决策建议或专业指导。分享/转载时请标明原文来源,同时请勿将内容用于商业售卖、虚假宣传等非学习用途哦~感谢您的理解与支持!
css两端对齐,通过margin负值、justify、space-between、column-count等多种方式来实现css的两端对齐。
flex布局(Flexible Box)是对界面css盒模型的一个优化,适应不同尺寸的屏幕,被定义flex的容器可以控制子元素的排列方向和大小,能够用更简单清晰的代码来完成复杂的布局。
 在我们的实际开发中,经常会遇到页面中需要悬浮效果,本文将介绍通过fixed的实现,以及通过原生Js实现滚动到一定位置,实现div的悬浮
CSS中Grid是一种二维网格式布局方式,Grid是为了解决二维布局问题而创建的CSS模块。使用Gird的好处,Gird在浏览器的兼容性,Grid布局的示例源码...
flex常用布局:经典的上-中-下布局。在上-中-下布局的基础上,加了左侧定宽 sidebar。左边是定宽 sidebar,右边是上-中-下布局。还是上-中-下布局,区别是 header 固定在顶部,不会随着页面滚动。左侧 sidebar 固定在左侧且与视窗同高,当内容超出视窗高度时,在 sidebar 内部出现滚动条。
本文中,所有的图形都是在单个标签内实现的,大量使用了 CSS3 中的 ::before 、::after 伪元素,transparent 、border,多重线性与径向渐变,多重内外阴影,如果你的效果不尽人意,请尝试在 Chrome 浏览器下预览。
html实现用时间点来展示事件发生点来代替用table展示一条条数据,能够给人清晰、一目了然能够看清事情发生的过程,UI页面也显示的那么清晰。如何用css+html做出时间轴展示事件点的?
 这篇文章主要整理一些关于基于jquery,实现横向/纵向时间轴的插件推荐:jquery.jqtimeline插件、timeline.js插件、Timeglider.js插件、Melon HTML5 、jQuery Timelinr、Timeline Porfolio
 css可以通过为元素设置一个position属性值,position定位是指定位置的定位,以下为常用的几种:static(静态定位)、relative定位(相对定位)、absolute定位(绝对定位)、fixed(固定定位)、inherit定位
css圣杯布局思路:外面一个大div,里面三个小div(都是浮动)。实现左右两栏宽度固定,中间宽度自适应。中间栏优先渲染。
内容以共享、参考、研究为目的,不存在任何商业目的。其版权属原作者所有,如有侵权或违规,请与小编联系!情况属实本人将予以删除!