HTML Element Style How to - Set width for inner div








Question

We would like to know how to set width for inner div.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.vote {<!--from  w  ww  . j ava 2  s.c o  m-->
  width: 300px;
  border: 1px solid black;
  height: 9px;
}

.up-vote {
  float: left;
  height: 9px;
  background: green;
}

.down-vote {
  float: left;
  height: 9px;
  background: red;
}
</style>
</head>
<body>
  <div class="vote">
    <div class="up-vote" style="width: 90%"></div>
    <div class="down-vote" style="width: 10%"></div>
  </div>
</body>
</html>

The code above is rendered as follows: