Span Width Not Working

Span is an inline element. It has no width or height.

1
2
3
4
5
6
7
8
9
<div id='box' style='  
  background: black;  
  border-radius: 15px;  
  top: 4%;  
  left: 2%;  
  width: 96%;  
  height: 94%;  
  position: absolute;  
'><span style='color:white; width:100%; text-align:right;'>test</span></div>

Things like this won’t work. You need to change the style of a span to something like below.

1
2
3
4
5
6
7
8
9
<div id='box' style='  
  background: black;  
  border-radius: 15px;  
  top: 4%;  
  left: 2%;  
  width: 96%;  
  height: 94%;  
  position: absolute;  
'><span style='color:white; width:100%; **display:inline-block;** text-align:right;'>test</span></div>

https://miro.medium.com/max/1400/1*QShqdyN82RpVk6iUD09Sww.png

And it worked!

According to Basheer AL-MOMANI (css — Does height and width not apply to span? — Stack Overflow): You could turn it into a block-level element, then it will accept your dimension directives.

contact me Hung, Chien-Hsiang (chienhsiang-hung.github.io)