Table of Contents
Shadow:
box-shadow
text-shadow
Background
background-size
background
Rounded border
Home Web Front-end CSS Tutorial A brief introduction to shadow, background and rounded border styles in CSS3

A brief introduction to shadow, background and rounded border styles in CSS3

Apr 27, 2017 pm 02:17 PM

It has been 7 years since CSS2.1 was released. The emergence of CSS3 is to enhance the functions of CSS2.1, reduce the use of images and solve special effects on HTML pages

Currently, the features of CSS3 technology most suitable for use in mobile Web development include:

●Enhanced selector

●Shadow

●Powerful background setting

●Rounded border

Shadow:

The current CSS3 style already supports shadow style effects. There are two types of shadow effects currently available: shadow effects for text content and shadow effects for elements.

box-shadow

The box-shadow property of CSS3 gives the element a shadow effect. Its syntax is as follows:

   box-shadow:<length> <length> <length> | color:
Copy after login

The first length is the horizontal offset of the shadow. value; the second length value is the shadow vertical offset value; the third value is the shadow blur value. The horizontal and vertical offset values ​​​​can take positive and negative values, such as 4px or -4px.

At present, box-shadow has been supported by most modern browsers. However, when we use this attribute on Webkit-based browsers such as Chrome and Safari, we need to write the name of the attribute in the form of -webkit-box-shadow. For Firefox browser, it should be written in the form of -moz-box-shadow.

The following code is a simple example of using box-shadow, which is compatible with Chrome, Safari and Firefox browsers:

<style type="text/css">
        p
        {
            /* 其他浏览器 */
            box-shadow: 3px 4px 2px #000;
            /* webkit内核浏览器 */
            -webkit-box-shadow: 3px 4px 2px #000; 
            /* Firefox浏览器 */
            -moz-box-shadow: 3px 4px 2px #000;
            padding:5px 4px;
        }
    </style>
Copy after login

text-shadow

The text-shadow attribute is used Set the shadow effect or blur effect of text content.

Currently, the text-shadow attribute is supported by Safari, Firefox, Chrome and Opera browsers. Browsers below IE8 do not support this feature. And, most mobile web browsers are well supported.

The syntax of text-shadow is basically the same as that of box-shadow:

box-shadow: | color:

The following code is a simple and practical example of text-shadow:

 <style type="text/css">
        p
        {
            text-shadow: 5px -10px 5px red;
            color:#666;
            font-size:16px;
        }
    </style>
Copy after login

Background

In the CSS3 specification, CSS3 adds many new features to the background attribute. It supports both the display range of the background and multiple image backgrounds. The most important thing is that it can set gradients or any color effects for the background color through attribute settings, which is very versatile.

CSS3 enhances the background attribute. In the past, we used pictures to replace various page modifications, and gradually they can be replaced by the background attribute. These features improve page loading speed, especially on mobile device platforms, and are a page performance improvement.

background-size

The background-size attribute is used to set the size of the background image.

At present, this attribute has been supported by Chrome, Safair, and Opera browsers. At the same time, this attribute also supports web browsers on Android and IOS platforms.

The background-size attribute has certain syntax differences in different web browsers. In the Chrome and Safari browsers based on the Webkite kernel, the writing method is -webkit-background-size;

In mobile development projects, it is recommended to use the compatibility mode writing method, the example is as follows:

 <style type="text/css">
        p
        {
            background-size:10px 5px;
            -webkit-backgriud-size:10px 5px;
        }
    </style>
Copy after login

background

The background attribute is given a very powerful function in CSS3. One of the very important features is multiple backgrounds. In the past, only one image could be used, but multiple background images can be set in CSS3. The syntax is as follows:

  background:url(bg.jpg) left top no-repeat,
                             url(bg2.jpg) left top no-repeat;
Copy after login

Both Chrome and Safari browsers support multiple background images with the background attribute. Since they are Webkit-based browsers, this feature is also supported by mobile browsers on Android and IOS platforms. However, since setting the background using pictures will seriously affect the overall experience and performance of the mobile Web, we use a feature in Webkit to use a color gradient for the background instead of using pictures. The syntax is as follows:

      -webkit-gradient(<type>, <type> [,<radius> ]?,<point> [, <radius> ]? [, <stop> ]*)
Copy after login

The type type refers to the gradient type, such as linear gradient linear or radial gradient radial. The following code:

