CSS魔法堂:那个被我们忽略的outline

前言

 在CSS魔法堂:改变单选框颜色就这么吹毛求疵!中我们要模拟原生单选框通过Tab键获得焦点的效果,这里涉及到一个常常被忽略的属性——outline,由于之前对其印象确实有些模糊,于是本文打算对其进行稍微深入的研究^_^

Spec是这样描述它的

作用

 用于创建可视对象的轮廓(元素的border-box),如表单按钮轮廓等。

与border不同

  1. outline不占文档空间;
  2. outline不一定是矩形。

具体属性说明

/* 轮廓线颜色 * invert表示为颜色反转,即使轮廓在不同的背景颜色中都可见 */
outline-color: invert | <color_name> | <hex_number> | <rgb_number> | inherit
/* 轮廓线样式 */
outline-style: none | dotted | dashed | solid | double | groove | ridge | inset | outset | inherit
/* 轮廓线宽度 */
outline-width: medium | thin | thick | <length> | inherit
/* 一次性设置轮廓线的颜色、样式 和 宽度 */
outline: <outline-color> <outline-style> <outline-width>;
/* 轮廓线的偏移量,大于0则轮廓扩大,小于0则轮廓缩小 */
outline-offset: 0px;

魔鬼在细节

兼容性

outline作为CSS2.1规范,因此IE6/7/8(Q)均不支持,在IE8下写入正确的DOCTYPE则支持outline属性。
outline-offset则IE下均不支持。

IE6/7/8(Q)下隐藏outline

若要在IE6/7/8(Q)下隐藏outline效果,则在元素上添加hideFocus特性即可。

outline:0outline:none的区别

在Chrome下执行如下代码

<style type="text/css">.outline0{outline: 0;}.outline-none{outline: none;}
</style>
<a href="#" class="outline0">outline: 0</a>
<a href="#" class="outline-none">outline: none</a>
<script type="text/javascript">const $ = document.querySelector.bind(document)const print = console.log.bind(console)const cssProps = ["outline-width", "outline-style", "outline-color"]const slctrs = [".outline0", ".outline-none"]slctrs.forEach(slctr => {styles = window.getComputedStyle($(slctr))cssProps.forEach(cssProp => {print("%s, %s is %s", slctr, cssProp, styles[cssProp])})})
</script>

结果:

.outline0, outline-width is 0px
.outline0, outline-style is none
.outline0, outline-color is rgb(0, 0, 238)
.outline-none, outline-width is 0px
.outline-none, outline-style is none
.outline-none, outline-color is rgb(0, 0, 238)

outline仅仅为设置单个或多个具体的outline属性提供更便捷的API而已,因此outline:0outline:none本质上效果是一致的。

真心没法弄出圆角

 自从有了border-radius后,我们就可以通过CSS制作圆角矩形、圆形等图形,甚至连box-shadow也受到border-radius影响从而实现元素阴影也能做到圆角的效果。那么outline是否也能做出圆角的效果呢?答案是否定的。那是因为outline的作用本来就是用于勾勒出元素所占的空间轮廓,通过border-radius虽然实现了图形视觉上的圆角,但该元素所占位置空间一点都没有变化,还是那个有棱有角的方形。

<style type="text/css">.round{width: 100px;height: 100px;background: yellow;border-radius: 50%;outline: solid 1px red;}
</style>

轮廓的差异

 在Chrome下outline仅限于标识当前元素自身所占的位置空间(border-box),但在FireFox下则包含子孙元素所占的位置空间。

<style type="text/css">.outline{width: 13px;height: 13px;outline: 1px solid red;}
</style>
<div class="outline"></div>
<script type="text/javascript">const el = document.querySelector(".outline")el.textContent = !!~navigator.appVersion.indexOf("Chrome") ? "Chrome" : "FireFox"
</script>

总结

 尊重原创,转载请注明来自:https://www.cnblogs.com/fsjoh... ^_^肥仔John

参考

https://www.xuebuyuan.com/757...
https://www.zhangxinxu.com/wo...

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389558.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

初创公司怎么做销售数据分析_初创公司与Faang公司的数据科学

初创公司怎么做销售数据分析介绍 (Introduction) In an increasingly technological world, data scientist and analyst roles have emerged, with responsibilities ranging from optimizing Yelp ratings to filtering Amazon recommendations and designing Facebook featu…

opencv:灰色和彩色图像的像素直方图及直方图均值化的实现与展示

直方图及直方图均值化的理论&#xff0c;实现及展示 直方图&#xff1a; 首先&#xff0c;我们来看看什么是直方图&#xff1a; 理论概念&#xff1a; 在图像处理中&#xff0c;经常用到直方图&#xff0c;如颜色直方图、灰度直方图等。 图像的灰度直方图就描述了图像中灰度分…

交换机的基本原理配置(一)

1、配置主机名 在全局模式下输入hostname 名字 然后回车即可立马生效&#xff08;在生产环境交换机必须有自己唯一的名字&#xff09; Switch(config)#hostname jsh-sw1jsh-sw1(config)#2、显示系统OS名称及版本信息 特权模式下&#xff0c;输入命令 show version Switch#show …

opencv:卷积涉及的基础概念,Sobel边缘检测代码实现及Same(相同)填充与Vaild(有效)填充

滤波 线性滤波可以说是图像处理最基本的方法&#xff0c;它可以允许我们对图像进行处理&#xff0c;产生很多不同的效果。 卷积 卷积的概念&#xff1a; 卷积的原理与滤波类似。但是卷积却有着细小的差别。 卷积操作也是卷积核与图像对应位置的乘积和。但是卷积操作在做乘…

r psm倾向性匹配_南瓜香料指标psm如何规划季节性广告

