使用以下方法创建这样的边框:之前和:在CSS中的伪元素之后?

前端之家收集整理的这篇文章主要介绍了使用以下方法创建这样的边框:之前和:在CSS中的伪元素之后?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目的

我希望能够在css中创建像this这样的边框,可能使用伪元素然后使用背景图像.

HTML

  1. <div id="footer"></div>

CSS

  1. #footer {
  2. background: #4b4b4b;
  3. color: #868686;
  4. padding: 0;
  5. position: relative;
  6. height: 100px;
  7. width: 900px;
  8. }
  9.  
  10. #footer:before {
  11. content: "";
  12. display: block;
  13. width: 220px;
  14. background-color: #e1e1e1;
  15. height: 8px;
  16. }

解决方法

看下面的代码片段,这是你想要的吗?
  1. body {
  2. background: silver;
  3. padding: 0 10px;
  4. }
  5.  
  6. #content:after {
  7. height: 10px;
  8. display: block;
  9. width: 100px;
  10. background: #808080;
  11. border-right: 1px white;
  12. content: '';
  13. }
  14.  
  15. #footer:before {
  16. display: block;
  17. content: '';
  18. background: silver;
  19. height: 10px;
  20. margin-top: -20px;
  21. margin-left: 101px;
  22. }
  23.  
  24. #content {
  25. background: white;
  26. }
  27.  
  28.  
  29. #footer {
  30. padding-top: 10px;
  31. background: #404040;
  32. }
  33.  
  34. p {
  35. padding: 100px;
  36. text-align: center;
  37. }
  38.  
  39. #footer p {
  40. color: white;
  41. }
  1. <body>
  2. <div id="content"><p>#content</p></div>
  3. <div id="footer"><p>#footer</p></div>
  4. </body>

JSFiddle

猜你在找的CSS相关文章