JIYIK CN >

Current Location:Home > Learning > WEB FRONT-END > CSS >

Overriding Bootstrap CSS

Author:JIYIK Last Updated:2025/04/19 Views:

This article introduces the famous CSS UI framework Bootstrap. We will discuss the process of overriding Bootstrap CSS with custom styles.


Bootstrap Overview

Using Bootstrap CSS makes it quicker and easier to create responsive websites than using pure CSS alone.

That’s because this open source toolkit provides pre-designed templates and components that enable you to quickly and easily create layouts using key design components like Bootstrap buttons, forms, and tables.

But the process isn’t as simple as copying and pasting this reusable code. First, you should customize the Bootstrap templates and components to confirm that the site accurately represents your unique brand.

For example, you might prefer a custom color instead of one of Bootstrap's ten color utility classes. Or, you might want to modify the breakpoints of a grid layout in Bootstrap.

You may also want to include custom classes, such as a .btn-cstm class for a unique button. While not advisable, you can edit the Bootstrap core files directly to make adjustments for your site.


Modify Bootstrap CSS

Modifying the Bootstrap default stylesheet directly becomes challenging. This makes it harder to recall your changes and makes it harder to update to improved versions of Bootstrap.

Since core files must be replaced when upgrading, all customizations will be lost. However, it is possible to make changes without modifying the Bootstrap source code.

Let's look at the process in more detail.


Overriding Bootstrap styles

If your site requires custom styles beyond those of Bootstrap, add another external stylesheet. It will apply these overridden styles to your class and id selectors based on how you load both stylesheets:

  1. Comes with Bootstrap.
  2. With custom stylesheet.

For example, in Bootstrap there is a class for buttons, namely btn-primary. For this class, the font size set by Bootstrap CSS is 16px. If we need to change the font size to 21px, we can override this class in a custom stylesheet.

The first step is to make a custom stylesheet, e.g. customStyles.cssthe stylesheet will look like this:

.btn-primary{
    font-size:21px;
}

After including the Bootstrap CSS, you can include this sheet in your HTML page like this:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="customStyling.css">
    </head>
    <body>
        <h1>Custom Bootstrap demo</h1>
        <button class="btn-primary">Demo</button>
    </body>
</html>

As you can see from the output, all properties except font-size are inherited from the default Bootstrap CSS, and only the font-size property is updated to the new value.

This is one of the easiest ways to override the Bootstrap CSS and add custom styles to your website.

Previous:Rotating text using CSS

Next: None

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Rotating text using CSS

Publish Date:2025/04/19 Views:152 Category:CSS

In this article, we will use CSS to rotate HTML text. Rotated text is commonly used in many languages, such as Chinese, Japanese, or Korean. Moreover, when designing a web page, developers may need to rotate the text to a certain degree to

Hide bullet points using CSS

Publish Date:2025/04/19 Views:163 Category:CSS

In this article, we will learn to hide the bullet points of a list in HTML. Developers can use HTML lists to display related items point by point. We can ol create ordered lists using the HTML tag and ul unordered lists using the HTML ul ta

覆盖 Bootstrap CSS

Publish Date:2023/04/28 Views:136 Category:CSS

本文介绍的是著名的 CSS UI 框架 Bootstrap。 我们将讨论使用自定义样式覆盖 Bootstrap CSS 的过程。

使用 CSS 制作带圆角的 HTML 表格

Publish Date:2023/04/28 Views:247 Category:CSS

这个简短的文章是关于在 HTML 页面上制作圆角表格的 CSS 样式。使用 CSS 制作带圆角的 HTML 表格 使图像、表格或 div 段的角变圆的属性是 border-radius。

CSS 设置轮廓 outline 的半径

Publish Date:2023/04/28 Views:141 Category:CSS

在本文中,用户将学习如何为 outline 属性设置圆角,与 border-radius 属性相同。 在这里,我们已经解释了将圆角应用于轮廓属性的不同方法。

使用 CSS 居中视频

Publish Date:2023/04/28 Views:272 Category:CSS

在本文中,用户将学习仅使用 CSS 将 <video> 元素居中。 我们已经在下面解释了使用 CSS 使视频居中的多种方法。

使用 CSS 居中内联块

Publish Date:2023/04/28 Views:123 Category:CSS

在本文中,我们将创建多个 HTML 元素并将其显示设置为 inline-block。 之后,我们将学习使用 display: inline-block 将所有元素居中。

使用 CSS 添加透明边框

Publish Date:2023/04/28 Views:537 Category:CSS

在本文中,我们将讨论在 HTML 中的图像、按钮或任何其他对象周围创建透明边框。 透明边框是图像或对象周围的边框,可改善用户体验。

使用 CSS 向上移动文本

Publish Date:2023/04/28 Views:715 Category:CSS

有时,在开发网页时,我们将文本放在底部或页脚中,因此我们可能需要在文本下方留一个空格并将文本上移。 我们将学习如何使用 css 从网页底部向上移动文本。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial