简体   繁体   English

为什么font-weight属性(CSS)在某些元素中不起作用?

[英]Why is font-weight property (CSS) not working in some elements?

I have somes spans in my HTML code in which I used the font-weight property of CSS. 我的HTML代码中有一些跨度,我在其中使用了CSS的font-weight属性。 The spans are grouped by a class. 跨度按类分组。 In some of the spans the property works, but in others it does not works, and I do not know why it is happening. 在某些范围内,该物业可以运作,但在其他地方,它不起作用,我不知道它为什么会发生。 Below there are some excerpts of my code. 下面是我的代码的一些摘录。

CSS code: CSS代码:

    .redasterix{
    color: rgb(240, 83, 50);
    font-size: 18px;
    font-weight: 700;
}

HTML code: HTML代码:

<h3>Informação pessoal</h3>
            <ul>
                <form>
                <li>Nome<span class="redasterix">*</span> <input type="text" name="nome" required></li>
                <li>Sobrenome<span class="redasterix">*</span> <input type="text" name="sobrenome" required></li>
                <li>Título<span class="redasterix">*</span> <input type="text" name="titulo" required></li>
                <li>Empresa<span class="redasterix">*</span> <input type="text" name="empresa" required></li>
                <li>Endereço 1 <input type="text" name="endereço1"></li>
                <li>Endereço 2 <input type="text" name="endereço2"></li>
                <li>Cidade<span class="redasterix">*</span> <input type="text" name="cidade" required></li>
                <li>
                    Estado<span class="redasterix">*</span> <select required>
                        <option value="selecionar"></option>
                        <option value="acre">Acre</option>
                        <option value="alagoas">Alagoas</option>
                        <option value="amapá">Amapá</option>
                        <option value="amazonas">Amazonas</option>
                        <option value="bahia">Bahia</option>
                        <option value="ceará">Ceará</option>
                        <option value="distritofederal">Distrito Federal</option>
                        <option value="espiritosanto">Espírito Santo</option>
                        <option value="goias">Goiás</option>
                        <option value="maranhao">Maranhão</option>
                        <option value="matogrosso">Mato Grosso</option>
                        <option value="matogrossodosul">Mato Grosso do Sul</option>
                        <option value="minasgerais">Minas Gerais</option>
                        <option value="para">Pará</option>
                        <option value="paraiba">Paraíba</option>
                        <option value="parana">Paraná</option>
                        <option value="pernambuco">Pernambuco</option>
                        <option value="piaui">Piauí</option>
                        <option value="riodejaneiro">Rio de Janeiro</option>
                        <option value="riograndedonorte">Rio Grande do Norte</option>
                        <option value="riograndedosul">Rio Grande do Sul</option>
                        <option value="rondonia">Rondônia</option>
                        <option value="roraima">Roraima</option>
                        <option value="santacatarina">Santa Catarina</option>
                        <option value="saopaulo">São Paulo</option>
                        <option value="sergipe">Sergipe</option>
                        <option value="tocantins">Tocantins</option>
                    </select>
                </li>
                <li>CEP<span class="redasterix">*</span> <input type="text" required></li>
                <li>País/Região<span class="redasterix">*</span> Brasil</li>
                <li>Email<span class="redasterix">*</span> <input type="email" required></li>
                <li>Telefone<span class="redasterix">*</span> <input type="tel" required></li>
            </form>

From the snippet you've provided, I'd guess that your problems comes from CSS's cascade as it seems to be rendering properly in jsbin . 从你提供的代码片段中,我猜你的问题来自CSS的级联,因为它似乎在jsbin中正确呈现 I would suggest verifying your CSS and making sure that there isn't a rule that overwrites your .redasterisk . 我建议验证你的CSS,并确保没有一个规则覆盖你的.redasterisk Check in your dev tools if your element isn't being overwritten by some other CSS. 如果您的元素没有被其他CSS覆盖,请检查您的开发工具。 Here's a CSS Tricks article I found that goes in detail into how the cascade works 这是我发现的一篇CSS Tricks文章,详细介绍了级联的工作原理

In your css file, try applying the !Important rule and see if that fixes the problem. 在您的css文件中,尝试应用!重要规则,看看是否能解决问题。 This rule will override your style sheet's default cascading properties and give the font-weight a higher priority. 此规则将覆盖样式表的默认级联属性,并为font-weight提供更高的优先级。

Here's how you can do that with the code that you provided: 以下是使用您提供的代码执行此操作的方法:

.redasterix{
   color: rgb(240, 83, 50);
   font-size: 18px;
   font-weight: 700 !important;
}

If this works, then you will need to take a look at your stylesheet to figure out what is overriding the font-weight. 如果这样可行,那么您需要查看样式表以找出覆盖字体粗细的内容。 It's against most conventions to use the !Important rule because it can cause other things to break and it makes debugging your code a nightmare, but you can use it in cases like this to see if you have an issue with your stylesheet's cascade. 使用!重要规则是违反大多数约定的,因为它可能导致其他事情中断,并且它使调试代码成为一场噩梦,但是你可以在这样的情况下使用它来查看样式表的级联是否存在问题。 Just be sure to remove it after you fix the problem. 解决问题后,请务必将其删除。

对于修复,您可以在font-weight值之后添加关键字!important以覆盖所有其他css font-weight。

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

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