【问题标题】:Css property not reflected for bootstrap specific button tag引导特定按钮标签未反映 CSS 属性
【发布时间】:2018-04-09 16:36:14
【问题描述】:
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/
   3.3.7/css/bootstrap.min.css">
    <script 
    src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
   </script>
    <script 
  src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> 
  </script>
  </head>
  <body>

<div class="container">
  <h2>Button Group</h2>
  <p>The .btn-group class creates a button group:</p>
  <div class="btn-group">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
</div>
<style type="text/css">
button{
background-color:red;
}
</style>
</body>
</html>

在上面的部分中,使用了 Bootstrap,当尝试为按钮标签应用 background-color 属性时,它没有被反映。这是什么原因?

【问题讨论】:

    标签: html css twitter-bootstrap button


    【解决方案1】:

    尝试添加 !important:

    <style type="text/css">
    button{
    background-color: red !important;
    }
    </style>
    

    或者把你的

    【讨论】:

    • 工作得很好。“!重要意味着什么?
    • 请避免在代码中使用
    • 你可以在 CSS 的任何地方添加这个...意思是“忽略其他来源的 CSS 代码,这个代码更重要”
    • 不使用 !important 一个好的建议是创建新类 - 您可以复制当前类的引导样式 - 并在标签中使用它而不是 boostraps'
    【解决方案2】:

    你可以使用!important因为bootstrap已经写好了样式e。所以如果你想覆盖那个样式,也许你需要在bootstrap的样式下写下来,否则你需要添加!important

    我想这个网站会帮助你理解!important的原因。 https://css-tricks.com/when-using-important-is-the-right-choice/

    【讨论】:

      猜你喜欢
      • 2016-01-04
      • 2015-06-24
      • 2014-12-30
      • 2012-04-26
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多