html - 悬停两个元素没有移动效果

标签 html css hover css-transitions

如何在没有移动效果的情况下同时悬停带有文本“Myriam lefebvre”的 div 和跨度“Développeure-front-end”?

.logo__name {
  position: absolute;
  top: 0px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px;
  padding-bottom: 15px;
}

.logo__name:hover {
  background-color: #e54b4b;
}

.logo__name:hover h1 {
  color: #ffffff;
  transition: all 300ms ease;
}

.logo__name:hover h1 span {
  transition: all 300ms ease;
  color: #ffffff;
}

.logo__name h1 {
  font-family: 'Sacramento', Cursive;
  font-size: 2rem;
  font-weight: normal;
  margin: 0;
  padding: 0;
  transition: all 300ms ease;
  text-align: center;
}

.logo__name h1 div {
  height: 33px;
  overflow: hidden;
}

.logo__name h1 span {
  font-family: 'Pt Serif', Serif;
  font-size: 0.85rem;
  text-transform: uppercase;
  margin-top: -50px;
  display: block;
  transition: all 300ms ease;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  		<link href="https://fonts.googleapis.com/css?family=PT+Serif:400,700|Sacramento|Pathway+Gothic+One" rel="stylesheet">
  <title>Myriam Lefebvre</title>
</head>
<body>
<div class="logo__name">
	<h1><div>Myriam lefebvre</div><br /><span>Développeure-front-end</span></h1>
</div>
</body>
</html>

例如代码已经缩短,我的代码更复杂。谢谢!

最佳答案

仅在 '.logo__name' 、 '.logo__name h1 div' 、 '.logo__name h1 span' 标签上尝试使用转换语句。在悬停标签上不应该是必需的,因为非悬停版本已经暗示了它。这就是您要找的东西?

.logo__name {
  position: absolute;
  top: 0px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px;
  padding-bottom: 15px;
  transition: all 300ms ease;
}

.logo__name:hover {
  background-color: #e54b4b;
}

.logo__name:hover h1 {
  color: #ffffff;
}

.logo__name:hover h1 span {
  color: #ffffff;
}

.logo__name h1 {
  font-family: 'Sacramento', Cursive;
  font-size: 2rem;
  font-weight: normal;
  margin: 0;
  padding: 0;
  text-align: center;
}

.logo__name h1 div {
  height: 33px;
  overflow: hidden;
  transition: all 300ms ease;
}

.logo__name h1 span {
  font-family: 'Pt Serif', Serif;
  font-size: 0.85rem;
  text-transform: uppercase;
  margin-top: -50px;
  display: block;
  transition: all 300ms ease;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  		<link href="https://fonts.googleapis.com/css?family=PT+Serif:400,700|Sacramento|Pathway+Gothic+One" rel="stylesheet">
  <title>Myriam Lefebvre</title>
</head>
<body>
<div class="logo__name">
	<h1><div>Myriam lefebvre</div><br /><span>Développeure-front-end</span></h1>
</div>
</body>
</html>

关于html - 悬停两个元素没有移动效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41050842/

相关文章:

html - 伪元素上的 CSS 转换不起作用 "second time"

html - 制作 ul 元素列表并包装到其父级

javascript - 从 div onclick 切换悬停(删除悬停,将其添加回来)

jquery - jQuery .css() 和 CSS 悬停属性之间的冲突

html - css居中动态div

javascript - 为什么在按 Enter 或使用条形码扫描仪时我的表单被提交两次?

javascript - 使用cdnjs时报错 "failed to load resource (map)"

javascript - JQuery 一次切换两个类

jQuery 滑入滑出动画

css - 悬停时改变 li 的颜色