最近开始研究前端,会不定期更新一些小块代码,写下自己的学习笔记,也希望能和大家一起进步!

1.单个标签实现分隔线:

<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.line_01{
width: 180px;
padding: 0 20px 0;
margin: 20px 0;
line-height: 1px;
border-left: 200px solid #ddd;
border-right: 200px solid #ddd;
text-align: center;
}
</style>
</head>
<body>
<div class="line_01">小小分隔线 单标签实现</div>
</body>
</html>

优点:代码简洁

2.巧用背景色实现分隔线:

<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.line_02{
height: 1px;
border-top: 1px solid #ddd;
text-align: center;
}
.line_02 span{
position: relative;
top: -8px;
background: #fff;
padding: 0 20px;
}
</style>
</head>
<body>
<div class="line_02"><span>小小分隔线 巧用色实现</span></div>
</body>
</html>

  

优点:代码简洁,可自适应宽度

3.inline-block实现分隔线:

<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.line_03{
width:600px;
}
.line_03 b{
background: #ddd;
margin-top: 4px;
display: inline-block;
width: 180px;
height: 1px;
_overflow: hidden;
vertical-align: middle;
}
.line_03 span{
display: inline-block;
vertical-align: middle;
padding: 0px 20px;
}
</style>
</head>
<body>
<div class="line_03"><b></b><span>小小分隔线 inline-block实现</span><b></b></div>
</body>
</html>

  

优点:文字可多行

4.浮动实现分隔线:

<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.line_04{
width:600px;
}
.line_04{
overflow: hidden;
_zoom: 1;
}
.line_04 b{
background: #ddd;
margin-top: 8px;
float: left;
width: 26%;
height: 1px;
_overflow: hidden;
}
.line_04 span{
float: left;
padding: 0px 20px;
}
</style>
</head>
<body>
<div class="line_04"><b></b><span>小小分隔线 浮动来实现</span><b></b></div>
</body>
</html>

 

5.hr实现分割线

<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.hr-more {
height: 20px;
width: 70px;
position: relative;
left: 46%;
top: -18px;
font: normal 1.2em/20px 微软雅黑;
vertical-align: middle;
text-align: center;
border-radius: 4px;
background-color: #ffffff;
}
.div-box{
width: 600px;
}
</style>
</head>
<body>
<div class="div-box">
<hr/>
<div class="hr-more">更多</div>
</div>
</body>
</html>

  

6.fieldset 实现分割线

<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
fieldset {
border:none;border-top:1px solid blue;
} legend {
width: 120px;
text-align: center;
}
</style>
</head>
<body>
<fieldset>
<legend>fieldset分割线</legend>
</fieldset>
</body>
</html>

  

7.after伪类实现分割线

<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.hot {
width: 100%;
height: 20px;
text-align: center;
color: #000;
font-size: 12px;
line-height: 20px;
position: relative;
} .hot:after {
content: "";
width: 100%;
height: 1px;
background-color: #c5c0c0;
position: absolute;
bottom: 50%;
z-index: 1;
left: 0;
} .hot span {
z-index: 2;
position: relative;
background-color: #ffffff;
padding: 0 10px;
}
</style>
</head>
<body>
<div class="hot">
<span>伪类实现分割线</span>
</div>
</body>
</html>

  

css分割线 文字居中的7种实现方式的更多相关文章

  1. 通过CSS实现 文字渐变色 的两种方式

    说明 这次的重点就在于两个属性, background 属性 mask 属性这两个属性分别是两种实现方式的关键. 方式一 解释 <!DOCTYPE html> <html> & ...

  2. 简单说 通过CSS实现 文字渐变色 的两种方式

    说明 这次的重点就在于两个属性, background 属性 mask 属性 这两个属性分别是两种实现方式的关键. 解释 方式一 效果图 代码 <!DOCTYPE html> <ht ...

  3. css 图片文字居中

    1.单行文字居中 2.多行文字居中 3.利用background-position:center;的图片居中 4.利用display:table-cell;属性的图片居中 <!DOCTYPE h ...

  4. 使用CSS完成元素居中的七种方法

    在网页布局中元素水平居中比元素垂直居中要简单不少,同时实现水平居中和垂直居中往往是最难的.现在是响应式设计的时代,我们很难确切的知道元素的准确高度和宽度,所以一些方案不大适用.据我所知, 在CSS中至 ...

  5. CSS绝对定位元素居中的几种方法

    转载自-CSS居中绝对https://www.cnblogs.com/skura23/p/6530556.html 作者:PajamaCat 1,div宽度未知1 <body> <d ...

  6. 【前端】使用CSS使元素居中的几种方式

    Precondition: <div class="parent"> <div class="item">居中</div> ...

  7. css布局 - 垂直居中布局的一百种实现方式(更新中...)

    首先将垂直居中的现象和实现方式两大方向细分类如下: 接下来逐条累加不同情况下的垂直居中实现. 目录: 一.父元素高度固定时,单行文本 | 图片的垂直居中 1. line-height行高简单粗暴实现法 ...

  8. css中对position的几种定位方式的最佳诠释

    关于元素的position定位的理解,牛客网的hardy给出了一个比较好的理解: 在html中网页可以看成一个立体的空间,一个完整的页面是由很多个页面堆积形成的,如上图所示   CSS中Positio ...

  9. css文字居中、图片居中、div居中解决方案

    一.文字居中 若文字只有一行 <!--html代码--> <div class="box"> <p class="text"> ...

随机推荐

  1. 10集合:List<T>,Dictionary<K,V>

    List<T>泛型集合 List<T>是C#中一种快捷.易于使用的泛型集合类型,使用泛型编程为编写面向对象程序增加了极大的效率和灵活性.   1.List<T>用法 ...

  2. hash表的建立和查找

    (1)冲突处理方法为:顺次循环后移到下一个位置,寻找空位插入.(2)BKDE 字符串哈希unsigned int hash_BKDE(char *str){/* 初始种子seed 可取31 131 1 ...

  3. 微信开发python+django两个月的成功经历,django是个好框架!

        时间:大三 上学期没有用微信内置浏览器而纯对话开发,坑了自己好一下. 下学期选错bottle框架,以为轻量好,谁知开发中什么都自己来很痛苦. 选对了框架django,终于在大三最后的个把月里写 ...

  4. Oracle 面试宝典 - General Questions

    转自 http://www.orafaq.com/wiki/Interview_Questions Tell us about yourself/ your background. What are ...

  5. AJAX编程模板

    AJAX一直以来没怎么接触,主要是做JSON数据在服务器和客户端之间传递的时候,被玩坏了,对它莫名的不可爱,最近心理阴影小了,于是又来看看它....... AJAX即“Asynchronous Jav ...

  6. .htaccess内容

    <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENA ...

  7. linux 下面 opcache 拓展

    PHP 5.5.0 及后续版本中已经绑定了 OPcache 扩展,只需要在编译安装的时候, 如果你使用--disable-all参数 禁用了默认扩展的构建, 那么必须使用--enable-opcach ...

  8. SQL语句の集锦

    6.删除数据后根据主键从备份表中恢复 insert  sameTable_1 (name,dz) select name,dz from sameTable_1_bak where not exist ...

  9. OC 之 谓词

    NSPredicate 分类: Objective-C iOS XCode Mac2012-10-26 17:26 10557人阅读 评论(1) 收藏 举报 简述:Cocoa框架中的NSPredica ...

  10. NSNumber

    integerfloatc 在Objective-c中有int的数据类型,那为什么还要使用数字对象NSNumber?这是因为很多类(如NSArray)都要求使用对象,而int不是对象.NSNumber ...