HTML Form How to - Align a label to top of radio button in CSS








Question

We would like to know how to align a label to top of radio button in CSS.

Answer


<!DOCTYPE html>
<html>
<head>
<style type="text/css">
label {<!--from  w ww  . j  av a2  s.  c  o m-->
  display: block;
}

ul {
  list-style: none;
  display: block;
}

ul li {
  float: left;
  display: block;
  width: 85px;
  text-align: center;
}
</style>
</head>
<body>
  <form>
    <ul>
      <li><input type="radio" name="opinions" id="radio-1" /> <label
        for="radio-1">Yes</label></li>
      <li><input type="radio" name="opinions" id="radio-2" /> <label
        for="radio-2">No</label></li>
      <li><input type="radio" name="opinions" id="radio-3" /> <label
        for="radio-3">I don't know</label></li>
      <ul>
  </form>
</body>
</html>

The code above is rendered as follows: