无法用外部css覆盖引导程序



我最近开始了一个编码训练营,我们正在学习bootstrap。我的很多朋友出于其他原因更喜欢远离bootstrap,但我们在课堂上学习,所以别无选择。不管怎样,我已经尝试了很多东西。我试着在我试图设计样式的元素中添加一个新的类,我试着像div > p .lead一样具体,还有很多其他想法,都是!important文本。我开始想,也许我的外部样式表链接不正确。我已经四次检查了文件位置,并尝试更改内容,看看这是否有帮助,但仍然没有成功。我也试着向我的一些朋友寻求帮助,但他们中的大多数人已经在工作了,目前无法帮助我,所以我来到了这里!

我的HTML和CSS代码。我知道CSS非常简单,这只是为了测试目的,试图找出如何覆盖html。我非常感谢你抽出时间来看这个。

顺便说一句,我的很多同学都取笑我如何将代码间隔开。如果你们认为这是个问题,就大声说出来!我想知道,这样我就不会拘泥于一种做事方式,在肌肉记忆开始变得难以改变之前,我有时间调整它!谢谢

.jumbotron h1
{
background-image: url(/img/pizza.png) !important;
}
title
{
font-family: cursive !important;
}
<!DOCTYPE html>
<html 
lang="en"
>
<head>
<link 
rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" 
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" 
crossorigin="anonymous"
>
<link 
rel="stylesheet"
type="text/css"
href="/css/custom.css"
>
<meta 
charset="UTF-8"
>
<meta 
name="viewport" 
content="width=, initial-scale=1.0"
>
<meta 
http-equiv="X-UA-Compatible" 
content="ie=edge"
>
<title>
Pizza World
</title>
</head>
<body>
<nav 
class="navbar navbar-expand-lg navbar-light bg-light"
>
<a 
class="navbar-brand" 
href="#"
>
Pizza World
</a>
<button 
class="navbar-toggler" 
type="button" 
data-toggle="collapse" 
data-target="#navbarSupportedContent" 
aria-controls="navbarSupportedContent" 
aria-expanded="false" 
aria-label="Toggle navigation"
>
<span 
class="navbar-toggler-icon"
>
</span>
</button>
<div 
class="collapse navbar-collapse" 
id="navbarSupportedContent"
>
<ul 
class="navbar-nav mr-auto"
>
<li 
class="nav-item active"
>
<a 
class="nav-link" 
href="#"
>
Order Online 
<span 
class="sr-only"
>
(current)
</span>
</a>
</li>
<li 
class="nav-item"
>
<a 
class="nav-link" 
href="#"
>
Menu
</a>
</li>
<form 
class="form-inline my-2 my-lg-0"
>
<input 
class="form-control mr-sm-2" 
type="search" 
placeholder="Zip Code" 
aria-label="Zip Code"
>
<button 
class="btn btn-outline-success my-2 my-sm-0" 
type="submit"
>
Search stores near you!
</button>
</form>
</div>
</nav>
<div 
class="jumbotron"
>
<h1 
class="display-12 myh1class"
>
Hello, world!
</h1>
<p 
class="lead"
>
This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.
</p>
<hr 
class="my-4"
>
<p>
It uses utility classes for typography and spacing to space content out within the larger container.
</p>
<p 
class="lead"
>
<a 
class="btn btn-primary btn-lg" 
href="#" 
role="button"
>
Learn more
</a>
</p>
</div>
<script             
src="https://code.jquery.com/jquery-3.2.1.slim.min.js" i
ntegrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
crossorigin="anonymous"
>
</script>
<script 
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" 
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" 
crossorigin="anonymous"
>
</script>
<script 
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
crossorigin="anonymous"
>
</script>

</body>
</html>

可以通过多种方式覆盖Bootstrap CSS。

  1. 您可以使用!重要的是,正如你在这里所做的,尽管这并不是最好的方法,因为它可能会在以后导致意外行为

  2. 您可以下载Bootstrap JS和CSS文件,并根据需要进行修改(而不是在标题中使用CDN链接(,并将其包含在项目文件中。

  3. 您可以在HTML中使用CSS选择器,例如id="bootstrap override"。Bootstrap主要使用的类的权重是ID的1/10。下面是一篇很好的文章,解释了CSS的特殊性

CSS位于外部链接,第一次读取它时,最简单的方法是将Bootstrap CSS上传到您的工作文件中,并用html链接它,然后根据需要进行编辑。很容易。

最新更新