Getting the Header Image to Function Nicely on Twenty Seventeen with IE & Edge
-
I’m running into the same issue as MurnaghanAP(@murnaghanap) had with the header image on individual pages (not the front page). The main image from the front page (which is loaded into WordPress at 2000px by 1200px) centers along the horizontal axis for the individual pages with the top and bottom 40% hidden, leaving the center 20% of the image showing on the individual pages when viewed with browsers that use “cutting-edge CSS techniques.” Edge and IE browsers are showing the bottom 20% of the image.
The reason for the difference, as Andrew Nevins (@anevins) pointed out, is support for the object-fit style, which Edge and ID don’t support (Edge is supposed to support it with release 16, but IE will never support it).
Twenty Seventeen’s css code (at line 1683) initially positions the image 50% from the left and top, but then does a -50% translateX and Y transform.
That style is overridden (at line 1728) for not front pages with a -50% translateX and a 0 translateY (this appears to be why the image is aligned at the bottom rather than the center).
For the browsers that support object-fit, they’re told (at line 1739) to ignore the transform and the left and top are set to 0 (rather than the 50%).
I put some code in my child-theme to adjust both the X and Y translate: transform: translateX(-50%) translateY(50%); (and repeated the code for the browsers that support object-fit).
It works on Edge and IE11 (the image is centered vertically on individual pages), but before putting the site online (it’s just running locally right now), I wanted to see if there is a problem doing it this way, and my second question is why does the theme shift the header image around the way it does, first shifting it one way, then shifting it another way, and then canceling the shift?
The code from my child them is below:
/* The header image on secondary pages is aligning at the bottom on IE and Edge as neither supports object-fit - this change moves the image down so the center (more or less) of the image is displayed rather than the bottom (changed translateY from 0 to 50%) */ .has-header-image:not(.twentyseventeen-front-page):not(.home) .custom-header-media img { -ms-transform: translateX(-50%) translateY(50%); -moz-transform: translateX(-50%) translateY(50%); -webkit-transform: translateX(-50%) translateY(50%); transform: translateX(-50%) translateY(50%); } /* For browsers that support 'object-fit' */ @supports ( object-fit: cover ) { .has-header-image:not(.twentyseventeen-front-page):not(.home) .custom-header-media img { -o-object-fit: cover; object-fit: cover; -ms-transform: none; -moz-transform: none; -webkit-transform: none; transform: none; width: 100%; } }
- The topic ‘Getting the Header Image to Function Nicely on Twenty Seventeen with IE & Edge’ is closed to new replies.