There is a table in my page, with 5 columns overall. 3 of these columns have static width, and the rest of them have dynamic width based on their content.
I've set max-width
to 170px, and min-width
to 50px. However, two strange thing happen:
1-
- in inspect, I can see that
min-width
(when cell is empty) is 188px, andmax-width
(when any extra character will cause a break word) is 408px. - When span consists of a very small piece of texts, like just a word, it gets a considerable padding from left and right, but in inspect I see
padding:0
for every direction.
I know that my span is not set to display:block
and its width is equal to the text inside it. So there must be something wrong with my column.
an instance of what happens can be seen in this picture.
Since I'm not sure which class or style caused this, I copied every style this dynamic column has received from inspect window, and put it here. I also marked those I thought would be relevant:
-webkit-font-smoothing: antialiased;
-webkit-user-select: none;
border-bottom-color: rgb(27, 25, 57);
border-bottom-style: none;
border-bottom-width: 0px;
border-collapse: collapse;
border-image-outset: 0px;
border-image-repeat: stretch;
border-image-slice: 100%;
border-image-source: none;
border-image-width: 1;
border-left-color: rgb(27, 25, 57);
border-left-style: none;
border-left-width: 0px;
border-right-color: rgb(27, 25, 57);
border-right-style: solid;
border-right-width: 2px;
border-top-color: rgb(27, 25, 57);
border-top-style: solid;
border-top-width: 2px;
**box-sizing: content-box;**
color: rgb(255, 255, 255);
direction: rtl;
**display: table-cell;**
font-family: iran, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 28.08px;
font-stretch: normal;
font-style: normal;
font-variant: normal;
font-weight: normal;
height: 44px;
line-height: 37.1429px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;
**max-width: 170px;**
**min-width: 50px;**
padding-bottom: 0px;
padding-left: 0px;
padding-right: 0px;
padding-top: 0px;
**position: relative;**
text-align: center;
vertical-align: middle;
**white-space: normal;**
word-break: break-all;
word-wrap: break-word;
What I've tried by now:
white-space : pre
; Not only adds extra padding to left and right, but also to the other two directions, too. Couldn't testwidth:100
; Although solves the extra padding issue, only lets the width to expand in inspect window, and prevents dynamic width in run time.- Alternating span with a div and set
display:inline
; no difference.margin:zero
, also no progress. Negative solves the problem for short spans, but lets longer spans to overflow the cell, which was predictable.
Any attempt to help will be highly appreciated. Thanks in advance.
edit: This is a jsFiddle which shows what happens. The padded one is the one which receive an extra padding from nowhere... or somewhere I can't see.