search
HomeWeb Front-endHTML TutorialCSS轮廓outline - 小火柴的蓝色理想

前面的话

  轮廓outline处在边框边界的外面,它不像边框那样参与到文档流中,因此轮廓出现或消失时不会影响文档流,即不会导致文档的重新显示。利用轮廓,浏览器可以合并部分轮廓,创建一个连续但非矩形的形状。默认地,轮廓是一个动态样式,只有元素获取到焦点或被激活时呈现

  [注意]IE7-浏览器不支持

 

轮廓样式

  与边框类似,轮廓最基本的方面是样式,如果一个轮廓没有样式,边框将根本不会存在。与边框不同的是,值少了一个hidden

outline-style

  值: none | dotted | dashed | solid | double | groove | ridge | inset | outset | inherit

  初始值: none

  应用于: 所有元素

  继承性: 无

 

轮廓宽度

  与边框类似,轮廓宽度不能为负数,也不能指定为百分比值

outline-width

  值: thin | medium | thick | | inherit

  初始值: medium

  应用于: 所有元素

  继承性: 无

  [注意]如果轮廓的样式是none,则轮廓宽度计算值为0

 

轮廓颜色

  与边框不同,轮廓颜色有关键字invert反色轮廓,代表对轮廓所在的像素完全反色转换,使轮廓在不同的背景颜色中都可见。但实际上invert关键字只有IE浏览器支持,其他浏览器的轮廓颜色是元素本身的前景色

outline-color

  值: | invert | inherit

  初始值: invert(IE)、前景色(其他浏览器)

  应用于: 所有元素

  继承性: 无

 

轮廓偏移

  轮廓偏移用来定义轮廓的偏移位置的数值。当参数值为正数时,表示轮廓向外偏移;当参数值为负值时,表示轮廓向内偏移

  [注意]IE浏览器不支持

outline-offset

  值: length | inherit

  初始值: 0

  应用于: 所有元素

  继承性: 无

 

轮廓

  轮廓outline类似于边框样式的border属性,允许一次完成轮廓样式、宽度和颜色的设置。由于给定轮廓必须采用某种统一的样式、宽度和颜色,所以outline是关于轮廓的唯一简写属性。对于轮廓没有诸如outline-top或outline-right之类的属性

  [注意]outline中并没有包括outline-offset,需要对outline-offset进行单独设置

outline

  值: [ || || ] | inherit

  初始值: 无

  应用于: 所有元素

  继承性: 无

 

应用

  由于轮廓outline不影响元素的盒模型大小,不影响页面布局,所以可以用outline模仿border边框效果。但如果是圆角边框就不是那么好办了。

  firefox浏览器支持私有属性-moz-outline-radius来设置轮廓圆角。该属性对应的js写法是MozOutlineRadius

  对于其他浏览器,我们可以使用其他属性实现类似效果。box-shadow与border-radius属性一脉相承,也就是说如果border-radius是圆角,则box-shadow的投影也是圆角

<span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="show"</span><span style="color: #0000ff;">></span>测试内容<span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span>
<span style="color: #800000;">.show</span>{<span style="color: #ff0000;">
    margin</span>:<span style="color: #0000ff;"> 50px</span>;<span style="color: #ff0000;">
    width</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;">
    height</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;">
    background-color</span>:<span style="color: #0000ff;"> pink</span>;<span style="color: #ff0000;">
    border-radius </span>:<span style="color: #0000ff;"> 1px</span>;<span style="color: #ff0000;">
    box-shadow</span>:<span style="color: #0000ff;"> 0 0 0 30px lightblue</span>;
}

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.