Home >Web Front-end >Front-end Q&A >Let's talk about css except the last style
h1 { color: red; font-size: 24px; }<p>The above code uses the tag selector to select all
<h1>
elements.
.text-red { color: red; }<p>Then use this class in HTML:
<p class="text-red">这里的文字是红色的。</p><p>The class selector can be used to uniformly set the style in the same page.
#my-title { font-size: 36px; }<p>Use this ID in HTML:
<h1 id="my-title">这是我的标题</h1><p>It should be noted that there can only be one same ID value in an HTML document.
input[type="submit"] { background-color: blue; }<p>The above code will set a blue background for all
<input>
elements whose type attribute is submit
.
.container .title { font-size: 24px; }<p>The above code means to select all descendant elements of class
title
in the element with class container
, and set their font size to 24 pixels .
a:hover { color: red; }<p>The above code means to set the color of the link to red when the mouse is hovering. <p>2. CSS box model <p>The CSS box model means that each part of an HTML element is a "box", including the content area, padding area, border area and margins. area. This model is important for understanding the overall structure and styling of HTML elements. <p>3. CSS Units <p>There are various units in CSS, which can be used to represent different style attributes to achieve various effects. Common units are:
p { font-size: 14px; }
.container { width: 80%; }<p>The above code means to set the width of
.container
to 80% of the width of its parent element.
em
is the font size relative to its own element, while rem
is the font size relative to the root element (usually an HTML element). For example:
h1 { font-size: 2.5em; } .container { width: 40rem; }<p>In the above code, the font size of the
h1
element is 2.5 times the font size of its own element, and the width of the .container
element is the font size of the root element 40 times.
.container { width: 80vw; height: 50vmin; }<p>In the above code, the width of the
.container
element is 80% of the viewport width, and the height is the greater of the viewport width and height. 50% of the smallest value.
<p>4. CSS properties
<p>CSS properties are various properties used to set the style of elements. Some of the common properties include:
h1 { color: red; }<p>The above code sets the text color of all
<h1>
elements to red.
.container { background-color: #f8f8f8; }<p>The above code sets the background color of the
.container
element to light gray.
.container { border: 2px solid black; }<p>The above code sets the border width of the
.container
element to 2 pixels, the color to black, and the border style to solid line.
p { font-size: 16px; }<p>The above code sets the font size of all
<p>
elements to 16 pixels.
h1 { text-align: center; }<p>上述代码将所有的
<h1>
元素的文本居中对齐。
<p>五、CSS框架
<p>CSS框架是指提供一组预定义的CSS样式和JavaScript交互,可以快速搭建网页的开发工具。常见的CSS框架有Bootstrap、Foundation、Materialize等。它们提供了大量的预设样式和交互组件,可以极大地加速开发的进度和提升用户体验。
<p>以上就是CSS的一些基本内容和重要性,虽然CSS的最后一个很重要,但我们也要关注其它内容,以了解并掌握CSS的全部知识,从而开发出更为优秀的网页。The above is the detailed content of Let's talk about css except the last style. For more information, please follow other related articles on the PHP Chinese website!