html – CSS形状外 – Firefox浏览器支持

前端之家收集整理的这篇文章主要介绍了html – CSS形状外 – Firefox浏览器支持前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我一直在尝试使用跨浏览器的CSS形状,我已经在Chrome和Safari中使用它没有任何问题,我似乎无法在Firefox中工作(尚未测试IE,不期待那样).

codepen

这是HTML:

这是CSS:

  1. .container {
  2. width: 960px;
  3. margin: 0 auto;
  4. }
  5. section.hero {
  6. padding: 8px;
  7. Box-sizing: border-Box;
  8. overflow: hidden;
  9. width: 100%;
  10. height: 400px;
  11. float:left;
  12. section.slide {
  13. position:relative;
  14. .shaped {
  15. background-size: cover;
  16. shape-outside: polygon(20% 0,100% 0,100% 100%,0% 100%);
  17. clip-path: polygon(20% 0,0% 100%);
  18. background-image: url(http://www.e-architect.co.uk/images/jpgs/aberdeen/bon_accord_centre_tonyfreeman221207_04.jpg);
  19. height: 384px;
  20. float:left;
  21. width: 70%;
  22. float: right;
  23. shape-margin: 20px;
  24. }
  25. .hero-text {
  26. Box-sizing: border-Box;
  27. background-color: #333;
  28. color: white;
  29. padding: 30px;
  30. height: 384px;
  31. width: 50%;
  32. h2 {
  33. margin-bottom: 20px;
  34. }
  35. }
  36. }
  37. }

我尝试过一种Adobe形状的polyfill,它没有任何区别,是否有其他选择,或者我应该考虑完全改变设计?

谢谢

最佳答案
你可以使用svg的clipPath for cross-browser support.

  1. .container {
  2. width: 960px;
  3. margin: 0 auto;
  4. }
  5. section.hero {
  6. padding: 8px;
  7. -moz-Box-sizing: border-Box;
  8. Box-sizing: border-Box;
  9. overflow: hidden;
  10. width: 100%;
  11. height: 400px;
  12. float: left;
  13. }
  14. section.hero section.slide {
  15. position: relative;
  16. }
  17. .shaped {
  18. background: url(http://www.e-architect.co.uk/images/jpgs/aberdeen/bon_accord_centre_tonyfreeman221207_04.jpg);
  19. height: 384px;
  20. width: 100%;
  21. }
  22. section.hero section.slide .hero-text {
  23. -moz-Box-sizing: border-Box;
  24. Box-sizing: border-Box;
  25. background-color: #333;
  26. color: white;
  27. padding: 30px;
  28. height: 384px;
  29. width: 50%;
  30. }
  31. section.hero section.slide .hero-text h2 {
  32. margin-bottom: 20px;
  33. }
  34. svg {
  35. float: right;
  36. }

您可以使用此方法添加曲线而不是直线.

这里有些例子.

  1. .container {
  2. width: 960px;
  3. margin: 0 auto;
  4. }
  5. section.hero {
  6. padding: 8px;
  7. -moz-Box-sizing: border-Box;
  8. Box-sizing: border-Box;
  9. overflow: hidden;
  10. width: 100%;
  11. height: 400px;
  12. float: left;
  13. }
  14. section.hero section.slide {
  15. position: relative;
  16. }
  17. .shaped {
  18. background: url(http://www.e-architect.co.uk/images/jpgs/aberdeen/bon_accord_centre_tonyfreeman221207_04.jpg);
  19. height: 384px;
  20. width: 100%;
  21. }
  22. section.hero section.slide .hero-text {
  23. -moz-Box-sizing: border-Box;
  24. Box-sizing: border-Box;
  25. background-color: #333;
  26. color: white;
  27. padding: 30px;
  28. height: 384px;
  29. width: 50%;
  30. }
  31. section.hero section.slide .hero-text h2 {
  32. margin-bottom: 20px;
  33. }
  34. svg {
  35. float: right;
  36. }
  1. .container {
  2. width: 960px;
  3. margin: 0 auto;
  4. }
  5. section.hero {
  6. padding: 8px;
  7. -moz-Box-sizing: border-Box;
  8. Box-sizing: border-Box;
  9. overflow: hidden;
  10. width: 100%;
  11. height: 400px;
  12. float: left;
  13. }
  14. section.hero section.slide {
  15. position: relative;
  16. }
  17. .shaped {
  18. background: url(http://www.e-architect.co.uk/images/jpgs/aberdeen/bon_accord_centre_tonyfreeman221207_04.jpg);
  19. height: 384px;
  20. width: 100%;
  21. }
  22. section.hero section.slide .hero-text {
  23. -moz-Box-sizing: border-Box;
  24. Box-sizing: border-Box;
  25. background-color: #333;
  26. color: white;
  27. padding: 30px;
  28. height: 384px;
  29. width: 50%;
  30. }
  31. section.hero section.slide .hero-text h2 {
  32. margin-bottom: 20px;
  33. }
  34. svg {
  35. float: right;
  36. }

    猜你在找的HTML相关文章