纯CSS三角形与半透明边框 可能?

前端之家收集整理的这篇文章主要介绍了纯CSS三角形与半透明边框 可能?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用CSS可以绘制一个有半透明边框的箭头吗?

到目前为止,我一直在努力,
http://jsfiddle.net/calebo/fBW4u/

CSS:

  1. .ui-overlay {
  2. padding-bottom: 10px;
  3. position: relative;
  4. }
  5. .ui-overlay-content {
  6. background: #999;
  7. color: #000;
  8. padding: 8px;
  9. border-radius: 4px;
  10. border: 5px solid rgba(0,0.2);
  11. background-clip: padding-Box;
  12. height: 100px;
  13. width: 200px;
  14. }
  15. .arrow {
  16. border-color: #999 transparent transparent;
  17. border-style: solid;
  18. border-width: 10px 10px 0;
  19. bottom: 5px;
  20. left: 15px;
  21. width: 0;
  22. height: 0;
  23. position: absolute;
  24. overflow: hidden;
  25. }

解决方法

这仍然需要一些工作,但这里是一般的想法:

使用伪元素,旋转45度并将样式应用于:

  1. .arrow {
  2. bottom: -25px;
  3. left: 30px;
  4. width: 40px;
  5. height: 40px;
  6. position: absolute;
  7. overflow: hidden;
  8. }
  9. .arrow:after {
  10. content: ' ';
  11. display: block;
  12. background: red;
  13. width: 20px;
  14. height: 20px;
  15. transform: rotate(45deg);
  16. position: absolute;
  17. top: -19px;
  18. left: 3px;
  19. background: #999;
  20. border: 5px solid rgba(0,0.2);
  21. background-clip: padding-Box;
  22. }

这是小提琴:http://jsfiddle.net/yZ3vB/

这样做的问题是边框重叠,使边缘变暗。

这可能通过添加另一个元素来补救。

更新:是的你去:http://jsfiddle.net/sJFTT/

更新2:您甚至不需要额外的元素。您可以使用主框中的伪元素:

  1. .ui-overlay-content:after {
  2. content: ' ';
  3. border-width: 13px;
  4. border-color: #999 transparent transparent;
  5. border-style: solid;
  6. bottom: -10px;
  7. left: 30px;
  8. width: 0;
  9. height: 0;
  10. position: absolute;
  11. }

这是小提琴:http://jsfiddle.net/6v9nV/

更新3:实际上,您只需单个元素即可完成所有这些操作,而无需使用伪元素即前一个和后一个:

  1. .speech-bubble {
  2. background: #999;
  3. background: linear-gradient(top,#444 0%,#999 100%);
  4. background-clip: padding-Box;
  5. border: 5px solid rgba(0,0.2);
  6. padding: 20px;
  7. width: 200px;
  8. height: 100px;
  9. position: relative;
  10. }
  11. .speech-bubble:before{
  12. content: ' ';
  13. border-color: rgba(0,0.2) transparent transparent;
  14. border-style: solid;
  15. border-width: 17px;
  16. position: absolute;
  17. bottom: -39px;
  18. left: 16px;
  19. }
  20. .speech-bubble:after{
  21. content: ' ';
  22. border-color: #999 transparent transparent;
  23. border-style: solid;
  24. border-width: 13px;
  25. position: absolute;
  26. bottom: -26px;
  27. left: 20px;
  28. }

这是小提琴:http://jsfiddle.net/95vvr/

附:不要忘记生产中的供应商前缀!

猜你在找的CSS相关文章