在不移动其他文本的情况下增加字体大小 [英] Increasing font size without moving other text

查看:91
本文介绍了在不移动其他文本的情况下增加字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习HTML和CSS,我已经搜索了这个问题,但是没有找到适合我的解决方案.

I'm learning HTML and CSS, I have searched this question but I didn't find a solution which worked for me.

因此,在我的导航栏中,当用户将鼠标悬停在一段文本上时,大小会增加,但也会移动其他文本.我希望增加大小,但不要移动其他文本.

So in my navigation bar, when the user hovers their mouse over a piece of text the size increases but also moves the other pieces of text. I want the size to increase but not move the other pieces of text.

我的网站

.nav {
    margin-top: 0px;
    height: 40px;
    width: 600px;
    background: white;
}
.nav ul {
    display: inline-block;
    margin: 0;
    padding: 0;
}
.nav ul li {
    list-style: none;
    display: inline;
}
.nav ul li a {
    text-decoration: none;
    float: left;
    display: block;
    padding: 10px 20px; 
    color: black;
    font-family: ProximaNova;
    font-size: 18px;
}
.nav ul li a:hover {
    color: #D46300;
    font-size: 22px;
}

 <div class="nav">
            <ul>
                <li><a href="news.html">News</a></li>
                <li><a href="servers.html">Servers</a></li>
                <li><a href="donate.html">Donate</a></li>
                <li><a href="bans.html">Bans</a></li>
                <li><a href="support.html">Support</a></li>
            </ul>
        </div>

推荐答案

这是您要寻找的吗?

.nav {
  margin-top: 0px;
  height: 40px;
  width: 600px;
  background: white;
}

.nav ul {
  display: block;
  margin: 0;
  padding: 0;
  position: relative;
}

.nav ul li {
  list-style-type: none;
  display: inline-block;
  width: 20%;
  padding: 0;
  margin: 0;
  float: left;
  text-align: center;
}

.nav ul li a {
  text-decoration: none;
  display: block;
  width: 100%;
  height: 100%;
  line-height: 40px;
  color: black;
  font-family: ProximaNova;
  font-size: 18px;
  transition: color .3s cubic-bezier(0.55, 0, 0.55, 0.2) , font-size .3s cubic-bezier(0.55, 0, 0.55, 0.2) ;
}

.nav ul li a:hover {
  color: #D46300;
  font-size: 22px;
}

<center>
  <div class="nav">
    <ul>
      <li><a href="news.html">News</a></li>
      <li><a href="servers.html">Servers</a></li>
      <li><a href="donate.html">Donate</a></li>
      <li><a href="bans.html">Bans</a></li>
      <li><a href="support.html">Support</a></li>
    </ul>
  </div>
</center>

实际上,不建议更改文本动画的字体大小,因为大多数情况下,动画都是生涩的.这是使用scale的示例:

As a matter of fact, changing font size is NOT recommended for text animations, as most of the times animation is jerky. Here's an example using scale:

.nav {
      margin-top: 0px;
      height: 40px;
      width: 600px;
      background: white;
    }
    .nav ul {
      display: block;
      margin: 0;
      padding: 0;
      position: relative;
    }
    .nav ul li {
      list-style-type: none;
      display: inline-block;
      width: 12%;
      padding: 0;
      margin: 0;
      text-align: center;
    }
    .nav ul li a {
      text-decoration: none;
      text-rendering: geometricPrecision;
      position: relative;
      display: block;
      width: 100%;
      height: 100%;
      line-height: 40px;
      color: black;
      font-family: ProximaNova;
      font-size: 18px;
      transition: transform .3s cubic-bezier(0.55, 0, 0.55, 0.2) , color .3s cubic-bezier(0.55, 0, 0.55, 0.2);
      transform-origin: 50% 30%;
    }
    .nav ul li a:hover {
      color: #D46300;
      transform: scale(1.3);
    }

<center>
  <div class="nav">
    <ul>
      <li><a href="news.html">News</a>
      </li>
      <li><a href="servers.html">Servers</a>
      </li>
      <li><a href="donate.html">Donate</a>
      </li>
      <li><a href="bans.html">Bans</a>
      </li>
      <li><a href="support.html">Support</a>
      </li>
    </ul>
  </div>
</center>

这是小提琴.可以根据自己的喜好进行调整.

Here's the fiddle. Feel free to tweak it to your liking.

这篇关于在不移动其他文本的情况下增加字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