Transition not running at the same time on different elements

Asked

Viewed 30 times

1

Guys, I have a problem in the transition CSS3, I have an icon in Font Awesome and link text that changes from white to light green on :hover, but when taking out the mouse the color changes one in the sequence of the other, instead of changing together.

Situation:

inserir a descrição da imagem aqui

My code is arranged as follows:

@import url('https://fonts.googleapis.com/css?family=Oswald:200,300,400,500,600,700');

html * {
    box-sizing: inherit;
    font-size: 16px;
    transition: color 0.5s ease;
}

body {
    line-height: inherit;
    font-family: 'Oswald', 'sans-serif';
    font-size: inherit;
    max-width: 100%;
    padding: 0;
    color: #828282;
    background: #fff;
}

.header-top-menu {
    height: 40px;
    background-color: #393738;
    max-width: 100%;
    vertical-align: center;
}

.header-top-menu ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.header-top-menu ul li {
    display: inline;
    font-size: 14px;
    list-style: none;
}

.header-top-menu ul li a {
    padding: 2px 10px;
    display: inline-block;
    color: #ddd;
    text-decoration: none;
}

.header-top-menu ul li:hover a, .header-top-menu ul li:hover a i {
    color: #d6e78d;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">

<div class="header-top-menu flex-container">
	<div class="content-box">
		<div class="content-lt">
			<ul>
				<li>
                     <a href="mailto:email" title="Envie um e-mail pra gente :)" alt="Envie um e-mail pra gente :)" target="_blank"><i class="far fa-envelope"></i> email</a>
                 </li>
			</ul>
		</div>
	</div>
</div>

Even Font Awesome using the property of color: inherit is not working. Some solution?

  • I know if I add the attribute color: #ddd; in the element .header-top-menu ul li a i right, but there is some way to do this in a general way for the whole site without having to stay set color in all the elements that I want to put transition color?

1 answer

3


Dude you have a problem in the selectors, the hierarchy is not cool. I gave a adjusted taking the transition of html * and it looks like you’ve tidied up!

EDIT

It’s also a matter of selector performance, notice that if you put the text inside a span, guy icontext vc will see that you can put * { Transition } that will not give the bug. But if vc let the text loose, without being inside a tag will give the bug... The solution to use on the whole site is to put all the texts inside the tag, leaving nothing "loose". I edited the answer Look there. Test the Hover on H2 etc

@import url('https://fonts.googleapis.com/css?family=Oswald:200,300,400,500,600,700');

* {
  box-sizing: inherit;
  font-size: 16px;
  transition: color 0.5s ease;
}

body {
  line-height: inherit;
  font-family: 'Oswald', 'sans-serif';
  font-size: inherit;
  max-width: 100%;
  padding: 0;
  color: #828282;
  background: #fff;
}

.header-top-menu {
  height: 40px;
  background-color: #393738;
  max-width: 100%;
  vertical-align: center;
}

.header-top-menu ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.header-top-menu ul li {
  display: inline;
  font-size: 14px;
  list-style: none;
}

.header-top-menu ul li a {
  padding: 2px 10px;
  display: inline-block;
  color: #ddd;
  text-decoration: none;

}

.header-top-menu ul li:hover a,
h2:hover {
  color: #d6e78d;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">

<div class="header-top-menu flex-container">
  <div class="content-box">
    <div class="content-lt">
      <ul>
        <li>
          <a href="mailto:email" title="Envie um e-mail pra gente :)" alt="Envie um e-mail pra gente :)"
            target="_blank">
            <i class="far fa-envelope"></i> 
            <span>email</span>
          </a>
        </li>
      </ul>
      <h2>Lorem, ipsum.</h2>
    </div>
  </div>
</div>

  • Thanks for the help Hugo! Just one question: I want to use the transition color throughout the site, how can I be using it without giving this problem and without repeating code?

  • 1

    @Leonardodias is a matter of selector performance, notice that if you put the text within a span, like <a href=""><i>icone</i><span>texto</span></a> you’ll see who can put * { transition } that will not give the bug. But if you leave the text loose, without being inside a tag will give the bug... The solution to use on the whole site is to put all the texts inside the tag, leaving nothing "loose". I edited the answer Look there. Test the Hover on H2 etc

Browser other questions tagged

You are not signed in. Login or sign up in order to post.