The block level element fills 100% overflow width-x: scroll container

I have a container element that has a specific width, s overflow-x: auto. In it, I have a block level header element (h1), which should be a block element, fill the container horizontally. And he does this until there are no other elements in the container that overflow, creating a horizontal scrollbar. If there are overflow elements, then the header element fills only the non-overflowing horizontal space of the container, but does not appear in the overflowing space.

Violin demonstrating the problem: http://jsfiddle.net/rand0mbits/qUh3s/

HTML:

<div id="one">
    <h1>header</h1>
    <table><tr><td>text</td><td>text</td><td>text</td><td>text</td><td>text</td>
    <td>text</td></tr></table>
</div>

CSS

#one {
    width: 200px;
    overflow: auto;
    border: solid 1px;
}

#one h1 {
    font-size 1.1em;
    background-color: blue;
    display: inline-block;
    width: 100%;
    margin-top: 0;
}

table td {
    border: solid 1px;
    padding: 20px;
}

How to make it <h1>fill the entire width of the container?

+4
4

H1 , , , #one .

#one overflow: auto, DIV overflow: auto. , #one , .

jsfiddle: http://jsfiddle.net/yetti/Ggua5/

+4

. fiddle.

HTML caption:

<div id="one">    

    <table>
        <caption>
            <h1>header</h1>
        </caption>
        <tr>
            <td>text</td>
            <td>text</td>
            <td>text</td>
            <td>text</td>
            <td>text</td>
            <td>text</td>
        </tr>
    </table>

</div>

CSS

#one {
    width: 200px;
    overflow: auto;
    border: solid 1px;    
}

#one h1 {
    font-size 1.1em;
    background-color: blue;        
    margin-top: 0;
    text-align: left;
}

table td {
    border: solid 1px;
    padding: 20px;
}
+6

:

CSS

#one {
    width: 200px;
    overflow: auto;
    border: solid 1px;
}

#one h1 {
    font-size 1.1em;
    background-color: blue;
    display: inline-block;
    width: 100%;
    margin-top: 0;
    position:relative;
}

table td {
    border: solid 1px;
    padding: 20px;
}

h1:after {
     content:"";
     background: blue;
     position: absolute;
     top: 0;
     bottom: 0;
     width: 100%;
    left:100%
 }

fiddle

+4

Change this CSS code as follows, then check and let me know if you want this:

#one {
width: 100%;
overflow: auto;
border: solid 1px;
}
+1
source

Source: https://habr.com/ru/post/1543092/


All Articles