结构-行为-样式-Css Div 居中的一个最佳实践
最近在做项目的时候,经常会有需要各种居中的情况,现在分享一个最佳实践。
<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 居中的一个最佳实践的更多相关文章
- 结构-行为-样式-Css笔记
0.常见的行级元素和块级元素: 行级元素:div,table,form ,ul,ol,p,h1-h6,hr; 块级元素:a,select,input,textarea,img,label,br,i, ...
- CSS UNIT 详解以及最佳实践
分类 ■ 绝对长度(Absolute units):cm,mm,in,pt,pc 绝对单位之间的换算:1in = 2.54cm=25.4mm=72pt=6pc 绝对长度在css中的表现和其他地方 ...
- 结构-行为-样式-css&html横纵居中最佳实践
最近在做手机端的H5项目,有个标题是在一根横线中的,就是水平居中加垂直居中(如图一).这应该是前端开发中经常遇到的一个场景了,做的次数多了就有一些体会,我今天就总结了下这种结构的实现思路:首先,用元素 ...
- css div居中
div中没有text-align和vehicle-align这两个属性,所在在css中设置这两个值没有作用 div 水平居中 设置左右边距有auto div{ margin: 0 auto; } 垂直 ...
- css div居中显示的4种写法
Demo:http://www.feman.cn/h5/center.html .absolute 绝对定位 这是我们最常用的一种居中定位写法 要求必须确定div的宽高度 目前市面上的浏览器基本上都支 ...
- CSS——div居中,window.open(0
margin:0 auto 表示什么意思?? margin后面如果只有两个参数的话,第一个表示top和bottom,第二个表示left和right因为0 auto,表示上下边界为0,左右则根据宽度自适 ...
- 自己用jquery+css+div写的一个弹窗
弹窗支持两种模式,一种是普通信息提示框,调用方法:popup.msgPopup(msg); 另一种是可以加载页面的弹窗,调用方法:popup.pagePopup(url); 效果图: css代码 ;; ...
- CSS DIV 居中
左右居中 margin-left: auto; margin-right: auto; 上下居中
- CSS - div居中在屏幕中(水平居中 + 垂直居中)
方法一代码 <div> <h1>404 Not Found.</h1> </div> <style> div { text-align: c ...
随机推荐
- 腾讯QQ音乐网页版 音频初始化模块解压混淆js源码
define("js/view/playerBar.js",function(t,e,o){ var i = t("js/lib/zepto.js"), a = ...
- openwrt构建过程探索
参考网站:http://wiki.openwrt.org/doc/howto/buildroot.exigence 需要下载必要的库文件,编译器等... 1 首先要获得openwrt的源码,参考ope ...
- android 删除SD卡或手机的缓存图像和文件夹
public static final String TEMP_PHOTO_FILE_NAME = "temp_photo.jpg"; private static String ...
- 必须掌握的JavaScript基本知识
作为一个前端工作者,应该了解一些javascript的发展历史,javascript实现及版本等.基本概念包括语法.关键字.变量.数据类型.操作符.语句控制及函数等,它们和我们学习的其它语言C/C++ ...
- Liunx readlink命令
readlink命令 分类: Shell 2013-07-13 16:41 417人阅读 评论(0) 收藏 举报 readlink是linux系统中一个常用工具,主要用来找出符号链接所指向的位置. 在 ...
- Dynamics CRM不发布JS调试
本博客已迁移至 http://www.krely.cn/ 上个项目做了一年多,大多是在做JS的开发,由于开发人数比较多,着实被坑的不轻.因为JS修改完成之后必须要发布,对于我们动辄几千行的JS的调 ...
- 10-18 noip提高组模拟赛(codecomb)T1倍增[未填]
T1只想到了找环,> <倍增的思想没有学过,所以看题解看得雨里雾里的(最近真的打算学一下! 题目出的挺好的,觉得noip极有可能出现T1T2T3,所以在此mark 刚开始T1以为是模拟,还 ...
- elasticsearch文档-modules
elasticsearch文档-modules modules 模块 cluster 原文 基本概念 cluster: 集群,一个集群通常由很多节点(node)组成 node: 节点,比如集群中的每台 ...
- [转]Building a Basic Fuzzer with GDB: The Five Minute GDB Scripting Tutorial
link:http://www.praetorian.com/blog/building-a-basic-fuzzer-with-gdb-the-five-minute-gdb-scripting-t ...
- ARM备忘
mov: move sub: subtract cmp: compare cmpls: ls--->lower or same, le--->less or equal, hi---> ...