2

I want to create menu where I need a feature like if any user hover the menu there will be a border and the border bottom only. I want to display the bottom border like trapezoid.

In my case i don't have a div for border, its only border-bottom.

Here is what I've tried:

#myDiv{
  background: #FED;
  border-bottom: 5px solid red;
}
<div id="myDiv">
  My div, I want to make my border bottom like trapezoid.
</div>

How can I achieve this?

  • Possible duplicate of [How do CSS triangles work?](http://stackoverflow.com/questions/7073484/how-do-css-triangles-work) – Justinas Jun 01 '16 at 06:30
  • In my case i don't have a div for border, its only border-bottom. –  Jun 01 '16 at 06:31
  • use `:after` to have triangle – Richa Jun 01 '16 at 06:32
  • 5
    I don't quite understand what you mean by *bottom border like triangle* - Can you include an image of the output you need? – Harry Jun 01 '16 at 06:32
  • 1
    As i make a customized output from answer, I understand that my desired shape is `trapezoid and not a triangle`. Thanks @Harry –  Jun 01 '16 at 06:42
  • @Justinas, I change my question, Is it also the same Duplicate??? –  Jun 01 '16 at 06:49

2 Answers2

3

If I get your correctly, you want to set the border shaped as triangle trapezoid after #myDiv. This is basically how you can do it with css..

#myDiv:after {
  content: "";
  display: block;
  border-left: 1vw solid transparent;
  border-top: 10px solid red;
  border-right: 1vw solid transparent;
 }
<div id="myDiv">
  My div, I want to make my border bottom like triangle.
</div>
choz
  • 17,242
  • 4
  • 53
  • 73
1

#myDiv {
  
  position: relative;
  display: inline-block;
 }
#myDiv:after {
    content: "";
    display: block;
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-top: 20px solid #f00;
    left: 50%;
    position: absolute;
    margin-left: -10px;
    bottom:-20px;
    display: none;
 }
 #myDiv:hover {
  border-bottom: 3px solid #f00;
 }
 #myDiv:hover:after {
  display: block;
 }
<div id="myDiv">
  My div, I want to make my border bottom like triangle.
</div>

#myDiv {
  position: relative;
  display: inline-block;
 }
#myDiv:after {
    content: "";
    display: block;
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-top: 20px solid #f00;
    left: 50%;
    position: absolute;
    margin-left: -10px;
    bottom:-20px;
    display: none;
 }
 #myDiv:hover {
  border-bottom: 3px solid #f00;
 }
 #myDiv:hover:after {
  display: block;
 }
Saika
  • 398
  • 3
  • 14
  • Hi Sayed, Please add HTML code,
    My div, I want to make my border bottom like triangle.
    , and see result on hover
    – Saika Jun 01 '16 at 07:11