Page Widget How to - Force border-top to overlap border-left and border-right








Question

We would like to know how to force border-top to overlap border-left and border-right.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.box {<!--from w  w w.ja  v a 2  s .c  o m-->
  border: solid 3px blue;
  border-left-color: red;
  border-right-color: red;
  width: 200px;
  height: 200px;
  position: relative;
}

.box:before {
  content: "";
  position: absolute;
  border-top: 3px solid blue; // save color as the .box
  width: 106px;
  left: -3px;
  top: -3px;
}
</style>
</head>
<body>
  <div class="box"></div>
</body>
</html>

The code above is rendered as follows: