jquery: Optimize footer display on mobile devices#486
Conversation
Optimize footer display on mobile devices
Fixed a bug that caused overflow when the width was too small.
mgol
left a comment
There was a problem hiding this comment.
Thanks for the PR. I don't think it's the best solution, though. What flex mostly does here is making float: left ineffective, more so than any real flex algorithm.
footer .books li has override styles for max-width: 700px. I checked and 3 books don't fit on the smallest phone screens (like first iPhone SE: 320 px wide) but they do for slightly larger screens.
In the interest of maintainability, I'd rather rework the whole footer .books & .footer .books li styles to remove floats and introduce flexbox with CSS gap, and then on the smallest breakpoints - max-width: 480 px - make it stretch instead.
Let me know if you'd like to work on it.
Rewrite the footer.books layout
mgol
left a comment
There was a problem hiding this comment.
Thanks for the updates. This is really close to what I'd like to see, just some tweaks needed and most of them involve removing more code.
themes/jquery/css/base.css
Outdated
| } | ||
|
|
||
| footer .books li:first-child { | ||
| margin-left: 0%; |
There was a problem hiding this comment.
In regular styles, we have margin-left: 2%. Do we need that? If not, both it and this override could be removed.
There was a problem hiding this comment.
I believe the purpose of margin-left: 2% is for visual compensation, because the title of the first book, Learning jQuery Fourth Edition, is rather long, and without a margin-left, the left and right sides might appear visually asymmetrical.Should it be removed?
There was a problem hiding this comment.
Actually, in the old layout the default margin-left for li elements in the books list is 2.8%, so this 2% for the first child decreases its margin, not increases it.
I think it's best to avoid such adjustments in the flex world. Let's remove this.
There was a problem hiding this comment.
I will remove the 2% margin😀.
themes/jquery/css/base.css
Outdated
| } | ||
|
|
||
| footer .books { | ||
| flex-wrap: wrap; |
There was a problem hiding this comment.
This is needed, but does it hurt to also leave it in general styles? Then we wouldn't need any additions to the max-width: 480px breakpoint; the general rules would cover everything.
Fix some issues
|
@mgol I have corrected most of the issues you mentioned. The fixed aspect ratio is no longer enforced below 480px. Finally, whether the margin-left code should be retained requires further judgment from you. |
mgol
left a comment
There was a problem hiding this comment.
Thanks, this looks a lot cleaner now!
I'll need to test this myself and I'm away from my computer right now, so I'll test this early next week and I'll see if we need any more changes.
themes/jquery/css/base.css
Outdated
| min-width: 95px; | ||
| margin-left: 2.8%; | ||
| margin-bottom: 15px; | ||
| flex: 1 0 29%; |
There was a problem hiding this comment.
Although the footer.books element in the original code has a width of 30%, I found during testing that maintaining 30% results in a display error on screens with dimensions between 770px and 940px.
footer .books li { float: left; width: 30%; min-width: 95px; margin-left: 2.8%; margin-bottom: 15px; line-height: 130%; font-size: 11px; text-align: center; }

The reason for this problem is that width(30%) x 3 + gap(16px) x 3 + first-child(2%) > 100%. Using 29%, it becomes width(29%) x 3 + gap(16px) x 3 + first-child(2%) < 100%. Of course, 29% isn't a very precise number, but it's simpler than using calc() and can display the desired result across all sizes.
There was a problem hiding this comment.
If the restriction is that a needs to be at least as large as the contained image then flex-basis should just be set to 92px instead of a percentage. So, flex: 1 0 92px here.
themes/jquery/css/base.css
Outdated
| } | ||
|
|
||
| footer .books li { | ||
| min-width: 92px; |
There was a problem hiding this comment.
Can you explain where this number came from?
There was a problem hiding this comment.
The width: 92px; here comes from the minimum image size set in the original footer.books.li a img attribute. I didn't change the actual image display size; I only rewrote the layout.
footer .books li a img { display: block; border-radius: 5px; border: solid 1px rgba(255,255,255,0.2); width: 92px; height: 114px; margin: 0 auto 5px; }
I think on devices with smaller screens, the size of the li element can be made to match the size of the img element inside it, so that the CSS can adapt to the screen size.
There was a problem hiding this comment.
If you set flex above to 1 0 92px as I suggested, this will probably not be needed anymore.
themes/jquery/css/base.css
Outdated
| } | ||
|
|
||
| footer .books li:first-child { | ||
| margin-left: 0%; |
optimize layout
|
@mgol Oh yes, I forgot to check the |



When the screen size is larger than 480px, follow the display style of the PC and place the books in a single line.


befofe:
after: