search
HomeWeb Front-endHTML TutorialCSS3 series two (media support, text and font related styles, box related styles)_html/css_WEB-ITnose

CSS3 media support

In css3, we can choose a page layout in the style to accurately adapt to different devices without changing the content, thereby improving User experience

You can use the meta tag in the page to specify the window width of how many pixels the browser will use when processing this page. The specification method is as follows

<meta name="viewport" content="width=600px" />

CSS can determine the devices that the style is applicable to by setting media, such as screen, tv, print, speech, handheld, all, etc.

<style media="all"><link media="print" href="xxx.css">

CSS3 can be based on more Set the visual properties, such as height, width, aspect ratio, resolution, device size, etc.

<style media="screen and (min-width:600px) and (max-width:900px)">

Specifically, the usage of Media Queries is as follows:

The values ​​that can be specified in Media Queries are the same as the The device type represented by the value is as follows:

The description of the specific device characteristics in Media Queries is as follows:

Use the and keyword to specify the style to be used when the value of a certain feature of a certain device type meets a certain condition

Use multiple statement to apply the same style to different device types and device characteristics

You can add the not keyword or the only keyword in the expression. The not keyword means that the following expression Perform the negation operation

The role of the only keyword is to allow browsers that do not support Media Queries but can read Media Type devices to hide the expression style

Add shadow to text

Wrap text automatically

For Western text, the browser will add half-width spaces or hyphens Automatically wrap lines in places without sudden line breaks in the middle of words. When Chinese text contains punctuation marks, it is always impossible for the browser to place the punctuation mark at the beginning of a line of text.

You can use the word-break attribute in css3 to determine the processing method of automatic line wrapping

Let long words and URL addresses wrap automatically

        div {            word-wrap:break-word;        }

Using server-side fonts

Webfonts is a very early CSS technology that allows the page to render specific fonts by downloading font files.

When using the @font-face attribute to display local fonts on the client, you need to modify the URL attribute value of the font file path to an attribute value in the form of local(), and add the following Write the font used in brackets

Declare the format of the font file in the format attribute value (when using the TrueType file format, set the format attribute value to truetype, when using the OpenType format, set the format attribute value to opentype . The file extension of TrueType is ttf, and the file extension of OpenType format is otf. When using server-side fonts in IE, you can only use Microsoft's own Embedded OpenType font file, the file extension is eot)

In the @font-face attribute, the attribute values ​​that can be specified are as follows:

Here we talk about the use of the font-size-adjust attribute. In fact, the method of use is very simple, but you need to use an aspect value (proportion value) that comes with each font

Quoting a browser method for calculating aspect values ​​introduced in "The Authoritative Guide to HTML5 and CSS3"

1. The width and height attributes can only be used on block type elements and have no effect on inline type elements.

2. By default, the table element attribute is of block type, so it cannot It is in the same line as other text, but if the table element is modified to the inline-table type, the table can be in the same line as other text

3. When specifying the element as run-in or compact type, If there is a block type element after the element, the run-in type element will be included inside the block type element, and the compact type element will be placed to the left of the block type element

4. css3 All table-related elements and their types are as follows

The support of each browser for various box types

Exceed the part to display ellipses

        div {            white-space:nowrap;/*使得盒右端的内容不能换行显示,这样一来盒中的内容就在水平方向上溢出了*/            overflow:hidden;/*超出div元素部分的文字将会被隐藏起来*/            text-overflow:ellipsis;/*在div元素的末尾出现一个省略号*/        }

box-shadow The usage method is exactly the same as text-shadow.

box-sizing: You can specify whether the width and height values ​​specified with the width attribute and height attribute respectively include the padding area inside the element, and the width and height of the border

The purpose of using the box-sizing attribute is to control the total width of the element. If this attribute is not used, the content-box attribute value is used by default in the style, which only specifies the width of the content. However, the total width of the element is not specified. In some cases, using the border-box attribute value will make the page layout more convenient

Title

Paragraph

Some other important details in CSS3

1) You may think that there is no big difference between the alpha channel and opacity of setting the color value. In fact, you need to use the alpha channel for both the background color and the text color at the same time. To achieve the effect of using opacity

2) If the color value is specified as transparent, the color of the background, text or border will be set to be completely transparent, which is equivalent to using an alpha channel with a value of 0 (in In css3, transparent values ​​can be specified in all attributes that specify color values)

3) Everyone knows that the outline attribute is used in css2 to draw an outline around the element. The specific usage method is as follows

By default, for elements with borders, using the outline attribute will draw an outline close to the outside of the border. What if we want the outline to deviate outward by a few pixels? The newly added outline-offset attribute in CSS3 has this effect. It is very simple to use. Just specify an integer value with pixel units for it. If it is specified as a positive integer, it will be offset outwards. If it is specified as a negative integer, then Offset inward

4) The resize development of css3 allows users to modify the size of elements by dragging and dropping (mainly used in any container element using the overflow attribute)

can be resized The values ​​specified by attributes are divided into the following types:

5) In CSS3, you can use the initial attribute value to cancel the style specification of the element, but in individual cases, use the initial attribute for the element The display result after the value is not equal to the result after directly deleting the style setting of the element (because after adding the style setting of the initial attribute value, the font size and font thickness of the element are set using the font size and font thickness attributes in CSS. A certain default value, regardless of what styles the browser adds to the element)

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
HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

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 Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools