You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Applied Visual Design: Adjust the Height of an Element Using the height Property - correct solution does not pass #18045
Describe your problem and - if possible - how to reproduce it
When you provide the correct code the test still fails, this is do to the tests passing the true height of the element and not what the CSS is set to. This issue occurs mainly on smaller resolutions because the height of the element is smaller and converted by the browser.
In my Dev Tools it was saying the true height of the element was 24.99px and when I would scroll out the browser converted the true height to 25.01px. I had to find a sweet spot in my zoom level to where it was exactly 25px.
The fix is to change the test to use regex and not use assert($('h4').css('height') == '25px'
@nathanhannig I have used height:25px and text-size-adjust:auto in h4 tag. text-size-adjust basically control text inflation or deflation for smaller resolutions.It worked for all resolutions.Hope it will resolve your issue.
I can't reproduce this bug, I tried zooming and messing with the viewport but nothing makes it trigger, so it is really hard to test.
However, this issue may either be caused by what values are returned by getComputedStyle, or simply the fact that it isn't guaranteed to return an integer.
The values returned by getComputedStyle are resolved values. These are usually the same as CSS 2.1’s computed values, but for some older properties like width, height, or padding, they are instead the same as used values.
The number returned by dimensions-related APIs, including .height(), may be fractional in some cases. Code should not assume it is an integer. Also, dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition.
Using offsetHeight might return a more reliable result as it also rounds (returns a long).
@lasjorg Appears the fix did not work for everyone (even those using Chrome).
See this latest forum topic where at least two people are still reporting issues. You can see that for some at least one user, the document.querySelector('h4').offsetHeight returns 26 even though the window.getComputedStyle returned 24.9844px.
I see different numbers at diffrent zoom levels in Chrome as well. At zoom level 90%, 67%, and 50% I get 26, at 33% I get, 24.
I believe the fix might be to use scrollHeight instead.
@RandellDawson I can't login to the forum at all because of the login issues. So if you can test this for me in the forum thread I'd really appreciate it.
Using scrollHeight at 50% zoom I still get 26 and at 33% I get, 24. Not sure how likely it is a user will zoom out that far but we may have to use .getBoundingClientRect().height and do the rounding ourselves.
This works for me on all zoom levels: Math.round(document.querySelector('h4').getBoundingClientRect().height) === 25
The problem is, I'm not affected by the initial bug using offsetHeight was supposed to fix. So it's impossible for me to really test this. Worse case, I guess we have to use a regex only.
Some links with info on the different ways of getting element dimensions:
@lasjorg How close are we to a cross-browser way to test this? If it is getting too complicated, maybe we should use regex against the code as a fix for now and keep the discussion going in this issue. I would prefer a less elegant regex fix now because the forum is seeing the same topics over and over related to the bugs in these two challenges.
@RandellDawson The PRs for the height and width challenges should fix it. I also added a note to the challenges about the zoom.
edit: correction
As said in the PR for the height width challenge I don't have any confirmation for that one and because I still can not login to the forum I have been unable to get a confirmation. I was planning to ask the same user that helped with the other challenge. But I believe both should work regardless of browser zoom.
BTW, both challenge tests already have a regex in place. So if we do just want a regex all we need to do is remove the first part of the conditional assert. Please let me know in the PRs if that is a preferred solution.
How much work is it to push updates now? It's been made much easier correct?
I think just having a regex is the safer choice as well. And considering the test already have a regex it makes the first part of the conditional assert a bit pointless anyway.
Will update the two PRs (height/width) to just use the regex already in place.
Activity
TomerPacific commentedon Aug 25, 2018
I would like to take this issue, if anyone doesn't have any objections.
nathanhannig commentedon Aug 28, 2018
Go fo it.
I also noticed the same when zoomed in very far on your screen resolution for
https://learn.freecodecamp.org/responsive-web-design/responsive-web-design-principles/use-a-retina-image-for-higher-resolution-displays
test must be looking at the computed true value of the element instead of the css code that is defining it. Bad practice.
prajwalsingla3014 commentedon Sep 17, 2018
@nathanhannig I have used height:25px and text-size-adjust:auto in h4 tag. text-size-adjust basically control text inflation or deflation for smaller resolutions.It worked for all resolutions.Hope it will resolve your issue.

thecodingaviator commentedon Nov 21, 2018
@nathanhannig / @ezioda004 please close the issue, it's fixed afaik
tdreid commentedon Dec 11, 2018
Neither
text-adjust-size: auto;nortext-size-adjust: none;change the behavior for me. The test doesn't pass.Also, if that is necessary to pass the challenge shouldn't it be pointed out and explained for the benefit of the learner?
lasjorg commentedon Oct 3, 2019
I can't reproduce this bug, I tried zooming and messing with the viewport but nothing makes it trigger, so it is really hard to test.
However, this issue may either be caused by what values are returned by
getComputedStyle, or simply the fact that it isn't guaranteed to return an integer.And here is the jquery docs on height().
Using
offsetHeightmight return a more reliable result as it also rounds (returns along).document.querySelector('h4').offsetHeight === 25Another option would be to do the rounding in the test or remove the CSS style test and just have the regex.
RandellDawson commentedon Nov 1, 2019
@lasjorg Appears the fix did not work for everyone (even those using Chrome).
See this latest forum topic where at least two people are still reporting issues. You can see that for some at least one user, the
document.querySelector('h4').offsetHeightreturns26even though the window.getComputedStyle returned24.9844px.lasjorg commentedon Nov 2, 2019
I see different numbers at diffrent zoom levels in Chrome as well. At zoom level 90%, 67%, and 50% I get
26, at 33% I get,24.I believe the fix might be to use
scrollHeightinstead.@RandellDawson I can't login to the forum at all because of the login issues. So if you can test this for me in the forum thread I'd really appreciate it.
lasjorg commentedon Nov 2, 2019
Update:
Using
scrollHeightat 50% zoom I still get 26 and at 33% I get,24. Not sure how likely it is a user will zoom out that far but we may have to use.getBoundingClientRect().heightand do the rounding ourselves.This works for me on all zoom levels:
Math.round(document.querySelector('h4').getBoundingClientRect().height) === 25The problem is, I'm not affected by the initial bug using offsetHeight was supposed to fix. So it's impossible for me to really test this. Worse case, I guess we have to use a regex only.
Some links with info on the different ways of getting element dimensions:
https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements
https://docs.microsoft.com/en-us/previous-versions//hh781509(v=vs.85)
RandellDawson commentedon Nov 7, 2019
@lasjorg How close are we to a cross-browser way to test this? If it is getting too complicated, maybe we should use regex against the code as a fix for now and keep the discussion going in this issue. I would prefer a less elegant regex fix now because the forum is seeing the same topics over and over related to the bugs in these two challenges.
lasjorg commentedon Nov 7, 2019
@RandellDawson The PRs for the height and width challenges should fix it. I also added a note to the challenges about the zoom.
edit: correction
As said in the PR for the
heightwidth challenge I don't have any confirmation for that one and because I still can not login to the forum I have been unable to get a confirmation. I was planning to ask the same user that helped with the other challenge. But I believe both should work regardless of browser zoom.lasjorg commentedon Nov 7, 2019
BTW, both challenge tests already have a regex in place. So if we do just want a regex all we need to do is remove the first part of the conditional assert. Please let me know in the PRs if that is a preferred solution.
How much work is it to push updates now? It's been made much easier correct?
moT01 commentedon Nov 13, 2019
I vote to just regex it - When we do that rounding, it makes room for invalid input; maybe something like
height: 24.9pxwould pass.lasjorg commentedon Nov 14, 2019
I think just having a regex is the safer choice as well. And considering the test already have a regex it makes the first part of the conditional assert a bit pointless anyway.
Will update the two PRs (height/width) to just use the regex already in place.
ojeytonwilliams commentedon Nov 14, 2019
@lasjorg To production? Yeah, it is. Mrugesh has made it very streamlined. The devops docs cover it.