I have a two column grid.
main {
max-width: 300px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
grid-column-gap: 6.4rem;
}
h3::before {
content: '';
display: block;
background-color: black;
height: 1px;
grid-column: 1 / span 2;
}
<main>
<h3>Heading blah</h3>
<p>Velluptiae dolupiet, im ea dolut que expercia sandionsed mo minvelibus modi occati sit autat quis ut fugitias maio. Moluptat.</p>
<h3>Heading blah</h3>
<p>Velluptiae dolupiet, im ea dolut que expercia sandionsed mo minvelibus modi occati sit autat quis ut fugitias maio. Moluptat.</p>
<h3>Heading blah</h3>
<p>Velluptiae dolupiet, im ea dolut que expercia sandionsed mo minvelibus modi occati sit autat quis ut fugitias maio. Moluptat.</p>
</main>
main {
display: grid;
grid-template-columns: 1fr 1fr;
grid-column-gap: 6.4rem;
}
With headings in the left column and body text in the right column.
Is it possible to have a border-top
on my H3
headings (that display in the left column), that span both columns? Possibly using the before:: pseudo-element? So a horizontal line appears above the headings and goes across both columns. Like trying to insert a <hr>
element before every H3
that spans both columns.
I've got the following:
h3::before {
content: "";
position: absolute;
border-top: 1px solid;
width: 100%;
grid-column: 1 / -1;
}
But the border-top stretches outside the width of the containing element (main
) and touches the right hand side of the browser window. Position: relative
doesn't seem to work.
UPDATE
I've tried this, but the black line only stretches across one column.
h3::before {
content: '';
display: block;
background-color: black;
height: 1px;
width: 100%;
grid-column: 1 / -1;
}
UPDATE 2
I guess I need the CSS grid to treat the before:: pseudo-element as an actual element, in order for it to span more than one column? Is that possible? According to this 5 year old post pseudo-elements are treated as an element in grid. pseudo-element acting like a grid item in CSS grid But that isn't the case for me.
`, therefore it is constrained to the dimensions of its parent, which only spans a single column.
– Terry Oct 27 '22 at 12:03and
– user2991837 Oct 27 '22 at 12:08and padding left to
to create a 'gap' and then add border top to both
and
– user2991837 Oct 27 '22 at 12:12`? ([Demo](https://jsfiddle.net/davidThomas/d4mn152r/)) – David Thomas Oct 27 '22 at 12:13
to the html. But to come up with a CSS work around – user2991837 Oct 27 '22 at 12:20