Reputation: 57
I have a fixed width and height div element which width/heigth changes when font-size property applied to it, Why?
I thought font-size affects only fonts size but not the container where it sits.
Upvotes: 2
Views: 2763
Reputation: 580
It's probably because of your display
properties.
display:table
and display:inline
both will adapt to your content's size even if you set a fixed width and height.
Try display:flex
or display:block
on your div and adjust the overflow
settings to your will (if you want the overflowed content to show or not) and you should be good.
Upvotes: 0
Reputation: 965
The width
and height
properties set the desired properties for an element, which means that the element may update it's size to fit the content.
If you wish to be restrict about sizing, you can use the overflow
property to update how it handles oversized content.
Examples:
overflow: hidden
: everything outside of the width
and height
won't be displayed
overflow: scroll
: the element has a scroll to show what's beyond width
and height
https://developer.mozilla.org/en/docs/Web/CSS/overflow
It may also be worth checking out min-width
, max-width
, min-height
and max-height
depending on your case.
Upvotes: 1