【问题标题】:Linear gradient is not working with <a> element [duplicate]线性渐变不适用于 <a> 元素 [重复]
【发布时间】:2019-02-25 22:12:45
【问题描述】:

我正在尝试将 CSS 渐变应用到我的 &lt;a&gt; 元素。它显然不起作用,我一直在尝试解决它但没有成功。如果它必须解决这个问题,我正在使用 Chrome。

body {
  margin: 1cm;
}

a {
  padding: 15px 60px 15px 60px;
  text-decoration: none;
  border: 1px solid black;
}

#1button {
  background: rgb(2, 0, 36);
  background: linear-gradient(65deg, rgba(2, 0, 36, 1) 0%, rgba(12, 12, 125, 1) 35%, rgba(0, 212, 255, 1) 100%);
}

#2button {
  background: rgb(2, 0, 36);
  background: linear-gradient(65deg, rgba(2, 0, 36, 1) 0%, rgba(232, 51, 55, 1) 35%, rgba(241, 95, 223, 1) 100%);
}
<a id="1button">Button #1</a>
<a id="2button">Button #2</a>

【问题讨论】:

  • ID 不能以数字开头,即使在 HTML5 中也可以使用

标签: html css


【解决方案1】:

不要使用数字作为您的 id 的第一个字符:

body {
  margin: 1cm;
}

a {
  padding: 15px 60px 15px 60px;
  text-decoration: none;
  border: 1px solid black;
}

#button1 {
  background: linear-gradient(65deg, rgba(2, 0, 36, 1) 0%, rgba(12, 12, 125, 1) 35%, rgba(0, 212, 255, 1) 100%);
}

#button2 {
  background: linear-gradient(65deg, rgba(2, 0, 36, 1) 0%, rgba(232, 51, 55, 1) 35%, rgba(241, 95, 223, 1) 100%);
}
<a id="button1">Button #1</a>
<a id="button2">Button #2</a>

【讨论】:

  • 我要补充一点,第一个背景属性是无用的,因为它被覆盖了......可能最好在背景定义之后添加background-color(或者删除它,因为渐变是用纯色制作的)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 2017-09-02
相关资源
最近更新 更多