简体   繁体   English

如何更改按钮内文本的字体样式/大小

[英]How to change the font style/size of text within a button

I am using bootstrap and CSS to style my website but I can't seem to figure out how to change the font style and weight of the text within my buttons.我正在使用 bootstrap 和 CSS 来设计我的网站样式,但我似乎无法弄清楚如何更改按钮中文本的字体样式和粗细。 Here is some of my code这是我的一些代码

<button type="button-apple" class="btn btn-light btn-lg download-button"><i class="fab fa-google-play"></i> Download</button>

I would like to change the font to be bolder so the words are easier to read because on my screen they come out as very thin lines.我想把字体改得更粗一些,这样文字就更容易阅读了,因为在我的屏幕上它们看起来很细。

Thanks in advance.提前致谢。

Whenever you try to work into libraries, please keep in mind that, you are overriding the style they already defined .每当您尝试使用库时,请记住,您正在覆盖它们已经定义的样式 In that case, just defining new styles such as color, font-weight etc. will not work.在那种情况下,仅仅定义新的 styles 例如颜色、字体粗细等是行不通的。 And also, please don't try to modify the class names they are already using .另外,请不要尝试修改他们已经在使用的 class 名称

You Can solve it in several ways您可以通过多种方式解决它

First Method is to add a new class from your own example: here -> .my-button-class and try to do the styling.第一种方法是从您自己的示例中添加一个新的 class:此处 -> .my-button-class并尝试进行样式设置。 Then use !important with that, it will override the style you want.然后使用!important ,它将覆盖您想要的样式。

For Example例如

Your HTML will be as follow:您的 HTML 将如下所示:

<button type="button-apple" class="btn btn-light btn-lg download-button my-button-class">
<i class="fab fa-google-play"></i> Download
</button>

CSS for the first method第一种方法CSS

.my-button-class{
    font-weight: bolder !important;
    font-size: 2rem !important;
    color: blue !important;
};

Second Method using specificity which is calling a class inside of a tag for example: button.my-button-class to style it instead of using !important , that's also a very good solution.第二种方法使用specificity性,例如在标签内调用 class : button.my-button-class来设置样式而不是使用!important ,这也是一个很好的解决方案。

CSS for the second method第二种方法CSS

button.my-button-class{
    font-weight: bolder;
    font-size: 2rem;
    color: blue;
};

Hope it will solve your problem.希望它能解决你的问题。 :) :)

Thanks谢谢

You can wrap your button text in an anchor and then use a span item:您可以将按钮文本包裹在锚点中,然后使用span项:

<a href="#" class="btn btn-light btn-lg download-button">
    <i class="fab fa-google-play"></i>
    <span style="font-weight:bolder;">Download</span>
</a>

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

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