How to set CSS3 var variables in HTML tags and JS
The content of this article is about how to set CSS3 var variables in HTML tags and JS. It has certain reference value and friends in need You can refer to it, I hope it will be helpful to you.
1. Set the CSS variables in the HTML tag
as follows:
<div style="--color: #cd0000;"> <img src="/static/imghw/default1.png" data-src="mm.jpg" class="lazy" style="max-width:90%" alt="How to set CSS3 var variables in HTML tags and JS" > </div>
Just set it in the style attribute just like a normal CSS statement.
The effect is as follows:
2. Set CSS variables in JS
as follows, HTML representation:
< ;div id="box">
< /div>
If you want var (--color) to take effect, execute the following JavaScript code:
box.style.setProperty('--color', '#cd0000' );
That is, use the setProperty() method, the effect is as follows GIF screenshot:
3. Obtain CSS variables in JS
You can use the getPropertyValue() method to obtain CSS variables in JS, as shown below:
// 获取 --color CSS 变量值 var cssVarColor = getComputedStyle(box)。getPropertyValue('--color'); // 输出cssVarColor // 输出变量值是:#cd0000 console.log(cssVarColor);
4. About CSS3 var() variables
CSS3 var() variables are a good thing, when they were introduced 2 years ago Not many browsers support it yet, but now, Edge16 also fully supports it.
The above is an introduction to how to set CSS3 var variables in HTML tags and JS. If you want to know more about CSS3 tutorial, please pay attention PHP Chinese website.
The above is the detailed content of How to set CSS3 var variables in HTML tags and JS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



HTML (HyperTextMarkupLanguage) is a standard language for creating Web pages. It uses tags and attributes to describe various elements on the page, such as text, images, tables, links, etc. However, when processing HTML text, it is difficult to quickly extract the text content for subsequent processing. At this time, we can use regular expressions in Python to remove HTML tags to quickly extract plain text. In Python, regular tables

How to use regular expressions to extract HTML tag content in Go language Introduction: Regular expression is a powerful text matching tool, and it is also widely used in Go language. In the scenario of processing HTML tags, regular expressions can help us quickly extract the required content. This article will introduce how to use regular expressions to extract the content of HTML tags in Go language, and give relevant code examples. 1. Introduce related packages First, we need to import related packages: regexp and fmt. regexp package provides

PHP is a commonly used server-side scripting language that is widely used in website development and back-end application development. When developing a website or application, you often encounter situations where you need to process HTML tags in strings. This article will introduce how to use PHP to remove HTML tags from strings and provide specific code examples. Why do you need to remove HTML tags? HTML tags are often included when processing user input or text obtained from a database. Sometimes we want to remove these HTML tags when displaying text

In PHP, you can use the htmlentities() function to escape html, which can convert characters into HTML entities. The syntax is "htmlentities(string,flags,character-set,double_encode)". You can also use the html_entity_decode() function in PHP to de-escape html and convert HTML entities into characters.

String is a final class in Java, it is immutable, which means we cannot change the object itself, but we can change the reference of the object. HTML tags can be removed from a given string using the replaceAll() method of String class. We can remove HTML tags from a given string using regular expressions. After removing the HTML tags from the string, it returns a string as normal text. Syntax publicStringreplaceAll(Stringregex,Stringreplacement) example publicclassRemoveHTMLTagsTest{&nbs

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

We can easily add HTML tags in the table. HTML tags should be placed inside <td> tags. For example, add paragraph <p>…</p> tags or other available tags inside the <td> tag. Syntax The following is the syntax for using HTMl tags in HTML tables. <td><p>Paragraphofthecontext</p><td>Example 1 An example of using HTML tags in an HTML table is given below. <!DOCTYPEhtml><html><head&g

PHP is an efficient web development language that supports regular expression functions and can quickly verify the validity of input data. In web development, HTML is a common markup language, and validating HTML tags is a very important method for web form validation. This article will introduce basic HTML tag verification methods and how to use PHP regular expressions for verification. 1. Basic structure of HTML tags HTML tags consist of element names and attributes surrounded by angle brackets. Common tags include p, a, div