<style type="text/css">
        p
        {
            background: -webkit-gradient(linear,0 0,0 100%,form(#ff),to(#000));
        }
</style>
Copy after login

Rounded border

In CSS3, the rounded corner effect can be easily achieved. As long as the border-radius attribute is defined in the code, the rounded corner effect can be achieved at will.

So far, this attribute has been supported by Chrome, Safari, Opera and Firefox browsers. However, there are some differences in writing methods between browsers. For example: Chrome and Safari browsers need to write -webkit-border-radius; Firefox browsers need to write -moz-border-radius; the compatible sample code is as follows:

<style type="text/css">
        p
        {
             border-radius:10px 5px;
             /* Firefox浏览器 */
             -moz-border-radius:10px 5px;
             /* webkit 内核浏览器 */
             -webkit-border-radius:10px 5px;
        }
    </style>
Copy after login

It should be noted that the border-radius attribute is not allowed to use negative values. When one of them is 0, the corner corresponding to the value is a rectangle, otherwise it is a rounded corner.

The above is the detailed content of A brief introduction to shadow, background and rounded border styles in CSS3. 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to achieve wave effect with pure CSS3? (code example) How to achieve wave effect with pure CSS3? (code example) Jun 28, 2022 pm 01:39 PM

How to achieve wave effect with pure CSS3? This article will introduce to you how to use SVG and CSS animation to create wave effects. I hope it will be helpful to you!

How to set a picture as the background in OneNote How to set a picture as the background in OneNote May 14, 2023 am 11:16 AM

Onenote is one of the best note-taking tools offered by Microsoft. Combined with Outlook and MSTeams, Onenote can be a powerful combination for increasing productivity at work and in personal creative productivity. We have to take notes in a different format, which may be more than just writing things down. Sometimes we need to copy images from different sources and do some editing in our daily work. Images pasted on Onenote can go a long way if you know how to apply the changes. Have you ever encountered a problem when using Onenote that images pasted on Onenote cannot allow you to work easily? This article will look at using images effectively on Onenote. we can

Detailed explanation of how to deal with all font shadows in Win10 computer Detailed explanation of how to deal with all font shadows in Win10 computer Jul 23, 2023 pm 11:13 PM

In the process of using the computer, some problems may occur due to improper operation and other situations. Recently, some netizens said that what to do with all the font shadows on their win10 computers, which affects viewing, and the icons on the desktop have shadows. The editor below will teach you how to clear all font shadows on your computer desktop. The specific steps are as follows: 1. First turn on the computer, enter the win+r key combination, open the run window, and enter gpedit.msc to confirm. 2. Find Enable ActiveDesktop, double-click it to open it, and disable it. 3. Next we need to open the disable ActiveDesktop button below, and then enable it. 4. Then open the system of the control panel, open its advanced system settings properties, and then enter the Properties

Use CSS skillfully to realize various strange-shaped buttons (with code) Use CSS skillfully to realize various strange-shaped buttons (with code) Jul 19, 2022 am 11:28 AM

This article will show you how to use CSS to easily realize various weird-shaped buttons that appear frequently. I hope it will be helpful to you!

Win11 new version of drawing: remove background with one click to realize cutout function Win11 new version of drawing: remove background with one click to realize cutout function Sep 15, 2023 pm 10:53 PM

Microsoft invites WindowsInsider project members in the Canary and Dev channels to test and experience the new Paint application. The latest version number is 11.2306.30.0. The most noteworthy new feature of this version update is the one-click cutout function. Users only need to click once to automatically eliminate the background and highlight the main body of the picture, making it easier for users to perform subsequent operations. The whole step is very simple. The user imports the picture in the new layout application, and then clicks the "removebackground" button on the toolbar to delete the background in the picture. The user can also use a rectangle to select the area to remove the background.

How to hide elements in css without taking up space How to hide elements in css without taking up space Jun 01, 2022 pm 07:15 PM

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

How to implement lace borders in css3 How to implement lace borders in css3 Sep 16, 2022 pm 07:11 PM

In CSS, you can use the border-image attribute to achieve a lace border. The border-image attribute can use images to create borders, that is, add a background image to the border. You only need to specify the background image as a lace style; the syntax "border-image: url (image path) offsets the image border width inward. Whether outset is repeated;".

How to replace all ppt backgrounds How to replace all ppt backgrounds Mar 25, 2024 pm 04:25 PM

PPT background replacement is an important operation that can quickly unify the visual style of the presentation. You can quickly replace the background of your entire presentation by modifying the slide master or using the Format Background feature. In addition, some PPT versions also provide a batch replacement function, which can easily replace the background of all slides. When replacing the background, you should pay attention to choosing a background that matches the theme of the presentation, and ensure that the background clarity and resolution meet the requirements.

See all articles