html - CSS中文本前的斜杠

标签 html css

我试着做这样的事情:

---

.line {
  font-size: 40px;
  transition: all .3s linear;
}

a:hover .line {
  font-size: 30px;
}

.text {
   position: relative;
    top: -7px;
}

<a href="#">
<span class="line">/</span>
 <span class="text">Home Page</span>
</a>  

但是当我尝试缩放这条线时,它会移动所有链接。 我想从中心缩放这条线而不移动所有元素。

a,
a:hover,
a:focus {
  text-decoration: none;
}

.line {
  font-size: 40px;
  transition: all .3s linear;
}

a:hover .line {
  font-size: 30px;
}

.text {
   position: relative;
    top: -7px;
}
<a href="#">
<span class="line">/</span>
 <span class="text">Home Page</span>
</a>  
<br>
<a href="#">
<span class="line">/</span>
 <span class="text">Another Page</span>
</a>  
<br>
<a href="#">
<span class="line">/</span>
 <span class="text">Another Page 2</span>
</a>  

最佳答案

不要调整字体大小,而是使用 scale 转换。

a,
a:hover,
a:focus {
  text-decoration: none;
}
.line {
  font-size: 40px;
  transition: all .3s linear;
  display: inline-block;
  /* required */
}
a:hover .line {
  transform: scale(0.75);
}
.text {
  position: relative;
  top: -7px;
}
<a href="#">
  <span class="line">/</span>
  <span class="text">Home Page</span>
</a>
<br>
<a href="#">
  <span class="line">/</span>
  <span class="text">Another Page</span>
</a>
<br>
<a href="#">
  <span class="line">/</span>
  <span class="text">Another Page 2</span>
</a>

更好的是......不要使用额外的跨度只是为了样式,而是使用伪元素......但同样的原则适用。

a,
a:hover,
a:focus {
  text-decoration: none;
}
a:before {
  content: '/';
  font-size: 40px;
  transition: all .3s linear;
  display: inline-block;
}
a:hover:before {
  transform: scale(0.75);
}
.text {
  position: relative;
  top: -7px;
}
<a href="#">
  <span class="text">Home Page</span>
</a>
<br>
<a href="#">
  <span class="text">Another Page</span>
</a>
<br>
<a href="#">
  <span class="text">Another Page 2</span>
</a>

关于html - CSS中文本前的斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38303976/

相关文章:

javascript - 为什么我不能在 HTML 标签中插入评论?

javascript - 无需插件即可创建滚动页面。无滚动效果

html - 有条件地链接到其他 html 页面

javascript - 转.js : Responsive Design With a Double-Page Viewing Format Not Working

html - div 内部 block 的垂直对齐中间

html - 边框 css 变化比变换旋转更快

html - 当我将鼠标悬停在一个词上时,如何使 css 不移动整个页面?

javascript - React Grid Layout - 在第一次初始化后更新 Tinymce Editor 高度

html - 如何在文本下创建一个点/小圆圈?

javascript - 将 HTML 元素分组为 2 个一组