CSS Reference

"clear" - css property (v. css 1)

  • To specify which sides of an element where other floating elements are not allowed.
  • Initial value: none
  • The property is not inherited
  • HTML usage: block-level elements
  • Browsers that support the clear - property :
    Internet Explorer Mozilla Firefox Opera Google Chrome Apple Safari

Possible clear values:

clear value Comments CSS
left The clearance of the generated box is set to the amount necessary to place the top border edge below the bottom outer edge of any left-floating boxes that resulted from elements earlier in the source document. 1
right The clearance of the generated box is set to the amount necessary to place the top border edge below the bottom outer edge of any right-floating boxes that resulted from elements earlier in the source document. 1
both The clearance of the generated box is set to the amount necessary to place the top border edge below the bottom outer edge of any right-floating and left-floating boxes that resulted from elements earlier in the source document. 1
none No constraint on the box's position with respect to floats. 1
inherit Will inherit the value from parent specification. This property value is new with CSS 2. 2

Property "clear" example:

<!DOCTYPE HTML >
<html  >
  <head>
    <title>Test</title>
    <script type="text/javascript" >
    </script>
    <style   type="text/css">
      .win { font-size:12px; background-color: #DDDDDD;
             width: 400px; height: 200px; }
      .tl  {float: left; margin: 4px 4px 4px 4px;
            width: 226px; background-color: #FFFFDD;}
      .tr  {float: right; margin: 4px 4px 4px 4px;
            width: 148px; background-color: #CCCCFF;}
      .fl  { width: 70px; height: 40px;
             margin: 4px 4px 4px 4px;
             float: left; background-color: #FFFFDD;}
      .fr  { width: 70px; height: 40px;
             margin: 4px 4px 4px 4px;
             float: right; background-color: #CCCCFF}
      .cb  {clear:both;}
    </style>
  </head>
  <body >
    <div class="win">
      <div class="fl">1. float left</div>
      <div class="fl">2. float left</div>
      <div class="fl">3. float left</div>
      <div class="fr">4. float right</div>
      <div class="fr">5. float right</div>
      <div class="tl cb" >(float: left;clear:both)
        Before you print a file on a Unix system, you may
        want to reformat it to adjust the margins,
        highlight some words, and so on. Most files
        can also be printed without reformatting ...
      </div>
      <div class="tr " >
        float: right
        <ul>
          <li>Unix system</li>
          <li>PostScript</li>
          <li>printing itself</li>
        </ul>
      </div>
      <div class="fl cb">6. float left (clear:both)</div>
      <div class="fl">7. float left</div>
      <div class="fl">8. float left</div>
      <div class="fr">9. float right</div>
      <div class="fr">10. float right</div>
    </div>
  </body>
</html>

Javascript access:

// To SET values ([o] is the target object)
[o].style.clear="clear value"
// To GET values you must first get the computed style object
// To get that object in IE or Opera:
var cStyle=[o].currentStyle;
// To get that object in Firefox, Chrome or Safari (w3c-type):
var cStyle=window.getComputedStyle([o],null)
// To GET the property value:;
var value=cStyle.clear;
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.