Home > front end >  Overriding Bootstrap classes in CodePen site
Overriding Bootstrap classes in CodePen site

Time:10-25

I have free account on CodePen. In my code I use Bootstrap but I also override some Bootstrap classes in the CodePen CSS editor. In the head tag of HTML editor, I defined the loading order:

link rel="stylesheet" type="text/css" href="bootstrap.min.css" <br>
link rel="stylesheet" type="text/css" href="custom.css"

I.e. my custom.css I must override the Bootstrap classes. But it does not work in the CodePen editor. I have to use the !important rule to override Bootstrap classes too many.

The main thing is my code works perfectly in Google Chrome and Firefox without using the !important rule when I open custom.html on my local computer.

Why does not it work in the CodePen editor and why does it make such a big difference?

CodePudding user response:

It seems that the order is :

  1. !important
  2. inline style
  3. <style> in the html part
  4. style in the css part
  5. style in css settings.

If you want to avoid adding !important, you should add your link in the settings.

Go to the Settings -> css-> ->Add External Stylesheets/Pens -> add you css link -> save & close.

(Codepen link)

  • Related