Styling DIV Arrow Outlines - Making hollow triangl

2019-07-20 22:12发布

问题:

thank you for all the years that I've never had to post a question and simply just searched!

Now, I'm trying to draw an arrow with a DIV. Example: http://i.imgur.com/wZBgv.png

So far code such as that below will draw a triangle: http://i.imgur.com/9nr3b.png

.arrow-small {
position: absolute;
bottom: 0;
left: 0;
width: 0; 
height: 0;
border-style: solid;
border-width: 80px 600px 50px 600px; 
border-color: transparent transparent blue transparent;
}

One method I've tried has been to create a smaller filled triangle to place on top of the large one which would create the arrow outline that I'm looking for, however I can not find a way to make the top div show the page background to complete the effect.

For clarity, my questions:

1) How does one create a backgroundless arrow with a div?

2) Or, how does one show the body background in a div ontop of another div that is not transparent?

回答1:

jsFiddle Demo: Florescent Green Arrow

I don't think that will work because you're covering something opaque with something else opaque. If you're able to use CSS3, the following might suit your needs:

<html>
  <head>
    <style>
      .chevron {
        position: absolute;
        width: 50px;
        height: 10px;
        top: 20px;
        background-color:red;
      }
      .left
      {
        left: 0px;
        -webkit-transform: rotate(340deg);
        -moz-transform: rotate(340deg);
        -o-transform: rotate(340deg);
        -ms-transform: rotate(340deg);
        transform: rotate(340deg);
      }
      .right
      {
        left: 43px;
        -webkit-transform: rotate(20deg);
        -moz-transform: rotate(20deg);
        -o-transform: rotate(20deg);
        -ms-transform: rotate(20deg);
        transform: rotate(20deg);
      }
    </style>
  </head>
  <body>
    <div class='chevron left'></div>
    <div class='chevron right'></div>
  </body>
</html>

I discovered transforms on this page, which was given in response to this question, which sounds close to yours.