Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

How do I achieve button smooth background transition on mobile device

Hi guys,

I've been working my random quote generator project and I want to achieve the effect that when I touch the button on mobile device the background color become semi-transparent. here is my code

#loadQuote {
  position: fixed;
  width: 12em;
  display: inline-block;
  left: 50%;
  margin-left: -6em;
  bottom: 50px;
  border-radius: 4px;
  border: 2px solid #fff;
  color: #fff;
  background-color: black;
  padding: 10px 0;
  transition: .5s ;
}

#loadQuote:active {
  background-color: rgba(255,255,255,.25);
  -webkit-transition: background-color 10ms linear;
     -ms-transition: background-color 10ms linear;
     transition: background-color 10ms linear;
}

I tried this out on google chrome emulator and it worked out fine but when I actually tried this on my iphone it doesn't have the effect as it should. I cannot think of why. and another weird thing is, at first I set the duration over which transitions should occur to 1000ms, the background changed really fast then I set them to be 10ms as in this case, the change appears much slowly and more noticeable. I was wondering why, shouldn't the animation last longer when the duration time is longer?

Here is the live demo for the project. https://zhenghaohe.github.io/random-quote-generator/

Thanks!

@Steven Parker could you help me with this?

Steven Parker
Steven Parker
229,783 Points

I don't have any experience with programming (or using, for that matter) iPhones. But it sounds like you have an issue with the browser in it. It makes no sense at all that 10ms would appear to be a long time.

@Steven Parker it's not necessarily programming iPhones, it's a simple web app and I want to use some responsive design to make it look good on any devices. I use chrome emulator to try different types of phones so it really is specifically related to iPhones. I agree it makes no sense at all that 10ms would appear to be a long time. But I really don't know how to figure this out or even debug css animations,

Steven Parker
Steven Parker
229,783 Points

Sure, but you said it works on other devices, just not on iPhones.

1 Answer

Hi Zhenghao,

I feel if you amend your code snippet so you are instead targetting the :focus state you will achieve the effect you are looking for.