On our website we have got a simple BB-Code based editor to create our posts. To be able to create basic grids I added a new tag which is a simple wrapper with display:grid and grid-template-columns: repeat(2, 1fr).
So the input looks something like this:
[easy-columns]
[box]
Text box 1
[/box]
[box]
Text box 2
[/box]
[/easy-columns]
And the output would look like this:
<div class="easy-columns">
<div class="box">Text box 1</div>
<br />
<div class="box">Text box 2</div>
</div>
My problem comes with the line breaks which let the grid collapse.
Solution 1: So my first attempt was simply to set display: none to the br elements inside the wrapper. But I am not sure if this is working in all browsers. (I would prefer this very simple solution)
Solution 2: And my second attempt was to use php domdocument to remove all br children from the div with the class easy-columns.
Is my css solution working or just a working 'bug' in my testing environment? Or should i go with domdocument?
.easy-columns {
gap: 2em;
align-items: stretch;
display: grid;
grid-auto-flow: row;
grid-template-columns: repeat(2, 1fr);
justify-items: stretch;
margin-bottom: 2em;
max-width: 100%;
overflow: hidden;
position: relative;
width: 100%;
}
.css-approach>br {
display: none;
}
.box {
background-color: grey;
color: white;
display: inline-block;
padding: 2em;
position: relative;
text-align: left;
}
[easy-columns]<br /> [box]
<br /> Text box 1<br /> [/box]
<br /> [box]
<br /> Text box 2<br /> [/box]
<br /> [/easy-columns]
<br />
<br />
<hr />
<br />
<br />
<div class="easy-columns">
<div class="box">
Text box 1
</div>
<br />
<div class="box">
Text box 2
</div>
</div>
<div class="easy-columns css-approach">
<div class="box">
Text box 1
</div>
<br />
<div class="box">
Text box 2
</div>
<div class="box">
Text box 1
</div>
<br />
<div class="box">
Text box 2
</div>
</div>