css绘制透明三角形

作者:互联网

2026-03-25

HTML教程

css实现下图样式,具体像素值记不住了,很好设置,html code (2014百度秋招面试题):

C# Code复制内容到剪贴板
  1. "demo">

分析:这个样式的关键就在三角形和三角形实现了之后的变成只有个边框的三角形。利用元素的:after和:before伪元素(请自动忽略低版本IE)。

思想:先实现个正方形,在实现个三角形层,放在右上角,然后再实现一个透明的三角形覆盖黑色三角形的内部,只留边框。

XML/HTML Code复制内容到剪贴板
  1. >
  2. <htmllang="zh">
  3. <head>
  4. <metacharset=utf-8>
  5. <title>demotitle>
  6. head>
  7. <style>
  8. #demo{
  9. width:100px;
  10. height:100px;
  11. border:2pxsolid#000;
  12. }
  13. #demo:before{
  14. content:'';
  15. display:block;
  16. width:0;
  17. height:0;
  18. position:relative;
  19. top:10px;
  20. left:100px;
  21. border-left:9pxsolid#000;
  22. border-top:7pxsolidtransparent;
  23. border-bottom:7pxsolidtransparent;
  24. }
  25. #demo:after{
  26. content:'';
  27. display:block;
  28. width:0;
  29. height:0;
  30. position:relative;
  31. top:-2px;
  32. left:100px;
  33. border-left:7pxsolid#fff;
  34. border-top:5pxsolidtransparent;
  35. border-bottom:5pxsolidtransparent;
  36. }
  37. style>
  38. <body>
  39. <divid='demo'>div>
  40. <script>
  41. script>
  42. body>
  43. html>

以上就是本文的全部内容,希望对大家的学习有所帮助。

原文:http://www.cnblogs.com/codinganytime/p/5193475.html