HTML Element Style How to - Set Tabindex for DIV








Question

We would like to know how to set Tabindex for DIV.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div {<!--from w w w  .ja  v a 2  s .com-->
  background-color: rgba(232, 232, 232, 1);
  margin: 5px 10px;
  height: 100px;
  width: 500px;
  border: 2px solid rgba(232, 232, 232, 1);
  border-radius: 2px;
  line-height: 100px;
  color: rgba(144, 144, 144, 1);
  float: left;
  clear: none;
  position: relative;
}

div:focus {
  border: 2px solid rgba(243, 181, 33, 0.5);
  outline: none;
}

p {
  margin: auto;
  padding: 0 0 0 30px;
  font-family: Tahoma, Geneva, sans-serif;
  cursor: default;
}
</style>
</head>
<body>
  <div tabindex="0">
    <p>First</p>
  </div>
  <div tabindex="1">
    <p>Second</p>
  </div>
  <div tabindex="2">
    <p>Third</p>
  </div>
  <div tabindex="3">
    <p>Fourth</p>
  </div>
</body>
</html>

The code above is rendered as follows: