html - 谷歌MDL文本字段焦点改变颜色

标签 html css material-design material-design-lite

我刚刚开始使用谷歌 Material 设计精简版。当你专注于这个标签时,我发现这个文本字段 float 。颜色是蓝色或海军蓝或我不知道。

问题是,我将链接颜色更改为靛蓝粉色

<link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.indigo-pink.min.css">

但是当我聚焦时,我的文本字段没有变为靛蓝色或粉红色。

问题很简单,怎么改?

我对此做了一些事情,但仍然没有运气。

HTML:

<form action="#">
  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
    <input class="mdl-textfield__input" type="text" id="sample4">
    <label class="mdl-textfield__label" for="sample3">Text...</label>
  </div>
  <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
    <input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="sample4">
    <label class="mdl-textfield__label mdl-color-modifier" for="sample4">Number...</label>
    <span class="mdl-textfield__error">Input is not a number!</span>
  </div>
</form>

CSS:

div .mdl-textfield__label:after {
  background: pink;
}
.mdl-textfield--floating-label .is-focused .mdl-textfield__label, .mdl-textfield--floating-label.is-dirty .mdl-textfield__label, .mdl-textfield--floating-label.has-placeholder .mdl-textfield__label{
    color:pink;
}

.mdl-color-modifier:focus{
    color:pink;
}

我尝试使用伪 :focus 在其中应用一个新类,但它仍然没有运气。

最佳答案

我都有了。键是 :after 修饰符和 is-focused 类。只需将 #FAFAFA 替换为您的 indigo-pink 即可,它应该适合您。这只是概念证明。检查 fiddle 。它的文本标签也有颜色。

.mdl-textfield.is-focused .mdl-textfield__label {
    color: #FAFAFA;
}

.mdl-textfield__label:after{
    background-color: #FAFAFA;
}

https://jsfiddle.net/90u6Lxc4/30/

关于html - 谷歌MDL文本字段焦点改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40992507/

相关文章:

jQuery mobile - Javascript、参数传递、CSS 文件组织

html - 是否可以在多个表格行上设置一个线性渐变背景?

html - 如何在不更改 bootstrap.css 文件的情况下管理 Bootstrap 列的宽度?

angular - 使用 Angular Material 实现 Notched Outline 主题时遇到问题

javascript - 如何在 ngMaterial md-autocomplete 中过滤查询?

html - 如何在一行div中排列2个div

javascript - .animate() slider 无法正常工作

javascript - 将变量添加到动画CSS

html - 悬停具有 border 属性的元素会移动

android - 我如何为我的 Gridview 实现触摸波纹?