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.pswp.cn/news/389558.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389558.shtml
英文地址,請注明出處:http://en.pswp.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;如顏色直方圖、灰度直方圖等。 圖像的灰度直方圖就描述了圖像中灰度分…

mysql.sock問題

Cant connect to local MySQL server through socket /tmp/mysql.sock 上述提示可能在啟動mysql時遇到&#xff0c;即在/tmp/mysql.sock位置找不到所需要的mysql.sock文件&#xff0c;主要是由于my.cnf文件里對mysql.sock的位置設定導致。 mysql.sock默認的是在/var/lib/mysql,…

交換機的基本原理配置(一)

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; 卷積的原理與濾波類似。但是卷積卻有著細小的差別。 卷積操作也是卷積核與圖像對應位置的乘積和。但是卷積操作在做乘…

機器學習股票_使用概率機器學習來改善您的股票交易

機器學習股票Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seek…

BZOJ 2818 Gcd

傳送門 題解&#xff1a;設p為素數 &#xff0c;則gcd(x/p,y/p)1也就是說求 x&#xff0f;p以及 y&#xff0f;p的歐拉函數。歐拉篩前綴和就可以解決 #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <map&…

LeetCode387-字符串中的第一個唯一字符(查找,自定義數據結構)

一開始想用HashMap&#xff0c;把每個字符放進去&#xff0c;然后統計出現的次數。 使用LinkedHashMap的話&#xff0c;鍵值對的順序都是不會變的。 LinkedHashMap<Character,Integer> map new LinkedHashMap<>();map.put(i,1111);map.put(j,2222);map.put(k,3333…

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;逾期率也會隨之增加&…

解決 Alfred 每次開機都提示請求通訊錄權限的問題

安裝完 Alfred 以后&#xff0c;每次開機都會提示請求通訊錄權限&#xff0c;把設置里的通訊錄關掉也沒用&#xff0c;每次都提示又非常煩人&#xff0c;這里把解決方法記錄一下。 依次打開 應用程序 - Alfred 3.app - 右鍵顯示包內容 - Contents - Frameworks - Alfred Framew…

【轉】DCOM遠程調用權限設置

原文&#xff1a;https://blog.csdn.net/ervinsas/article/details/36424127 最近幾天被搞得焦頭爛額&#xff0c;由于DCOM客戶端程序是在32位系統下開發的&#xff0c;調試時DCOM服務端也是安裝在同一臺機器上&#xff0c;所有過程一直還算順利。可這次項目實施的時候&#xf…

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是目前最優…

關于outlook簽名圖片大小的說明

96 dpiwidth576 height114轉載于:https://blog.51cto.com/lch54734/2298115