html - 我无法从 css 访问 body

标签 html css

我在 Codepen 上建立了这个致敬页面。我添加了 Bootsrap。然后我无法从 css 访问 body。你可以在这里查看我的代码。

body {
  background-color: black;
}

.header {
  font-size: 100px;
  font-family: "Libre Barcode 39 Text";
  text-align: center;
}

.mainPicture {
  width: 95px;
}
<link href="https://fonts.googleapis.com/css?family=Libre+Barcode+39+Text" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">

<div class="container-fluid">
  <h1 class="header">Travis<span><img class="mainPicture" src="https://ih0.redbubble.net/image.398989678.9673/ap,550x550,12x12,1,transparent,t.u1.png"></span>Scott</h1>

最佳答案

Bootstrap 风格覆盖了您的风格。使用 !important 覆盖 Bootstrap 样式。有关详细信息,请检查这些用法

html>body {
  background-color: black;
}

.header {
  font-size: 100px;
  font-family: "Libre Barcode 39 Text";
  text-align: center;
}

.mainPicture {
  width: 95px;
}
<link href="https://fonts.googleapis.com/css?family=Libre+Barcode+39+Text" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">

<div class="container-fluid">
  <h1 class="header">Travis<span><img class="mainPicture" src="https://ih0.redbubble.net/image.398989678.9673/ap,550x550,12x12,1,transparent,t.u1.png"></span>Scott</h1>

替代解决方案:-

使用 html > body 来增加特异性,这是一个很好的做法

html > body {
  background-color: black;
}

.header {
  font-size: 100px;
  font-family: "Libre Barcode 39 Text";
  text-align: center;
}

.mainPicture {
  width: 95px;
}
<link href="https://fonts.googleapis.com/css?family=Libre+Barcode+39+Text" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">

<div class="container-fluid">
  <h1 class="header">Travis<span><img class="mainPicture" src="https://ih0.redbubble.net/image.398989678.9673/ap,550x550,12x12,1,transparent,t.u1.png"></span>Scott</h1>

关于html - 我无法从 css 访问 body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46377209/

相关文章:

java - HTML表单参数全部为空

javascript - 如何根据下拉列表中的选择向表中添加行并使用列表中的选定数字填充单元格

java - 我应该使用什么查询来使用 Jsoup 从 html 页面中提取符号?

javascript - 如何使用 HTML 表单简单地将 javascript 数据发布到 PHP

html - 使用列表项的 CSS3 弹出导航

javascript - 如何将具有特定类的div的内容添加到其他页面?

php - 为什么我不能在 WordPress functions.php 中加入多个 Google 字体?

php - 显示外部网站的某些部分并修改 HTML/CSS

jQuery并保存页面之间的参数

css - 固定宽度元素左侧的动态全宽容器内的全宽输入