简体   繁体   English

如何同时拥有自己的style.css和bootstrap?

[英]How to have your own style.css and bootstrap at the same time?

So I just got into Bootstrap and I want to use Bootstrap and use my own CSS for stuff I want to re-touch myself. 所以我刚进入Bootstrap,我想使用Bootstrap并使用自己的CSS做我想重新修饰自己的东西。 Right now it's like this: 现在是这样的:

<link rel="stylesheet" href="css/bootstrap.css">

But when I override the stylesheet to be style.css (my css file) Bootstrap stops working. 但是,当我将样式表覆盖为style.css(我的CSS文件)时,Bootstrap停止工作。 How do I style with CSS and Bootstrap? 如何使用CSS和Bootstrap设置样式? (without using style in the html.) (不使用html中的样式。)

you should have something like this.. 你应该有这样的东西。

<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">

if you want to edit something from bootstrap, you can copy it's css and edit it... 如果您想从引导程序中进行编辑,则可以复制它并进行编辑...

for example, bootstrap.css has this lines... 例如, bootstrap.css有这行...

.navbar-default .navbar-nav>li>a {
    color: #777;
}

if you want to change that, you should put in your style.css something like this 如果要更改此设置,则应在style.css如下内容

.navbar-default .navbar-nav>li>a {
    color: #fff;
    font-weight: bold; /* plus additional codes if needed */
}

just be sure that style.css is after bootstrap.css in order of <link> tags. 只要确保style.cssbootstrap.css之后就按<link>标签的顺序。

There are two ways: 有两种方法:

  1. Create a new style sheet, and place if AFTER the bootstrap 创建一个新的样式表,并在引导放置

      <link href="css/bootstrap.css" rel="stylesheet"/> <link rel="stylesheet" href="css/style.css" rel="stylesheet"/> 


Reason you need to put it after bootstrap so that it can override the default styles that may have been defined already in bootstrap, by cascading them. 您需要将其放在引导程序之后的原因,以便它可以通过级联它们来覆盖可能已经在引导程序中定义的默认样式。

  1. Directly edit the bootstrap.css where ever you need to change the styling. 直接在需要更改样式的地方直接编辑bootstrap.css。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM