


Check out these two CSS interview questions to test your foundation!

1 2 3 |
|
1 2 3 4 5 6 |
|
<p>
green or blue? <p>Interestingly, the final result here is blue, which means color: blue
takes effect. [Recommended learning: css video tutorial]<p>
<p>
element and only saw color: green
taking effect, but no div:: was found. The style definition of first-line
: <p>
can we find the final You can see such a rule below:
<p>
tag inherits the parent element
This rule applies to the first row of elements, overwriting the
color: green
defined in the original ID selector. Verify again
Here, another confusing point is why the ID selector has a higher priority than <p>::first-line The selector is lower.
Let’s make some simple attempts: <p>The following DEMO shows the priority comparison of the <p>::first-line style and various selectors when they work together. Even
!important rules are included:
- Paragraph 1 is set to gray via the tag selectorParagraph 2 is set to gray via the class selectorThe 3rd paragraph is set to gray through the ID selector The 4th paragraph is set to gray through !important bash
selector.
1 2 3 4 5 6 7 8 9 10 11 |
|
CodePen Demo -- ::first-line: demo<p>https://codepen.io/KittyGiraudel/pen/kWobaa/569e082a67400f5fb39a96030d0e9b6c<p>Look at the effect: <p><p>

.
The reason is that <p>::first-line is actually a pseudo-element rather than a pseudo-class, and the content selected by it will actually be treated as a child element of the element. The processing is similar to
::before and
::after. Therefore, the color rule of the parent element is just a cascading relationship for it, through
: :first-line The rules defined by itself will have a higher priority!
This is why, in the MDN document, the double colon writing method is more recommended (of course, browsers support the single colon writing method) -- <p>MDN -- ::first-line <p>
One more question, an example of an MDN error? An interesting phenomenon
After finishing the above question. Let’s look at another question, a very similar question. <p>On the MDN page introducing <p>:not, there is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
You can choose anything that is not
<p> Element of tag. However, the actual results of the above CSS selector in the following HTML structure are not quite right.
1 2 3 4 |
|
CodePen Demo -- :not pesudo demo<p>https://codepen.io/ Chokcoco/pen/KKZbWjy<p>means that <p>:not(p)
can still select
<p> elements. Yes, the results are the same across multiple browsers.
When you see this, you can stop and think about it, why is the color of the <p><p> element still
color: blue?
Why is this? Answer: <p><p>这是由于 :not(p)
同样能够选中 <body>
,那么 <body>
的 color 即变成了 blue
,由于 color
是一个可继承属性,<p>
标签继承了 <body>
的 color 属性,导致看到的 <p>
也是蓝色。<p>我们把它改成一个不可继承的属性,试试看:1 2 3 4 |
|
<p>
没有边框体现,没有问题!
<p>因此,实际使用的时候,需要一定要注意样式继承的问题!
<p>(学习视频分享:css视频教程、web前端)The above is the detailed content of Check out these two CSS interview questions to test your foundation!. 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



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
