【问题标题】:Targeting placeholder text using sass使用 sass 定位占位符文本
【发布时间】:2026-01-06 04:55:01
【问题描述】:

所以我为一个网站设计了一个平面注册表单来学习前端开发。我使用 Mailchimp 作为表单,这一切似乎都有效。现在我已经把所有的东西都设计好了,但是我不能让这个占位符文本具有正常的不透明度。对我来说,它的不透明度似乎低于“1”,或者它没有完全显示为“白色”。

我尝试了几件事,但没有任何效果; “不透明度 1”并尝试使用其他帖子中提到的供应商修复来选择占位符。我还尝试提出一个 mixin 来针对供应商修复(在之前的帖子中作为解决方案提到),但什么也没发生。

谢谢!

.newsletter-container {
  display: flex;
  height: 200px;
  background-color: #f4f4f4;
  align-items: center;
  justify-content: center;
}
.newsletter-container .newsletter-form {
  max-width: 700px;
  width: 100%;
}
.newsletter-container .newsletter-form .form-display {
  background: #f4f4f4;
  display: flex;
}
.newsletter-container .newsletter-form .form-display .mc-field-group {
  flex: 2;
}
.newsletter-container .newsletter-form .form-display input {
  background: #1d1c1c;
  border: 0;
  padding: 0;
  color: white;
  height: 50px;
  width: 100%;
  font-family: "Open Sans";
  font-size: 12px;
}
.newsletter-container .newsletter-form .form-display input[type="submit"] {
  flex: 1;
  border-left: 5px solid #f4f4f4;
  text-transform: uppercase;
}
.newsletter-container .newsletter-form .form-display input[type="text"] {
  padding-left: 10px;
}
<div class="newsletter-container">
  <div class="newsletter-form">
    <div id="mc_embed_signup">
      <form action="//facebook.us14.list-manage.com/subscribe/post?u=868cbba0c64a29c8fb08f6aef&amp;id=eda72469b9" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
        <div id="mc_embed_signup_scroll">
          
          <div class="form-display">
          
            <div class="mc-field-group">
              <label for="mce-FNAME"></label>
              <input type="text" value="" name="FNAME" class="" id="mce-FNAME" placeholder="Full Name">
            </div>
          
            <div class="mc-field-group">
              <label for="mce-EMAIL"></label>
              <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="Email Adress">
            </div>      
            
            <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
          </div>
          
          <div id="mce-responses" class="clear">
            <div class="response" id="mce-error-response" style="display:none"></div>
            <div class="response" id="mce-success-response" style="display:none"></div>
          </div>    
      
          <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
          <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_868cbba0c64a29c8fb08f6aef_eda72469b9" tabindex="-1" value=""></div>
        </div>
      </form>
    </div>
  </div>
</div>

【问题讨论】:

    标签: html css forms placeholder


    【解决方案1】:

    都是正确的,除了需要针对不同的浏览器专门更改输入占位符的颜色,试试:

    WebKit、Blink(Safari、Google Chrome、Opera 15+)和 Microsoft Edge 正在使用伪元素

    ::-webkit-input-placeholder {
        color: white;
    }
    

    Mozilla Firefox 4 到 18 正在使用伪类::-moz-placeholder

    Mozilla Firefox 19+ 正在使用伪元素:::-moz-placeholder(双冒号)

    Internet Explorer 10 和 11 使用伪类::-ms-input-placeholder

    浏览器 这并不奇怪!)

    //affects all input placeholders across webkit browsers
    ::-webkit-input-placeholder {
        color: white;
    }
    //affects all input placeholders across webkit browsers
    
    //no change in any of your other styles
    .newsletter-container {
      display: flex;
      height: 200px;
      background-color: #f4f4f4;
      align-items: center;
      justify-content: center;
    }
    //no change in any of your other styles
    

    希望这有帮助..

    更新:

    这对 OP 有帮助。

    同时检查::-webkit-input-placeholder 是否被normalize.scss 等任何其他文件覆盖。

    【讨论】:

    • 再次感谢 :),当我在 Codepen 中添加所有行时,它似乎可以工作。由于我使用 SASS 编写此页面,因此选择这些伪元素是不同的。现在对我来说变得很棘手,因为我显然无法正确定位它们。有什么想法吗?
    • 您可以将它们放在代码中的任何位置。伪元素选择器并不意味着它必须始终附加到元素。如果您只是编写上面的代码,它应该适用于跨 webkit 浏览器的所有输入。无需在其中添加或附加任何内容。您能否也提供指向您的 Codepen 的链接,以便我进行演示
    • 是的,当我将它添加到 Codepen 时会有所帮助,但是当我将它添加到代码编辑器 Atom 中的 SASS 文件中时,它不会显示白色。其他所有更改都有效,但不是这个。我已经完全按照你说的做了,但是当我在 Atom 上运行它时它似乎不起作用。
    • 有效!我的 normalize.scss 文件为占位符定义了颜色和不透明度,因此它没有覆盖。再次感谢您的帮助:)。
    • 不用担心,您也可以接受答案以帮助他人。干杯