Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have a non-rectangular div?

I need to shape ONE div tag in the following shape:

enter image description here

Is it possible to make it cross browser? I don't necessarily need rounded corners. I need it so I can change the color of the borders of the whole div on hover, so I assume it can't be achieved by using two divs.

like image 723
Ilya Knaup Avatar asked Jun 22 '11 17:06

Ilya Knaup


People also ask

How do you make a DIV not take up the whole width?

You can simply use the CSS display property with the value inline-block to make a <div> not larger than its contents (i.e. only expand to as wide as its contents).


1 Answers

A one div solution using pseudo elements:

/* relevant styles for shape */
.tab {
  border-top-left-radius: 0px;
  margin-left: 100px;
}

.tab:before {
  content:"";
  display: block;
  position: relative;
  height: 50px;
  width: 50px;
  right: 52px; /* width + border width */
  top: -2px;
  background-color: white;
  border: inherit;
  border-right-width: 0px;
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
}

/* styles to look like example */
div{
  box-sizing: border-box;
  background-color: white;
  border: 2px solid red;
  height: 100px;
  width: 200px;
  border-radius: 5px;
}

div:hover {
  border-color: green;
}
<div class="tab"></div>
like image 61
sudo rm -rf slash Avatar answered Oct 14 '22 11:10

sudo rm -rf slash