CSS Layout How to - Add a Border Around Floating Elements








Question

We would like to know how to add a Border Around Floating Elements.

Answer


<!DOCTYPE html>
<html>
<head>
</head><!--from   www  .  ja v  a 2  s. c  o  m-->
<body>
  <div style="overflow: hidden; border: 2px black solid;">
    <img src="http://www.java2s.com/style/download.png" alt="Test Image 1" style="float: right;" /> 
    <img src="http://www.java2s.com/style/download.png" alt="Test Image 2" style="float: left;" />
    <p>Test Text</p>
  </div>
</body>
</html>

The code above is rendered as follows: