CSS, Cascading Style Sheets, is a style language used for web design. With CSS, you can change the appearance, layout, and behavior of individual elements on an HTML page.
CSS was originally created by developers at Specter Corporation and became an industry standard in 1996. With the development of the Internet and the emergence of the HTML language, CSS has become one of the most widely used web design tools.
Let’s take a look at the basic uses of CSS.
By using CSS, you can easily change the size, color, font and other attributes of the text on the page. For example, you can use the following code to change the text style of a paragraph:
p { color: blue; font-size: 16px; font-family: Arial; }
This code block will change the text color of all paragraphs to blue, the text size to 16 pixels, and the font to Arial.
CSS also allows you to control the position and layout of individual elements on the page. By using positioning and float properties in CSS, you can easily achieve complex layout effects. For example, you can use the following code block to implement a simple header and footer layout:
header { background-color: gray; height: 100px; } footer { background-color: gray; height: 50px; position: absolute; bottom: 0; width: 100%; }
This code block changes the background color of the header element (header) in the page to gray and the height to 100 pixels . The background color of the footer element (footer) in the page is also changed to gray, the height is 50 pixels, and it is positioned at the bottom of the page.
With the popularity of mobile phones and tablets, people are increasingly using mobile devices to browse the web. This also leads to a new need: website design that can adapt to different screen sizes.
CSS realizes the design of responsive web pages through the media query (Media Queries) function. By using responsive layout technology, you can easily style and lay out different styles and layouts for different devices and screen widths.
@media screen and (max-width: 600px) { /* 小于600像素宽度时的样式 */ body { font-size: 14px; } } @media screen and (min-width: 601px) and (max-width: 900px) { /* 在601像素至900像素宽度范围内的样式 */ body { font-size: 16px; } } @media screen and (min-width: 901px) { /* 大于900像素宽度时的样式 */ body { font-size: 18px; } }
This code block will set three different viewport width ranges for the page, and set different font sizes in different ranges.
To summarize, CSS is a style language used to design web pages. It can be used to change the appearance, layout and behavior of each element on an HTML page. By mastering CSS, you can design beautiful, powerful and easy-to-use web pages, making your web pages and websites more attractive and easy to use.
The above is the detailed content of What is css? What is the use?. For more information, please follow other related articles on the PHP Chinese website!