html - 将鼠标悬停在文本上时难以更改文本颜色

标签 html css

我试图将鼠标悬停在文本上时将其颜色更改为白色,但我无法这样做。

这是我试过的代码。如何确保将鼠标悬停在文本上时文本颜色变为白色,并且将鼠标悬停在文本上时文本大小也会发生变化?

这是我试过的代码

h1::before,
h1::after {
  content: "";
  width: 0%;
  position: absolute;
  height: 2px;
  background: white;
  transition: width .3s ease;
}

h1:hover::before,
h1:hover::after {
  width: 100%;
}

h1::before {
  top: 0;
  left: 0;
}

h1::after {
  top: 100%;
  right: 0;
 
}
<body>
<div class="text-wrapper">


  <h1 id='text'>
    Days are gone </h1>


</div> 
</body>

最佳答案

您可以使用 :hover 执行此操作。#text:hover{color:red}

body {
  Background: #7a86cb;
  text-align: center;
}

h1 {
  text-align: center;
  color: #6849e3;
  font-family: Merriweather;
  display: inline-block;
  position: relative;
}

h1:hover {
   color: #6849e3;
   
 }

h1::before,
h1::after {
  content: "";
  width: 0%;
  position: absolute;
  height: 2px;
  background: blue;
  transition: width .3s ease;
}

h1:hover::before,
h1:hover::after {
  width: 100%;
}

h1::before {
  top: 0;
  left: 0;
}

h1::after {
  top: 100%;
  right: 0;
 
}
#text:hover{
color:red
}
<body>
<div class="text-wrapper">


  <h1 id='text'>
    INTERNET </h1>


</div> 
</body>

关于html - 将鼠标悬停在文本上时难以更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56683695/

相关文章:

PHP MySQL将html输出三乘三排列,按组的第一个字母排序

html - 带边距间距的 Flexbox 网格系统

javascript - 如何最小化一个 div 并隐藏包含的 div?

javascript - 如何缩小多复选框过滤器中的搜索结果?

jquery - 如何使用代码清除特定站点的缓存?

javascript - 提交时从表单中删除未更改的输入字段

html - 如何将音频混合到html5视频中?

html - 我怎样才能把这张 table 放在一个盒子里?

php - 一起使用 HTML 和 Php?

javascript - jQuery 和 Twitter Bootstrap 进度条