<form>
<fieldset>
<label class="active">
<input type="radio" name="class" value="container--one" class="radio" checked="checked">
<code>row</code>
<small>(default)</small>
</label>
<label>
<input type="radio" name="class" value="container--two" class="radio">
<code>column</code>
</label>
<label>
<input type="radio" name="class" value="container--three" class="radio">
<code>row</code> (+ writing-mode)
</label>
<label>
<input type="radio" name="class" value="container--four" class="radio">
<code>column</code> (+ writing-mode)
</label>
</fieldset>
</form>
<div class="container container--one" id="container">
<p>
<strong>Item 1</strong>
</p>
<p>
<strong>Item 2</strong>
</p>
<p>
<strong>Item 3</strong>
</p>
</div>
xxxxxxxxxx
.container--one {
flex-direction: row;
}
.container--two {
flex-direction: column;
}
.container--three {
flex-direction: row;
writing-mode: vertical-rl;
}
.container--four {
flex-direction: column;
writing-mode: vertical-rl;
}
/* ETC (Formatting only): */
body {
margin: 1.5em;
font-size: 130%;
font-family: sans-serif;
background: #F2F0EC;
color: #2E2C08;
}
.container {
border: 10px solid #2E2C08;
background: white;
padding: 1em;
display: flex;
}
.container p {
text-align: center;
background: #e5e3de;
font-weight: bold;
margin: 1rem;
padding: 1rem;
border: .5rem dotted #abab9d;
padding-block: 2rem;
border-block-color: #2E2C08;
}
fieldset {
border: darkgrey 1px solid;
padding: 0;
margin-bottom: 2em;
}
label {
display: inline-block;
padding: 0.5em;
cursor: pointer;
}
.active {
background: lightgrey;
}
xxxxxxxxxx
var radios = document.querySelectorAll('.radio');
var container = document.getElementById('container');
radios.forEach(function(i){
i.addEventListener('click', function(el){
var clicked = el.currentTarget;
var active = clicked.parentElement.parentElement.querySelector('.active');
active && active.classList.remove('active');
clicked.parentElement.classList.add('active');
container.className = 'container '+clicked.value;
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.