用CSS繪製三角形箭頭

來源:互聯網
上載者:User
用CSS繪製三角形箭頭。使用純CSS,你只需要很少的代碼就可以創作出各種瀏覽器都相容的三角形箭頭!

CSS代碼:

/* create an arrow that points up */div.arrow-up {    width: 0;    height: 0;    border-left: 5px solid transparent;  /* left arrow slant */    border-right: 5px solid transparent; /* right arrow slant */    border-bottom: 5px solid #2f2f2f; /* bottom, add background color here */    font-size: 0;    line-height: 0;} /* create an arrow that points down */div.arrow-down {    width: 0;    height: 0;    border-left: 5px solid transparent;    border-right: 5px solid transparent;    border-top: 5px solid #2f2f2f;    font-size: 0;    line-height: 0;} /* create an arrow that points left */div.arrow-left {    width: 0;    height: 0;    border-bottom: 5px solid transparent;  /* left arrow slant */    border-top: 5px solid transparent; /* right arrow slant */    border-right: 5px solid #2f2f2f; /* bottom, add background color here */    font-size: 0;    line-height: 0;} /* create an arrow that points right */div.arrow-right {    width: 0;    height: 0;    border-bottom: 5px solid transparent;  /* left arrow slant */    border-top: 5px solid transparent; /* right arrow slant */    border-left: 5px solid #2f2f2f; /* bottom, add background color here */    font-size: 0;    line-height: 0;}

繪製這些三角形的關鍵在於,你要讓箭頭所指方向的兩個側邊有很粗的邊框。而背向箭頭方向的一邊也是同樣粗的邊框,而這條邊的顏色就是你的三角形的顏色。邊框越粗,三角形越大。用這種方法你可以繪製出各種顏色、各種大小、各種朝向的箭頭。最妙的是,你只需要幾行CSS代碼就能實現這種效果。

  • 相關文章

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.