Image shrinks, icons don't
Hi guys!
There's a problem with my navbar. I have a logo
<img src="QuickCart.svg" alt="logo" />
and couple of FA icons in my unordered list. When I make the window width smaller, image shrinks down up until the point it's not visible anymore, while icons remain the same size.
How can I make everything shrink? I mean, both the icons and the logo.Here's my JSX from Navbar component and couple of pictures:
44 Replies
well image shrink because there is probably set
width:100%
or max-width: 100%;
in font you have font-size
to change the size so you probably want to use clamp ???I haven't given any classes to img, so I guess its width is default to 100%.
Too bad there's no way to use clamp in Tailwind (at least not officially)
it's not default tailwind is probably adding that.
you can always extend tailwind in config and add what you want
I added clamp manually through .css file, but it doesn't seem to be doing the trick:
All images in Tailwind have
max-width: 100%
on them by default as you said, but if I remove that, everything just overflows and doesn't shrink๐ฅนyou added font size to svg not the icons
icons are text not an svg
Huh, I can see it's being applied in dev tools
that is why max-width: 100%; is for so the images shring to make them responsive
set the font size on li not svg ๐
wait
you have class fa-2xl
this probably set the size of the icons
Yeah, it does, I overruled it with
!important
Alright, I'll trywhat's the rule set by that fa-2xl class?
what have I done
Now it's hella big and it still won't shrink
revert the clamp back to the svg not li
you need to play with the clamp more to get effect you are after
does the svg of the icon get that
max-width:100%
from tailwind ?It does not
I just added it manually, icons do shrink now, but only after the logo shrinks out of the existence
oh so tailwind doesn't add max-width: 100% on svg strange
how small you go for the logo to disappear ?
It definitely has something to do with flex-1 on my container here:
Removing it makes everything shrink at almost the same time
But if I remove it, the search input breaks
with flex 1:
without:
and here's css it has:
why not use space-between instead of gap and flex-1 ?
It shrinks down until its not visible, like this
If I make the window smaller, it would be impossible to see the logo
how small the window get tho? you know there is nothing below like 320px in terms of devices
On 470px its not visible at all
Doesn't do the trick sadly
the gap screws with the shrinking imo
it's to big imo
Because I want the search input to stretch when it's on a bigger screen
like that
you can't try flex-shrink-0 on logo to stop it from shrinking so the flexbox will shrink only the searchabr
It might be the
ml-20
on my ul
that messes everything upml-20 what is that line margin-left : 20rem?
that is ridiculous lol
actually ml-20 is margin left 5rem
still big
5 * 16 is like 80px
why not ml-auto?
ml-auto does this:
same as no margin-left at all
looks much better with ml-20 on
probably it's not the best way
so you need a gap between logo search and ul
no need for margin there at all
add gap on the nav and remove that ml from ul
yeah, you right, I've just fixed it
apparently margin didn't have anything to do with, so the problem stays
damn styling things is really confusing
I removed the gap on
ul
and it got a bit better
But there's no gap which looks ugly...well you can add it but not a big one you need to remember it is small device. you can increase it at bigger viewport
I think I finally did it
All I had to do was to put max-width on both li and svgs inside of it
Now I don't even have to clamp anything actually, it works fine without it
Thanks for all your suggestions and your help! I'm eternally grateful ๐
no problem i made quick codepen maybe this will help you https://codepen.io/MannixMD/pen/QWBzyRG
i set small gaps and made flexbox do most of the work
Thanks! It looks nice
Really appreciate you going an extra mile
no problem i like coming up with solution it help me get better at it ๐