CSS Layout How to - Float div right tight within parent








Question

We would like to know how to float div right tight within parent.

Answer


<!--from ww w  . j a  v  a 2 s .co m-->

<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#a {
  overflow: auto;
  border: red 1px solid;
  position: relative;
}

#b {
  height: 400px;
  background: yellow;
  width: 200px;
  float: left;
}

#c {
  background: green;
  height: 100%;
  position: absolute;
  right: 0;
  width: 40px;
}
</style>
</head>
<body>
  <div id="a">
    <div id="b">A</div>
    <div id="c">B</div>
  </div>
</body>
</html>

The code above is rendered as follows: