Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are willing to use <code>display: table-cell</code>, and pseudo-elements, you can have a pretty good solution (with some minor limitations).</p> <p>The HTML does not change:</p> <pre><code>&lt;div class="dossier_titre"&gt; &lt;h2&gt;Horizon 2020, nouvelles opportunités&lt;/h2&gt; &lt;/div&gt; </code></pre> <p>and you can apply the following CSS:</p> <pre><code>.zone_33 { width: 238px; padding: 0px; margin: 0px; } .zone_33 .dossier_titre { margin: 0px 0px 20px 0px; } .zone_33 h2 { color: #616263; font-size: 150%; font-weight: lighter; padding: 0px 0px 12px 0px; background: none; border-bottom: 1px solid grey; display: table-cell; text-transform: uppercase; } .zone_33 .dossier_titre:after { content: ""; display: table-cell; width: 100%; } </code></pre> <p>For the <code>&lt;h2&gt;</code> element, set <code>display: table-cell</code>, and add a pseudo-element after <code>.dossier_titre</code> (the containing block for the header/title element). The pseudo-element is also a <code>table-cell</code> and has a width of 100% (this is the key).</p> <p>Also, since <code>h2</code> is no longer a block element, add your margins to <code>.dossier_titre</code> to maintain the visual spacing in our layout.</p> <p><strong>How This Works</strong><br> I am creating a two-cell table with the second cell (the pseudo-element) having a width of 100%. This triggers the browser to calculate the shrink-to-fit width for the first cell (<code>h2</code>) that contains the title text. The first cell's width is thus the minimal needed to display the text. The bottom border is as long as the longest text line in the text block within the table-cell. </p> <p><strong>Limitations</strong><br> <code>table-cell</code> is not supported in IE7 without a hack, but the work-around is fairly well known and can be found if needed.</p> <p>If the title had many short words, you might get the line breaking in unexpected places. You would need to insert <code>&amp;nbsp</code> to keep specific words together as needed.</p> <p>Fiddle: <a href="http://jsfiddle.net/audetwebdesign/h34pL/" rel="noreferrer">http://jsfiddle.net/audetwebdesign/h34pL/</a></p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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