Search code examples
htmlcss-tables

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.


Solution

  • 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 />