r psm倾向性匹配Retail managers have been facing an extraordinary time with the COVID-19 pandemic. But the typical plans to prepare for seasonal sales will be a new challenge. More seasonal products have been introduced over the years, making August the bes…

主成分分析:PCA的思想及鸢尾花实例实现

主成份分析算法PCA 非监督学习算法 PCA的实现&#xff1a; 简单来说&#xff0c;就是将数据从原始的空间中转换到新的特征空间中&#xff0c;例如原始的空间是三维的(x,y,z)&#xff0c;x、y、z分别是原始空间的三个基&#xff0c;我们可以通过某种方法&#xff0c;用新的坐…

两家大型网贷平台竟在借款人审核问题上“偷懒”?

python信用评分卡&#xff08;附代码&#xff0c;博主录制&#xff09; https://study.163.com/course/introduction.htm?courseId1005214003&utm_campaigncommission&utm_sourcecp-400000000398149&utm_mediumshare 放贷流量增加&#xff0c;逾期率也会随之增加&…

opencv:边缘检测之Laplacian算子思想及实现

Laplacian算子边缘检测的来源 在边缘部分求取一阶导数&#xff0c;你会看到极值的出现&#xff1a; 如果在边缘部分求二阶导数会出现什么情况? 从上例中我们可以推论检测边缘可以通过定位梯度值大于邻域的相素的方法找到(或者推广到大 于一个阀值). 从以上分析中&#xff0c…

使用机器学习预测天气_如何使用机器学习预测着陆

使用机器学习预测天气Based on every NFL play from 2009–2017根据2009-2017年每场NFL比赛 Ah, yes. The times, they are changin’. The leaves are beginning to fall, the weather is slowly starting to cool down (unless you’re where I’m at in LA, where it’s on…

laravel 导出插件

转发&#xff1a;https://blog.csdn.net/gu_wen_jie/article/details/79296470 版本&#xff1a;laravel5 php 5.6 安装步骤&#xff1a; 一、安装插件 ①、首先在Laravel项目根目录下使用Composer安装依赖&#xff1a; composer require "maatwebsite/excel:~2.1.0"…

国外 广告牌_广告牌下一首流行歌曲的分析和预测,第1部分

国外 广告牌Using Spotify and Billboard’s data to understand what makes a song a hit.使用Spotify和Billboard的数据来了解歌曲的流行。 Thousands of songs are released every year around the world. Some are very successful in the music industry; others less so…

Jmeter测试普通java类说明

概述 Apache JMeter是Apache组织开发的基于Java的压力测试工具。本文档主要描述用Jmeter工具对基于Dubbo、Zookeeper框架的Cassandra接口、区块链接口进行压力测试的一些说明&#xff0c;为以后类似接口的测试提供参考。 环境部署 1、 下载Jmeter工具apache-jmeter-3.3.zip&am…

opencv:Canny边缘检测算法思想及实现

Canny边缘检测算法背景 求边缘幅度的算法&#xff1a; 一阶导数&#xff1a;sobel、Roberts、prewitt等算子 二阶导数&#xff1a;Laplacian、Canny算子 Canny算子效果比其他的都要好&#xff0c;但是实现起来有点麻烦 Canny边缘检测算法的优势&#xff1a; Canny是目前最优…

opencv:畸变矫正:透视变换算法的思想与实现

畸变矫正 注意&#xff1a;虽然能够成功矫正但是也会损失了部分图像&#xff01; 透视变换(Perspective Transformation) 概念&#xff1a; 透视变换是将图片投影到一个新的视平面(Viewing Plane)&#xff0c;也称作投影映射(Projective Mapping)。 我们常说的仿射变换是透视…

数据多重共线性_多重共线性对您的数据科学项目的影响比您所知道的要多

数据多重共线性Multicollinearity is likely far down on a mental list of things to check for, if it is on a list at all. This does, however, appear almost always in real-life datasets, and it’s important to be aware of how to address it.多重共线性可能根本不…

K-Means聚类算法思想及实现

K-Means聚类概念&#xff1a; K-Means聚类是最常用的聚类算法&#xff0c;最初起源于信号处理&#xff0c;其目标是将数据点划分为K个类簇&#xff0c; 找到每个簇的中心并使其度量最小化。 该算法的最大优点是简单、便于理解&#xff0c;运算速度较快&#xff0c;缺点是只能应…

(2.1)DDL增强功能-数据类型、同义词、分区表

1.数据类型 &#xff08;1&#xff09;常用数据类型  1.整数类型 int 存储范围是-2,147,483,648到2,147,483,647之间的整数&#xff0c;主键列常设置此类型。 &#xff08;每个数值占用 4字节&#xff09; smallint 存储范围是-32,768 到 32,767 之间的整数&#xff0c;用…

充分利用昂贵的分析

By Noor Malik努尔马利克(Noor Malik) Let’s say you write a query in Deephaven which performs a lengthy and expensive analysis, resulting in a live table. For example, in a previous project, I wrote a query which pulled data from an RSS feed to create a li…

层次聚类和密度聚类思想及实现

层次聚类 层次聚类的概念&#xff1a; 层次聚类是一种很直观的算法。顾名思义就是要一层一层地进行聚类。 层次法&#xff08;Hierarchicalmethods&#xff09;先计算样本之间的距离。每次将距离最近的点合并到同一个类。然后&#xff0c;再 计算类与类之间的距离&#xff0…

通配符 或 怎么浓_浓咖啡的咖啡渣新鲜度

通配符 或 怎么浓How long could you wait to brew espresso after grinding? Ask a barista, any barista, and I suspect their answer is immediately or within a few minutes. The common knowledge on coffee grounds freshness is that after 30 minutes or so, coffee…