Table of Contents
border and outline:
Home Web Front-end CSS Tutorial Analysis of the difference between outline and border in css

Analysis of the difference between outline and border in css

Jul 27, 2017 am 09:21 AM
border outline

border and outline:

border attributes:

border-width, border-style, border-color where border-style can be none or hidden

outline (outline)
Draw a line surrounding the element around the edge of the element's border, including outline-color, outline-style, outline- The settings of the three sub-properties of width can be defaulted and there is no fixed order. Outlines do not take up page space and are not necessarily rectangular.
Browsers other than IE directly support outline. Only IE8 and above browsers that specify !DOCUMENT support outline.

outline-style can be none (does not contain the hidden attribute)

##Summary: The differences between the two are:
1.outline does not take up space and does not add extra width or height (this will not cause reflow or repaint when the browser renders)
2.outline has It may be non-rectangular (under Firefox browser)

In FireFox browser, there are rounded corners matching outlineoutline-radius

Example:

Use outline to achieve the following effect


<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>直角三角形(右下角)</title>
    <style type="text/css">
        .use-outline-offset{
            margin-left: auto;
            margin-right: auto;
            width: 200px;
            height: 200px;
            border:40px solid #000000;
            background-color:#cccccc;
            outline-width:40px;
            outline-style:dotted;
            outline-offset:-80px;
            box-sizing: border-box;
        }
    </style></head><body><p class="use-outline-offset"></p></body></html>
Copy after login

Rendering:

box-shadow simulates the rounded corner effect of outline

outline-radiusAlthough No chance, but we can use other attributes to achieve similar effects. For example, box-shadow.

, one of the masters of graphics construction, we usually use

box- The most common parameters of shadow are the first three parameters, horizontal/vertical offset and blur size. Some friends may not know the purpose of the fourth optional parameter value? box-shadowThe fourth parameter value, expansion outside the name, can expand the projection range. Of course, the expanded area is a solid color area. We can use this feature to simulate the outline solid color border effect that does not affect the size of the element!

Example first, the code is as follows:


<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>圆角</title>
    <style type="text/css">
        .outline-radius {
            margin: 200px auto;
            width: 400px;
            height: 300px;
            border-radius: 1px;
            box-shadow: 0 0 0 30px #cd0000;
        }
        .outline-radius>img{
            width: 100%;
            height: 100%;
        }
    </style></head><body><p class="outline-radius">
    <img src="img/mm1.jpg"></p></body></html>
Copy after login

The rendering is as follows:

The following is a brief explanation of the meaning of the next two lines of CSS code:

  1. ##border-radius: 1px represents the rounded corner size 1 pixel. Some students may be surprised, why is it 1 pixel? The rounded corners of the screenshot are obviously dozens of pixels, which is explained below;

  2. box- shadow: 0 0 0 30px #cd0000There are 4 values ​​​​appearing, namely horizontal offset 0, vertical offset 0, blur 0 (solid color), and expanded size 30 pixels. We can imagine that the light is shining directly from above the box, because there is no offset or blur, and we cannot see any shadows. In fact, the shadow of the box is exactly the size of the box (with a 1-pixel rounded corner). At this time, it is expanded by 30 pixels. We can imagine that the shadow of the 1-pixel rounded corner is expanded by an additional 30 pixels. Oh, isn’t it the effect we need? Isn’t it the effect shown in the screenshot?

    You know

    border-radius It’s about 1 pixel, right? After extending it by 30 pixels, the rounded corners will be 30 pixels in size.

#However, although it is not visible to the naked eye, the above method is actually flawed because the image is not a pure right angle, but has a 1-pixel rounded corner. If you want to achieve a perfect inner square and outer circle effect, you can add a layer of labels, and use

border-radius and box-shadow for the outer labels.

The above is the detailed content of Analysis of the difference between outline and border in css. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles