【问题标题】:Hover two elements without shifting effect悬停两个元素而没有移位效果
【发布时间】:2017-04-24 08:48:22
【问题描述】:

如何同时悬停带有文本“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>

对于已缩短代码的示例,我的代码更复杂。谢谢!

【问题讨论】:

    标签: html css hover css-transitions


    【解决方案1】:

    仅在 '.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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 2021-11-12
      • 2013-06-08
      • 2010-11-30
      • 2017-08-14
      • 2021-07-12
      • 1970-01-01
      相关资源
      最近更新 更多