css 的text-decoration可以实现文字下方的下划线,但是距离文字比较近,不是很好看,我们可以使用border-bottom来模拟这个效果

(inline元素虽然不可以设置margin-top和margin-bottom,但是可以设置padding值和border)

body{
margin: 0;
} div {
width: 500px;
margin: 50px auto;
} span {
padding-bottom:2px;
color: red;
border-bottom:1px solid;
}
<div>
<span>下划线</span>
</div>

  设置border时,建议不要设置border的颜色,这样border默认就是文字的颜色,特别是在a标签中,hover时文字颜色改变,就可以实现下划线与文字颜色保持一致而不需要设置border的颜色

text-decoration目前浏览器支持不较好的属性:

text-decoration-line:none underline  overline line-through

text-decoration-style:solid  double  dotted  dashed  wavy  inherit

text-decoration-color

支持多值:

text-decoration: underline overline;

支持缩写:
text-decoration: underline wavy red;

  border,text-shadow边框色默认就是color属性的颜色

background-color:currentColor; css3 ie9+ 
就是当前的背景颜色由color决定
在iOS Safari浏览器下(iOS8)下,currentColor还是有一些bug的,例如伪元素hover时候,background:currentColor的背景色不会跟着变化

参考来自:http://www.zhangxinxu.com/wordpress/2016/11/css-text-decoration-underline-skip-override/

实现文字下划线 ---模拟text-decoration的更多相关文章

  1. android TextView 例子代码(文字中划线、文字下划线)

    XML: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  2. NSAttributedString能否设置文字下划线?是否支持line break?

    #import <CoreText/CoreText.h> #import "ViewController.h" @interface ViewController ( ...

  3. 1.1.15 word调整文字与下划线之间的间距

    先请按CTRL+U快捷键,或点击“下划线”按钮,然后输入一个空格,再输入文字“下划线间距”,在文字的尾部再添加一个空格.选中文字内容(注意不要选中首尾的空格),单击菜单“格式”→“字体”,在“字体”设 ...

  4. CSS样式下划线

    样式之文字下划线 第一 text-decoration: underline; 缺点是不好修改颜色 不要修改下划线的位置,优点就是一行代码解决 可以使用line-height: 20px; 也能调整位 ...

  5. iOS 给NSString文字上添加横线 中间和下划线

    有时候我们需要给文字添加横线,有两种情况: 第一种是贯穿中间的横线: 横线的颜色和文字的颜色保持一致 _oldPriceLabel.text = "; _oldPriceLabel.text ...

  6. WPF编程,TextBlock中的文字修饰线(上划线,中划线,基线与下划线)的使用方法。

    原文:WPF编程,TextBlock中的文字修饰线(上划线,中划线,基线与下划线)的使用方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_4330 ...

  7. 解决文字和text-decoration:underline下划线重叠问题

    一.text-decoration:underline下划线的问题 CSS text-decoration:underline可以给内联文本增加下划线,但是,如果对细节要求较高,就会发现,下划线经常会 ...

  8. WPF TextBlock 调整下划线与文字的距离

    <TextBlock Foreground="> <TextBlock.TextDecorations> <TextDecorationCollection&g ...

  9. UI-切圆角、透明度、取消按钮点击高亮效果、按钮文字带下划线

    一.切UIView的某个角为圆角 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某 ...

随机推荐

  1. java通过反射获取bean字段注解@Column中的信息

    直接上代码吧: Field field; Field[] fields=clas.getDeclaredFields(); for (int i = 0; i <fields.length ; ...

  2. Ubuntu 16.04下快速在当前目录打开终端的快捷键设置

    说明:不一定每次都准确打开,80%的机会是行的. 原理:使用xdotool模拟键盘按键,打开的文件夹管理界面,然后通过Ctrl+L获取地址栏地址,然后传递到终端上. 安装: 1.安装xdotool s ...

  3. js如何获取table或者ul中鼠标点的行号和内容

    <html> <head> <script language="javascript"> function doclick() { var td ...

  4. react+flask+antd

    待学习: 1.https://www.cnblogs.com/jlj9520/p/6625535.html 2.http://python.jobbole.com/87112/ 3.

  5. fatal error C1189: #error : core.hpp header must be compiled as C++

    两次opencv工程需要设置为C++编译:找了一半天的解决方法. I am building a C application that uses OpenCV. when compiling, I g ...

  6. [转]PHP并发IO编程之路(深度长文)

    原文:https://www.imooc.com/article/8449 -------------------------------------------------------------- ...

  7. GridView的经常使用属性

    1.android:numColumns="auto_fit"   //GridView的列数设置为自己主动 2.android:columnWidth="90dp &q ...

  8. 【Leetcode】经典的Jump Game in JAVA

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  9. [Python-MATLAB] 在Python中调用MATLAB的API

    可以参考官方的说明文档: http://cn.mathworks.com/help/matlab/matlab_external/get-started-with-matlab-engine-for- ...

  10. cocos2dx学习进度

    将cocos2dx实战上面的例子都自己过一遍,手动敲一边里面的代码,瓦片地图,地图滚动,碰撞,容器类,现在搞到了fileUtils相关的了,哦,官方叫做数据持久化,一不小心就6点了,时间过得太快了,看 ...