Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Transition font-size: avoid jittering / wiggling

Tags:

html

css

I made the following tile, with an hover-effect that increases the font-size with an CSS-transition:

body {
  font-family: 'Segoe UI', sans-serif;
}
.website {
  width: 180px;
  height: 73px;
  text-align: center;
  line-height: 80px;
  margin: 1px;
  color: white;
  border-bottom: 5px solid darkslateblue;
  background-color: darkslateblue;
  white-space: nowrap;
  overflow: hidden;
  transition: border-color 0.66s ease-out, font-size 0.3s ease-out;
}
.website:hover {
  font-size: 16pt;
  cursor: pointer;
  transition: border-color 0s;
  border-color: black;
}
<div class="website">Blog 1</div>
<div class="website">Blog 2</div>
<div class="website">Blog 3</div>

When you hover them you can see that the transition of the font-size is not smooth at all. In other words it wiggles up and down when changing size.
Does anyone have an Idea how to fix or work around it?

like image 369
CoderPi Avatar asked Jan 11 '16 09:01

CoderPi


People also ask

How to avoid CSS Jitter?

Don't transition the width and the height. Keep the same width and height and just transition the border of your outer circle.

How do I keep text from resizing CSS?

To prevent a text field from being resized, you can use the CSS resize property with its "none" value. After it you can use the height and width properties to define a fixed height and width for your <textarea> element.

What is hover transition?

CSS transitions allows you to change property values smoothly (from one value to another), over a given duration.

How do I Auto Adjust text in CSS?

The font-size-adjust property gives you better control of the font size when the first selected font is not available. When a font is not available, the browser uses the second specified font. This could result in a big change for the font size. To prevent this, use the font-size-adjust property.


1 Answers

On hover put transition: border-color 0s, font-size 0.3s ease-out;

Because on hover transition: border-color 0s will give only border-color transition not give to font-size.

body {
  font-family: 'Segoe UI', sans-serif;
}
.website {
  width: 180px;
  height: 73px;
  text-align: center;
  line-height: 80px;
  margin: 1px;
  color: white;
  border-bottom: 5px solid darkslateblue;
  background-color: darkslateblue;
  white-space: nowrap;
  overflow: hidden;
  transition: border-color 0.66s ease-out, font-size 0.3s ease-out;
}
.website:hover {
  font-size: 16pt;
  cursor: pointer;
  transition: border-color 0s, font-size 0.3s ease-out;
  border-color: black;
}
<div class="website">Blog 1</div>
<div class="website">Blog 2</div>
<div class="website">Blog 3</div>
like image 148
ketan Avatar answered Sep 30 '22 13:09

ketan