【问题标题】:Button text color is not changing to white in SCSS codeSCSS 代码中的按钮文本颜色不会变为白色
【发布时间】:2021-02-10 18:22:18
【问题描述】:

我在 codepen 链接上练习我的 CSS(SCSS):https://codepen.io/zubaer41/pen/XWKzomo?editors=1100 但我遇到了一个问题,无法解决。应该出现两个按钮,其中的文本应该是白色的。我可以更改按钮的背景颜色,但我无法将按钮文本颜色设为白色,即使我找不到任何发生这种情况的原因。请帮忙!!
//==== HTML & CSS(SCSS) 代码 ====


    <nav >
      <ul class="navigation">
        <li><a href="#">About us</a></li>
        <li><a href="#">Pricing</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
      <div class="button">
        <a class="btn-main" href="#">Sign up</a>
        <a class="btn-hot" href="#">Get a quote</a>
      </div>
    </nav>```
      
    
    =========================================================
    =================== CSS (SCSS) CODE =====================
    =========================================================
    
    ```* {
      margin: 0;
      padding: 0;
    }
    
    $color-primary: #f9ed69; //yellow color
    $color-secondary: #f08a5d; //orange color
    $color-tertiary: #b83b5e; //pink color
    $color-text-dark: #333;
    $color-text-light: #eee;
    
    $width-button: 150px;
    
    @mixin clearfix {
         &::after {
        content: "";
        clear: both;
        display: table;
      }
    }
    
    @mixin style-link-text($color) {
      text-decoration: none;
      text-transform: uppercase;
      color: $color;
    }
    
    @function divide($a, $b) {
      @return $a / $b;
    }
    
    nav {
      margin: divide(60, 2) * 1px;
      background-color: $color-primary;
      
      @include clearfix;
    }
    
    .navigation {
      list-style: none;
      float: left;
      
      li {
        display: inline-block;
        margin-left: 30px;
        margin-top: 10px;
        
        &:first-child {
        margin: 10px;
        }
        
        a {
          @include style-link-text($color-text-dark);
        }
      }
    }
    
    .button {
      float: right;
    }
    
    %btn-placeholder {
      padding: 10px;
      display: inline-block;
      text-align: center;
      border-radius: 100px;
      width: $width-button;
      @include style-link-text($color-text-light);
    }
    
    .btn-main {
      &:link {
        @extend %btn-placeholder;
        background-color: $color-secondary;
      }
      
      &:hover {
        background-color: darken($color-secondary, 10%);
      }
    }
    
    .btn-hot {
      &:link {
        @extend %btn-placeholder;
        background-color: $color-tertiary;
      }
      
      &:hover {
        background-color: lighten($color-tertiary, 10%);
      }
    }```

【问题讨论】:

    标签: html css web button sass


    【解决方案1】:

    我认为你必须添加

      &:focus {
        color:white;
      }

    在您的 .btn-mainbtn-hot 中。 这使按钮文本对我来说是白色的......

    【讨论】:

      【解决方案2】:
      .btn-main {
          &:link {
              @extend %btn-placeholder;
              background-color: $color-secondary;
              color : #fff;
          }
      }
      

      试试这个

      【讨论】:

        【解决方案3】:

        将 .button div 中的“a”作为目标,:link 仅在它是链接时才有效(设置了 href)

        .button {
          a { color:#eee; }
        }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-01-24
          • 2023-04-07
          • 1970-01-01
          • 2012-05-02
          • 2022-01-02
          相关资源
          最近更新 更多