Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Impossible with Pure CSS given Constraints</h2> <p>It appears that what you are asking is in most cases mathematically impossible (except text being the same length) with only css <em>because of your constraints</em>. </p> <p>Consider an example of just two tabs and the following four particular (and conflicting) requirements of yours (assume <code>500px</code> fixed width container; requirements have been reordered for illustration):</p> <p><strong>(1)</strong> Each Tab has unknown width (depends on text inside).</p> <p>Assume Tab2 has text twice as long as Tab1. So for the illustration, Tab1 = <code>10px</code>, Tab2 = <code>20px</code>, then...</p> <p><strong>(2)</strong> All Tabs should share the same padding (space from outer most letters to inner border of tab should be the same, represented by the ".." above). This padding does not have to be fixed but should be the same among the tabs.</p> <p>and...</p> <p><strong>(3)</strong> No Calculations. All should work without modifying the css if one ore more tabs are added or removed.</p> <p>Self-explanatory enough, but...</p> <p><strong>(4)</strong> Tabs should not expand over that div, but <em>should fill it out</em>.</p> <p><strong>This means one of the following:</strong></p> <p><strong>A.</strong> Each Tab will be 50% of the width and text width remains unaltered, so Tab1 = <code>120px 10px 120px</code>, Tab2 = <code>115px 20px 115px</code>, which does not meet (1) as overall size of both will be same width, or (2) as padding will vary in width per the illustration, but does possibly meet (3) and (4). This is <em>not</em> what you desire.</p> <p><strong>B.</strong> Each Tab will be 50% of the width, but text width must <em>stretch</em> for Tab1 or <em>compress</em> for Tab2 to make the text width equal. This still technically fails to fulfill (1), but does meet (2) &amp; (4) as both are set to either <code>120px 10px 120px</code> or <code>115px 20px 115px</code>, as the text gets distorted in some way to "fit" the space. Whether this is possible without doing (3) is questionable, but probably irrelevant, as I'm sure this is <em>not</em> what you desire.</p> <p><strong>C.</strong> Each Tab will be set as you desire for (1) and (2) with (2) at some fixed amount (say 10px), which leaves gaps between or around the tabs, something like <code>10px 10px 10px</code>, gap of <code>430px</code>, then <code>10px 20px 10px</code>. This will possibly be able to meet (3), but does not meet (4) as they will not really "fill" the space of the fixed container--there is going to be "gaps" somewhere. This is not what you want.</p> <p><strong>D.</strong> What you ultimately state you want is for each Tab to have padding set to be equal, which can be done with respect to (1) and (2), but not with your constraint (3), <em>as a calculation is needed</em>. In the example, it is <code>(500px - 30px) / 4 = 117.5px</code>. This makes the tabs <code>117.5px 10px 117.5px</code> and <code>117.5px 20px 117.5px</code>. But as you can see, since text is flexible width, this has to be done dynamically, roughly with the formula:</p> <pre><code>(containerWidth - totalTextWidths) / (2 x numTabs) = padding </code></pre> <p>If you want some type of small gap between tabs, then that would need to be added into the formula (here it assumes a 2px gap, so <code>gapWidths = ((numTabs - 1) x 2px)</code>):</p> <pre><code>(containerWidth - totalTextWidths - gapWidths) / (2 x numTabs) = padding </code></pre> <p><strong>So the constraints you give make the solution impossible--either a calculation has to be allowed for, or you need to rethink how you want your tabs to display.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload