最近在做项目的时候,经常会有需要各种居中的情况,现在分享一个最佳实践。

<div class="success-bottom">
        <div class="hr-use"></div>
        <div class="youwant">
            <span class="loveicon"></span>
            <span>你可能还想要</span>
        </div>
        <img src="data:images/active.png" />
    </div>
.success-bottom {
    margin-top: 15px;
    background-color: #fff;
    border-top: 1px solid #c8c8c8;
    position: relative;
}
.success-bottom .loveicon {
    background: url("bgimg/icon-love.png") no-repeat left center;
    display: inline-block;
    width: 25px;
    height: 26px;
    position: absolute;
    background-size: 24px;
}

.success-bottom span:nth-child(2) {
    display: inline-block;
    margin-left: 28px;
    line-height: 28px;
}

.youwant {
    width: 124px;
    height: 36px;
    background-color: #fff;
    z-index:;
    padding-top: 5px;
    position: relative;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
}

.hr-use {
    width: 100%;
    height: 1px;
    border-top: 1px solid #c8c8c8;
    position: absolute;
    top: 18px;
}

其实思路就是让一个Div绝对定位,设置成中线;让另外的内容固定宽度,margin-left: auto; margin-right: auto;  最后再调整下位置就可以达到内容在中间,且在横线中间的效果。

结构-行为-样式-Css Div 居中的一个最佳实践的更多相关文章

  1. 结构-行为-样式-Css笔记

     0.常见的行级元素和块级元素: 行级元素:div,table,form ,ul,ol,p,h1-h6,hr; 块级元素:a,select,input,textarea,img,label,br,i, ...

  2. CSS UNIT 详解以及最佳实践

    分类 ■    绝对长度(Absolute units):cm,mm,in,pt,pc 绝对单位之间的换算:1in = 2.54cm=25.4mm=72pt=6pc 绝对长度在css中的表现和其他地方 ...

  3. 结构-行为-样式-css&html横纵居中最佳实践

    最近在做手机端的H5项目,有个标题是在一根横线中的,就是水平居中加垂直居中(如图一).这应该是前端开发中经常遇到的一个场景了,做的次数多了就有一些体会,我今天就总结了下这种结构的实现思路:首先,用元素 ...

  4. css div居中

    div中没有text-align和vehicle-align这两个属性,所在在css中设置这两个值没有作用 div 水平居中 设置左右边距有auto div{ margin: 0 auto; } 垂直 ...

  5. css div居中显示的4种写法

    Demo:http://www.feman.cn/h5/center.html .absolute 绝对定位 这是我们最常用的一种居中定位写法 要求必须确定div的宽高度 目前市面上的浏览器基本上都支 ...

  6. CSS——div居中,window.open(0

    margin:0 auto 表示什么意思?? margin后面如果只有两个参数的话,第一个表示top和bottom,第二个表示left和right因为0 auto,表示上下边界为0,左右则根据宽度自适 ...

  7. 自己用jquery+css+div写的一个弹窗

    弹窗支持两种模式,一种是普通信息提示框,调用方法:popup.msgPopup(msg); 另一种是可以加载页面的弹窗,调用方法:popup.pagePopup(url); 效果图: css代码 ;; ...

  8. CSS DIV 居中

    左右居中 margin-left: auto; margin-right: auto; 上下居中

  9. CSS - div居中在屏幕中(水平居中 + 垂直居中)

    方法一代码 <div> <h1>404 Not Found.</h1> </div> <style> div { text-align: c ...

随机推荐

  1. Fedora21无法播放MP4[已解决]

    首先,安装安装rpmfusion源 http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-21.noarch.rpm ht ...

  2. SQL点滴17—使用数据库引擎存储过程,系统视图查询,DBA,BI开发人员必备基础知识

    原文:SQL点滴17-使用数据库引擎存储过程,系统视图查询,DBA,BI开发人员必备基础知识 在开发过程中会遇到需要弄清楚这个数据库什么时候建的,这个数据库中有多少表,这个存储过程长的什么样子等等信息 ...

  3. MVC 用扩展方法执行自定义视图,替代 UIHint

    MVC 用扩展方法执行自定义视图,替代 UIHint 项目中用了 Bootstrap , 这样就不用写太多的CSS了,省去很多事情.但是这个业务系统需要输入的地方很多,每个表都有100多个字段,每个页 ...

  4. c#生成word文档

    参考:http://blog.163.com/zhouchunping_99/blog/static/7837998820085114394716/ 生成word文档 生成word文档 view pl ...

  5. [Framework Design Guideline]

    [Framework Design Guideline]基础知识 最近在读<Framework design guideline>, 感觉其中Framework的许多设计经验同样适用于业务 ...

  6. 支付宝集成时的InvalidKeySpecException

    近来在集成第三方支付---支付宝,在集成的过程中严格按照支付宝开发者平台所发布的说明文档和Demo,在我的测试机上可以完美的运行,但是在别人的手机无论怎么就是调用不起来,总是弹出"remot ...

  7. UML基础概念

    UML概述 uml简介 uml(unified Modeling Language )为面向对象软件设计提供统一的.标准的.可视化的建模语言.适用于描述以用例为驱动,以体系结构为中心的软件设计的全过程 ...

  8. IOS UI 第二篇:基本UI

    1.UI书写:   一个小练习图片如下:     代码如下:     @implementation AppDelegate{    UIControl *control;    UILabel *l ...

  9. KMP 代码 暂存

    #include <stdio.h> #include <string.h> ],B[]; ]; int n, m; void _next(){ ; ; next[] = ; ...

  10. Webapi帮助文档

    生成自己的Webapi帮助文档(一) 最近Webapi接口的开发刚刚进入尾声,随之而来的是让用户知道接口的详细参数信息,看过淘宝的接口文档,但网上没找到他的实现方式 虽然新建Webapi时C#也会给你 ...