简体   繁体   English

当我添加 Boostrap 5 时字体大小缩小

[英]Font size shrinks when I add Boostrap 5

The font size changes when I add the Boostrap CDN link.当我添加 Boostrap CDN 链接时,字体大小会发生变化。

I found that this is because Boostrap has a default font size.我发现这是因为 Boostrap 有一个默认的字体大小。 I tried to change the font size by specifying the font size in the external style sheet and putting !import , but it doesn't work.我试图通过在外部样式表中指定字体大小并放置!import来更改字体大小,但它不起作用。 And it only works when I put font size in the inline style sheet.而且只有当我在内联样式表中输入字体大小时它才有效。

 div.banner { font-size: 500%;important; }
 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js"></script> <main> <div class="banner"> <h1 class="slideUp" style="font-family: 'EB Garamond', serif"> Yasuní National Park<br /> <span style="font-size: 40%">&nbsp; between oil exploitation and conservation</span> </h1> </div> </main>

This is the part of my code and I was trying to change the font size of <h1> tag by applying the code below.这是我的代码的一部分,我试图通过应用下面的代码来更改<h1>标签的字体大小。 But it doesn't work.但它不起作用。 Can you explain why?你能解释为什么吗?

div.banner {
    font-size: 500% !important;
}

Firstly, we change the size of font sizes using em, rem, and px.首先,我们使用 em、rem 和 px 更改字体大小。

Given CSS:给定 CSS:

Let us say you have you font size declared for your entire document like this假设您为整个文档声明了字体大小,如下所示

* {
  font-size: 20px;
}

that is in pixel.以像素为单位。

If we want to change this part of your code.如果我们想更改您的这部分代码。

<span style="font-size: 40%;">&nbsp; between oil exploitation and conservation</span></h1>

We use rem mostly.我们主要使用 rem。 like:喜欢:

<span style="font-size: 2rem;">&nbsp; between oil exploitation and conservation</span></h1>



//2rem means -> default 20px(declared) * 2 = 40px will be the font-size of 2rem, 3 rem is 60, etc.

I see you tagged specificity too..我看到你也标记了specificity ..

Not a good practice to use important even in testing.即使在测试中也不是使用important的好习惯。

Highest priority is inline styling -> then IDs -> classes.最高优先级是inline styling -> then IDs -> classes.

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

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