html – 使用CSS合并节标记的边框颜色

前端之家收集整理的这篇文章主要介绍了html – 使用CSS合并节标记的边框颜色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个稍微旋转的中心部分边框.另外,我给这个部分的每一面都有不同的颜色.这是我的基本代码
  1. body{
  2. background-color: #594451;
  3. color: #fff;
  4. }
  5.  
  6. .Boxed{
  7. position: absolute;
  8. margin:auto;
  9. /* border: 3pc solid rgba(255,255,1); */
  10. border-left: solid rgba(127,203,170,1) 3pc;
  11. border-right: solid rgba(186,179,173,1) 3pc;
  12. border-bottom: solid rgba(0,171,238,1) 3pc;
  13. border-top: solid rgba(229,99,57,1) 3pc;
  14. height: 20pc;
  15. width: 20pc;
  16. top: 0;
  17. right: 0;
  18. bottom: 0;
  19. left: 0;
  20. -webkit-transform: rotate(45deg);
  21. -moz-transform: rotate(45deg);
  22. -o-transform: rotate(45deg);
  23. -ms-transform: rotate(45deg);
  24. transform: rotate(45deg);
  25. }
  1. <h1>Welcome to Rahul's Lab</h1>
  2. <section class="Boxed">
  3. <!-- <p>This will contain the Box properly</p> -->
  4. </section>

我可以实现相互重叠的边界吗?是否可以通过使用CSS或我是否必须为此创建单独的部分/ div?
HTML & CSS Design and build websites

参考:封面图片HTML& CSS设计和构建Jon Duckett的网站.

解决方法

边界重叠是不可能的……

…但是,这里只是一个使用CSS创建效果解决方案,使用:

>多个线性渐变来创建背景
> background-blend-mode混合角落中的颜色



更新的代码段:
使用背景速记语法,就像Temani在这里做的那样https://stackoverflow.com/a/50526694/5061000

  1. .Boxed {
  2. position: absolute;
  3. margin: 5pc auto; /* Modified to better fit in tiny snippet */
  4. --border-pc: 10%; /* You could even use a CSS variable to store the width if you want to be able to modify it easily. Or the colors. Or both. */
  5. background:
  6. /* Shorthand Syntax used below: image position/sizeX sizeY */
  7. linear-gradient(rgba(229,099,057,1),rgba(229,1)) top /100% var(--border-pc),/* Orange with CSS var */
  8. linear-gradient(rgba(000,rgba(000,1)) bottom/100% var(--border-pc),/* Blue */
  9. linear-gradient(rgba(127,rgba(127,1)) left /var(--border-pc) 100%,/* Green */
  10. linear-gradient(rgba(186,rgba(186,1)) right /var(--border-pc) 100%; /* Gray */
  11. background-blend-mode: multiply;
  12. background-repeat: no-repeat;
  13. height: 20pc;
  14. width: 20pc;
  15. top: 0;
  16. right: 0;
  17. bottom: 0;
  18. left: 0;
  19. transform: rotate(45deg);
  20. }
  1. <section class="Boxed">
  2. <!-- <p>This will contain the Box properly</p> -->
  3. </section>



旧样式片段:
是的,它有效,但我更喜欢第一个!

  1. .Boxed {
  2. position: absolute;
  3. margin: 5pc auto; /* Modified to better fit in tiny snippet */
  4. --border-pc: 10%; /* You could even use a CSS variable to store the width if you want to be able to modify it easily. Or the colors. Or both. */
  5. /* I tried to indent it to better see the code: */
  6. background-image:
  7. linear-gradient(to top,/* Blue */
  8. rgba(0,1) 0%,rgba(0,1) var(--border-pc),/* example use of the CSS var */
  9. transparent var(--border-pc) ),linear-gradient(to right,/* Green */
  10. rgba(127,1) 10%,transparent 10% ),linear-gradient(to bottom,/* Orange */
  11. rgba(229,linear-gradient(to left,/* Gray */
  12. rgba(186,transparent 10% );
  13. background-blend-mode: multiply; /* Added to mix the colors */
  14. height: 20pc;
  15. width: 20pc;
  16. top: 0;
  17. right: 0;
  18. bottom: 0;
  19. left: 0;
  20. transform: rotate(45deg);
  21. }
  1. <section class="Boxed">
  2. <!-- <p>This will contain the Box properly</p> -->
  3. </section>

(请注意,如果您不使用背景混合模式,您可以通过播放订单来选择哪些渐变与其他渐变重叠!)

希望能帮助到你.

猜你在找的HTML相关文章