I’m new to python/flask, and have made a simple app which collects user input for 5 variables, and display an output that’s dependant on the combination of those six variables. I’ve made a simple webpage with the following code to collect the user’s input via clickable buttons:
function setValue(inputId, value, button) {
document.getElementById(inputId + '_input').value = value;
}
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
.button {
align-self: center;
background-color: #fff;
background-image: none;
background-position: 0 90%;
background-repeat: repeat no-repeat;
background-size: 4px 3px;
border-radius: 15px 225px 255px 15px 15px 255px 225px 15px;
border-style: solid;
border-width: 2px;
box-shadow: rgba(0, 0, 0, .2) 15px 28px 25px -18px;
box-sizing: border-box;
color: #41403e;
cursor: pointer;
display: inline-block;
font-family: Neucha, sans-serif;
font-size: 1rem;
line-height: 23px;
outline: none;
padding: .75rem;
text-decoration: none;
transition: all 235ms ease-in-out;
border-bottom-left-radius: 15px 255px;
border-bottom-right-radius: 225px 15px;
border-top-left-radius: 255px 15px;
border-top-right-radius: 15px 225px;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
}
.button:hover {
box-shadow: rgba(0, 0, 0, .3) 2px 8px 8px -5px;
transform: translate3d(0, 2px, 0);
}
.button:focus {
box-shadow: rgba(0, 0, 0, .3) 2px 8px 4px -6px;
}
<h1>Rhesus Genotype Analyzer</h1>
<form method="POST" action="/">
<label for="D">D:</label>
<button type="button" class="button" onclick="setValue('D', 'pos', this)">Pos</button>
<button type="button" class="button" onclick="setValue('D', 'neg', this)">Neg</button>
<label for="C">C:</label>
<button type="button" class="button" onclick="setValue('C', 'pos', this)">Pos</button>
<button type="button" class="button" onclick="setValue('C', 'neg', this)">Neg</button>
<br><br>
<label for="E">E:</label>
<button type="button" class="button" onclick="setValue('E', 'pos', this)">Pos</button>
<button type="button" class="button" onclick="setValue('E', 'neg', this)">Neg</button>
<br><br>
<label for="c">c:</label>
<button type="button" class="button" onclick="setValue('c', 'pos', this)">Pos</button>
<button type="button" class="button" onclick="setValue('c', 'neg', this)">Neg</button>
<br><br>
<label for="e">e:</label>
<button type="button" class="button" onclick="setValue('e', 'pos', this)">Pos</button>
<button type="button" class="button" onclick="setValue('e', 'neg', this)">Neg</button>
<br><br>
<input type="hidden" id="D_input" name="D">
<input type="hidden" id="C_input" name="C">
<input type="hidden" id="E_input" name="E">
<input type="hidden" id="c_input" name="c">
<input type="hidden" id="e_input" name="e">
<input type="submit" value="Submit">
The issue I have is that only one of the 10 buttons displays the ‘focus’ state. Is it possible to treat each row of buttons independently? I.e., allow the ‘D’ pos or neg button to be ‘focused’, and allow the ‘E’ pos or neg to be ‘focused’ too, so that the user can see what they’ve selected?
Thanks a lot for any help!
2
Answers
You can update the
className
of the selected buttons and separate the selected ones byclassName
. In this example, I addedactive
className to the clicked buttons and showed their background asgreen
. When the user clicks on the selected button again, remove theactive
className and set it to default properties.Hope, it’s clear and useful
One approach is as follows, though this answer is reliant on the
:has()
CSS pseudo-class function, though this is – now – well supported in modern browsers, this approach may mean you’ll need to use JavaScript depending on the browsers employed by your users.That said, the following meets your needs (I think) and uses only HTML and CSS to do so; explanatory comments are in the code:
JS Fiddle demo.
References:
:active
.align-items
.aspect-ratio
.background
.background-color
.block-size
.border
.border-radius
.box-sizing
.clip-path
.content
.cursor
.display
.filter
.flex-flow
.:focus
.font-family
.font-size
.font-weight
.gap
.:has()
, compatibility.:hover
.inset
.isolation
.margin
.margin-block-end
.min-block-size
.opacity
.padding
.padding-block
.padding-inline
.place-content
.pointer-events
.position
.scale
.transform
.transform-style
.transition
.transition-property
.:user-invalid
.z-index
.