search
HomeWeb Front-endBootstrap TutorialCan bootstrap change the style?

Can bootstrap change the style?

Change the default style of bootstrap

I haven’t used bootstrap for a long time and have forgotten to modify the style according to my own needs. .

I added a new class as soon as I started, and rewritten the css style to overwrite the original style, but it actually didn't work. Because the priority of the selector is not considered. Some of these questions will be asked during interviews, but I have never been able to connect theory and practice.

My solution is to increase the weight through sub-selectors. Seeing that others also use IDs, I don’t like adding selectors with IDs.

Recall a wave of selectors and their priorities.

1. css selector

1. Tag selector (such as: body, div, p, ul, li)

2. Class Selector (such as: class)

3. ID selector (such as: id)

4. Global selector (such as: * number)

5. Combination selection Selector (such as: .head .head_logo, note that the two selectors are separated by the space bar)

6. Descendant selector (such as: #head .nav ul li Selector from parent set to descendant set)

7. Group selector div, span, img {color:Red} means that tags with the same style are displayed in groups

8. Inherit the selector (such as: div p, note that the two selectors use the space bar Separate)

9. Pseudo-class selector (for example: link style, pseudo-class of a element, 4 different states: link, visited, active, hover.)

10. Attribute selectors for string matching (^ $ * three types, corresponding to the beginning, end, and inclusion respectively)

11. Sub-selector (such as: div>p, with greater than sign>)

12.CSS adjacent sibling selector (such as: h1 p, with plus sign)

Related recommendations: "bootstrap Getting Started Tutorial"

2. Priority

When using the !important rule on a style declaration, the style declaration will override any other declaration in CSS. IE6 does not support this attribute.

The weight of the inline style sheet is up to 1000; that is, adding style to the element tag in HTML, that is, inline style. This method will make the css difficult to manage, so it is not recommended.

The ID selector has a weight of 100; defined by one or more id selectors. For example, the #id{margin:0;}id selector overrides the class selector .classname{margin:3pxl}.

Class The weight of the class selector is 10; it is defined by one or more class selectors, attribute selectors, and pseudo-class selectors. For example, .classname{margin:3px} will cover div{margin:6px;}.

The label selector weight is 1: defined by one or more type selectors. For example, div{marigin:6px;} covers *{margin:10px;}.

Wildcard selector: such as *{marigin:6px;}.

The browser customization or inheritance value is 0.1.

Summary sorting: !important > Inline style > ID selector > Class selector > Tag > Wildcard > Inheritance > Browser default properties

三,! important

Using !important is a bad habit and should be avoided as much as possible, because it breaks the inherent cascading rules in the style sheet and makes debugging and finding bugs more difficult. When two conflicting declarations with the !important rule are applied to the same element, the declaration with greater precedence will be used.

Query experience:

Never use !important on site-wide css.

Use !important only in specific pages that need to cover the entire site or external css (such as referenced ExtJs or YUI).

Never use !important in your plugins.

To optimize consider using style rule priority to solve the problem instead of !important.

The above is the detailed content of Can bootstrap change the style?. For more information, please follow other related articles on the PHP Chinese website!

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
Bootstrap vs. Other Frameworks: A Comparative OverviewBootstrap vs. Other Frameworks: A Comparative OverviewApr 18, 2025 am 12:06 AM

Bootstrap is better than TailwindCSS, Foundation, and Bulma because it is easy to use and quickly develop responsive websites. 1.Bootstrap provides a rich library of predefined styles and components. 2. Its CSS and JavaScript libraries support responsive design and interactive functions. 3. Suitable for rapid development, but custom styles may be more complicated.

Integrating Bootstrap Styles in React: Methods and TechniquesIntegrating Bootstrap Styles in React: Methods and TechniquesApr 17, 2025 am 12:04 AM

Integrating Bootstrap in React projects can be done in two ways: 1) introduced using CDN, suitable for small projects or rapid prototyping; 2) installation using npm package manager, suitable for scenarios that require deep customization. With these methods, you can quickly build beautiful and responsive user interfaces in React.

Bootstrap in React: Advantages and Best PracticesBootstrap in React: Advantages and Best PracticesApr 16, 2025 am 12:17 AM

Advantages of integrating Bootstrap into React projects include: 1) rapid development, 2) consistency and maintainability, and 3) responsive design. By directly introducing CSS files or using the React-Bootstrap library, you can use Bootstrap's components and styles efficiently in your React project.

Bootstrap: A Quick Guide to Web FrameworksBootstrap: A Quick Guide to Web FrameworksApr 15, 2025 am 12:10 AM

Bootstrap is a framework developed by Twitter to help quickly build responsive, mobile-first websites and applications. 1. Ease of use and rich component libraries make development faster. 2. The huge community provides support and solutions. 3. Introduce and use class names to control styles through CDN, such as creating responsive grids. 4. Customizable styles and extension components. 5. Advantages include rapid development and responsive design, while disadvantages are style consistency and learning curve.

Breaking Down Bootstrap: What It Is and Why It MattersBreaking Down Bootstrap: What It Is and Why It MattersApr 14, 2025 am 12:05 AM

Bootstrapisafree,open-sourceCSSframeworkthatsimplifiesresponsiveandmobile-firstwebsitedevelopment.Itofferspre-styledcomponentsandagridsystem,streamliningthecreationofaestheticallypleasingandfunctionalwebdesigns.

Bootstrap: Making Web Design EasierBootstrap: Making Web Design EasierApr 13, 2025 am 12:10 AM

What makes web design easier is Bootstrap? Its preset components, responsive design and rich community support. 1) Preset component libraries and styles allow developers to avoid writing complex CSS code; 2) Built-in grid system simplifies the creation of responsive layouts; 3) Community support provides rich resources and solutions.

Bootstrap's Impact: Accelerating Web DevelopmentBootstrap's Impact: Accelerating Web DevelopmentApr 12, 2025 am 12:05 AM

Bootstrap accelerates web development, and by providing predefined styles and components, developers can quickly build responsive websites. 1) It shortens development time, such as completing the basic layout within a few days in the project. 2) Through Sass variables and mixins, Bootstrap allows custom styles to meet specific needs. 3) Using the CDN version can optimize performance and improve loading speed.

Understanding Bootstrap: Core Concepts and FeaturesUnderstanding Bootstrap: Core Concepts and FeaturesApr 11, 2025 am 12:01 AM

Bootstrap is an open source front-end framework, and its main function is to help developers quickly build responsive websites. 1) It provides predefined CSS classes and JavaScript plug-ins to facilitate the implementation of complex UI effects. 2) The working principle of Bootstrap relies on its CSS and JavaScript components to realize responsive design through media queries. 3) Examples of usage include basic usage, such as creating buttons, and advanced usage, such as custom styles. 4) Common errors include misspelling of class names and incorrectly introducing files. It is recommended to use browser developer tools to debug. 5) Performance optimization can be achieved through custom build tools, best practices include predefined using semantic HTML and Bootstrap

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor