HTML Element Style How to - Align a label to the top middle of the div control and draw a rectangle around it








Question

We would like to know how to align a label to the top middle of the div control and draw a rectangle around it.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!--from   w w  w . j  a  v  a  2  s  .com-->
  text-align: center;
  width: 180px;
  border: 1px #333 solid; padding 5px;
  height: 90px
}
</style>
</head>
<body>
  <div id="ctrl">
    <span>This is a label</span>
  </div>
</body>
</html>

The code above is rendered as follows: