Skip to content

Applied Visual Design: Adjust the Height of an Element Using the height Property - correct solution does not pass #18045

Description

@nathanhannig

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'

Additional users having issues: https://forum.freecodecamp.org/t/applied-visual-design-adjust-the-height-of-an-element-using-the-height-property/199328/5

Add a Link to the page with the problem

https://learn.freecodecamp.org/responsive-web-design/applied-visual-design/adjust-the-height-of-an-element-using-the-height-property/

Tell us about your browser and operating system

  • Browser Name: Chrome
  • Browser Version:
  • Operating System:

If possible, add a screenshot here

Activity

  1. TomerPacific commented on Aug 25, 2018

    @TomerPacific
    Contributor

    I would like to take this issue, if anyone doesn't have any objections.

  2. nathanhannig commented on Aug 28, 2018

    @nathanhannig
    MemberAuthor

    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.

  3. prajwalsingla3014 commented on Sep 17, 2018

    @prajwalsingla3014

    @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.
    screenshot 42

  4. thecodingaviator commented on Nov 21, 2018

    @thecodingaviator
    Contributor

    @nathanhannig / @ezioda004 please close the issue, it's fixed afaik

  5. tdreid commented on Dec 11, 2018

    @tdreid

    Neither text-adjust-size: auto; nor text-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?

  6. added
    scope: curriculum
    on Feb 21, 2019
  7. lasjorg commented on Oct 3, 2019

    @lasjorg
    Contributor

    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.

    getComputedStyle: Notes

    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.

    And here is the jquery docs on height().

    jquery: height()

    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).

    offsetHeight

    This property will round the value to an integer.

    document.querySelector('h4').offsetHeight === 25

    Another option would be to do the rounding in the test or remove the CSS style test and just have the regex.

  8. RandellDawson commented on Nov 1, 2019

    @RandellDawson
    Member

    @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.

  9. lasjorg commented on Nov 2, 2019

    @lasjorg
    Contributor

    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.

  10. lasjorg commented on Nov 2, 2019

    @lasjorg
    Contributor

    Update:

    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:

    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)

  11. RandellDawson commented on Nov 7, 2019

    @RandellDawson
    Member

    @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.

  12. lasjorg commented on Nov 7, 2019

    @lasjorg
    Contributor

    @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.

  13. lasjorg commented on Nov 7, 2019

    @lasjorg
    Contributor

    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?

  14. moT01 commented on Nov 13, 2019

    @moT01
    Member

    I vote to just regex it - When we do that rounding, it makes room for invalid input; maybe something like height: 24.9px would pass.

  15. lasjorg commented on Nov 14, 2019

    @lasjorg
    Contributor

    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.

  16. ojeytonwilliams commented on Nov 14, 2019

    @ojeytonwilliams
    Contributor

    How much work is it to push updates now? It's been made much easier correct?

    @lasjorg To production? Yeah, it is. Mrugesh has made it very streamlined. The devops docs cover it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: curriculum

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions