【问题标题】:Input tag runs unexpected CSS effect输入标签运行意外的 CSS 效果
【发布时间】:2020-09-17 21:26:23
【问题描述】:

我正在尝试设置我的 Drupal 主题按钮的样式,但是当我将相同的 CSS 放入“输入”标签时出现了问题。

在这个 sn-p 示例中,我们可以使用相同的 CSS 代码验证 2 种不同的效果。

我认为这是一个 Drupal 问题,但事实并非如此。当我把代码拿到外面并用输入标签尝试它时,它的显示方式与 Drupal 站点中的相同。

/* Buttons */
.form-submit {
  cursor: pointer;
  margin-left: 5px;
  margin-bottom: 15px;
  text-shadow: 0 -2px 0 #4a8a65, 0 1px 1px #c2dece;
  box-sizing: border-box;
  font-size: 2em;
  font-family: Helvetica, Arial, Sans-Serif;
  text-decoration: none;
  font-weight: bold;
  color: #5ea97d;
  height: 65px;
  line-height: 65px;
  padding: 0 32.5px;
  display: inline-block;
  width: auto;
  background: -webkit-gradient(linear, left top, left bottom, from(#9ceabd), color-stop(26%, #9ddab6), to(#7fbb98));
  background: linear-gradient(to bottom, #9ceabd 0%, #9ddab6 26%, #7fbb98 100%);
  border-radius: 5px;
  border-top: 1px solid #c8e2d3;
  border-bottom: 1px solid #c2dece;
  top: 0;
  -webkit-transition: all 0.06s ease-out;
  transition: all 0.06s ease-out;
  position: relative;
}
.form-submit:visited {
  color: #5ea97d;
}

.form-submit:hover {
  background: -webkit-gradient(linear, left top, left bottom, from(#baf1d1), color-stop(26%, #b7e4ca), to(#96c7ab));
  background: linear-gradient(to bottom, #baf1d1 0%, #b7e4ca 26%, #96c7ab 100%);
}

.form-submit:active {
  top: 6px;
  text-shadow: 0 -2px 0 #7fbb98, 0 1px 1px #c2dece, 0 0 4px white;
  color: white;
}
.form-submit:active:before {
  top: 0;
  box-shadow: 0 3px 3px rgba(0, 0, 0, 0.7), 0 3px 9px rgba(0, 0, 0, 0.2);
}

.form-submit:before {
  display: inline-block;
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  z-index: -1;
  top: 6px;
  border-radius: 5px;
  height: 65px;
  background: linear-gradient(to top, #1e5033 0%, #378357 6px);
  -webkit-transition: all 0.078s ease-out;
  transition: all 0.078s ease-out;
  box-shadow: 0 1px 0 2px rgba(0, 0, 0, 0.3), 0 5px 2.4px rgba(0, 0, 0, 0.5), 0 10.8px 9px rgba(0, 0, 0, 0.2);
}
<input type="submit" id="edit-submit" name="op" value="Comprar" class="form-submit">
<a class="form-submit" href="#0">Comprar</a>

【问题讨论】:

    标签: css input tags effect


    【解决方案1】:

    伪元素::before::after 不适用于某些元素,例如输入。渲染的差异来自那里。问题已经提出,我邀请您阅读此答案以获取更多详细信息。:https://stackoverflow.com/a/4660434

    【讨论】:

    • 我不知道。我看到了链接,似乎有很多解决方法,但是当我使用 Drupal 时,我不能改变它的代码,但它的风格。按钮的 Drupal 样式只有 .form-submit 和 .form-submit:hover。我想知道我是否可以做一些工作。
    • 我对 Drupal 不熟悉,但据我所知,有一些像 WordPress 这样的钩子可能会有所帮助。您应该寻找如何用 Drupal 上的按钮替换输入元素。这是一个示例,但我不知道这是否是最好的方法:drupal.stackexchange.com/a/226494
    • 您好,感谢您提供更多信息。我看了一下,但我使用 Drupal 7 而不是 8。
    • 我搜索了关键字“用 Drupal 上的按钮替换输入元素”,还找到了drupal.org/forum/support/module-development-and-code-questions/… 问题是我需要更改所有表单提交,我需要一些更实用的解决方案的工作量很大。
    【解决方案2】:

    嗯,嗯...我不是 CSS 专家,实际上我是自学成才的,但我可以改进下面这个片段的问题的解决方案。 如果我们不能以特定的方式做某事,我们就必须跳出框框思考并找到一种方法让它发挥作用。如果不相等但与预期的相似。 谁能帮我把它做得比这更好?

    /* Buttons */
    .form-submit {
      /* :before */
    
      top: 6px;
      border-radius: 5px;
      height: 65px;
      background: linear-gradient(to top, #1e5033 0%, #378357 6px);
      /* -webkit-transition: all 0.078s ease-out; 
      transition: all 0.078s ease-out; */ 
      box-shadow: 0 1px 0 2px #9ddab6, 0 5px 2.4px #7fbb98, 0 8px 9px rgba(0, 0, 0, 0.2);
      
      cursor: pointer;
      margin-left: 5px;
      margin-bottom: 15px;
      text-shadow: 0 -2px 0 #4a8a65, 0 1px 1px #c2dece;
      box-sizing: border-box;
      font-size: 2em;
      font-family: Helvetica, Arial, Sans-Serif;
      text-decoration: none;
      font-weight: bold;
      color: #5ea97d;
      height: 65px;
      line-height: 65px;
      padding: 0 32.5px;
      display: inline-block;
      width: auto;
      background: -webkit-gradient(linear, left top, left bottom, from(#9ceabd), color-stop(26%, #9ddab6), to(#7fbb98));
      background: linear-gradient(to bottom, #9ceabd 0%, #9ddab6 26%, #7fbb98 100%);
      /* border-radius: 5px; */
      border-top: 1px solid #c8e2d3;
      border-bottom: 1px solid #c2dece;
      top: 0;
      -webkit-transition: all 0.06s ease-out;
      transition: all 0.06s ease-out;
      position: relative;
    }
    
    
    .form-submit:visited {
      color: #5ea97d;
    }
    
    .form-submit:hover {
      background: -webkit-gradient(linear, left top, left bottom, from(#baf1d1), color-stop(26%, #b7e4ca), to(#96c7ab));
      background: linear-gradient(to bottom, #baf1d1 0%, #b7e4ca 26%, #96c7ab 100%);
    }
    
    .form-submit:active {
      top: 6px;
      text-shadow: 0 -2px 0 #7fbb98, 0 1px 1px #c2dece, 0 0 4px white;
      color: white;
      box-shadow: 0 0px 0 2px rgba(0, 0, 0, 0.3), 0 0px 2.4px rgba(0, 0, 0, 0.5), 0 0px 9px rgba(0, 0, 0, 0.2);
    }
    <input type="submit" id="edit-submit" name="op" value="Comprar" class="form-submit">
    <a class="form-submit" href="#0">Comprar</a>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      • 2022-07-26
      相关资源
      最近更新 更多