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!

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 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.

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 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.

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

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 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.

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


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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
The most popular open source editor