Over time, this particular query has been raised multiple times in various settings.
The general consensus seems to be that utilizing vertical-align: middle
is sufficient for styling purposes.
However, a recurring issue appears to be the lack of self-contained examples in these queries. While SVGs can provide self-containment, similar alignment challenges persist with other image types.
Despite attempts to align both the radio group and SVG images vertically by applying vertical-align: middle
, the desired alignment remains elusive.
<!DOCTYPE HTML>
<head>
<meta charset="UTF-8">
<style>
.myRadio .myradioG { vertical-align: middle; }
svg { stroke:black; stroke-width:5; opacity:0.5; }
</style>
</head>
<body>
<label class="myLabel">
<input type="radio" name="radioGroup" class="myradioG">
<svg width="100" height="100" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="30"
style="fill:blue;" />
</svg>
</label>
<label class="inline-radio">
<input type="radio" name="radioGroup" class="myradioG">
<svg width="100" height="100" viewBox="0 0 100 100">
<rect x="20" y="20" rx="15" ry="15" width="60" height="60"
style="fill:red;" />
</svg>
</label>
</body>
Citing numerous upvotes, an associated Q & A recommend replacing the existing style with the following:
<style>
svg { stroke:black; stroke-width:5; opacity:0.5; vertical-align:middle; }
</style>
However, implementing this change does not yield the intended result. Why?
Update
Having reviewed Michael's response, one potential area of confusion stands out. The focus should have been on clarifying the target of the vertical alignment—radio buttons with images—in instances where uniformity is lacking.
There is a desire to align the radio buttons alongside the images vertically.
Update 2
If someone could offer insight on why the current solution is effective, it would provide clarity. Discussions suggest applying "vertical-align: middle" to the element being aligned vertically, yet here we aim to align radio buttons with images, resulting in the need to apply the attribute to the images rather than the radio buttons. Why is this the case?