Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Span with percentage width

Like in case of tables

TD WIDTH 25    TD WIDTH 75

this is what I want to achieve with DIV/SPAN. All I have:

  <span style="background-color: green; width: 25%; display: inline-block;">1</span>
  <span style="background-color: yellow; width: 75%; display: inline-block;">2</span><br />
  <span style="background-color: green; width: 25%; display: inline-block;">a</span>
  <span style="background-color: yellow; width: 75%; display: inline-block;">b</span><br />

but then puts span to new line. It works with fix (px) sizes.

like image 234
John Smith Avatar asked Nov 20 '25 03:11

John Smith


2 Answers

use float

  <span style="background-color: green; width: 25%; float:left;">1</span>
  <span style="background-color: yellow; width: 75%; float:right;">2</span><br />
  <span style="background-color: green; width: 25%; float:left;">a</span>
  <span style="background-color: yellow; width: 75%; float:right;">b</span><br />

The problem is with the whitespace between the two spans.

<span style="display:inline:block; width:25%">..</span>
<span style="display:inline:block; width:75%">..</span>

These have a space between them, so the whole thing won't fit in 100%; it's 100% plus the width of a space wide.
If you remove the newline between the two spans, it will work.

<span style="display:inline:block; width:25%">..</span><span etc...>
like image 42
Mr Lister Avatar answered Nov 21 '25 16:11

Mr Lister