【问题标题】:Multiple color border around image [closed]图像周围的多种颜色边框[关闭]
【发布时间】:2013-12-19 16:13:41
【问题描述】:

如何在图像周围创建这样的 2 色边框?

像这样:

这是一个 HTML 网站。我应该使用什么 CSS?在此先感谢:)

【问题讨论】:

  • 你在说什么技术?
  • 您必须更具体。这是做网站的吗?如果是的话,你熟悉 css 吗?
  • 这是针对 HTML 网站的。我应该使用哪些 CSS 代码? @simbabque
  • 是的,我对 CSS @JacobGoulden 不太熟悉
  • @JacobGoulden W3Fools.。尽量不要作为参考

标签: css image border


【解决方案1】:

Fiddle Link

CSS

 #mainDiv {
     height: 200px;
     width: 560px;
     position: relative;
     border-bottom: 8px solid #f51c40;
     background: #3beadc;
    border-top: 4px solid yellow;
  }

 #borderLeftbottom  {
   border-left: 8px solid #f51c40;
   position: absolute;
   top: 50%;
   bottom: 0;
 }
#borderRightbottom{
  border-right: 8px solid #f51c40;
   position: absolute;
   top: 50%;
   bottom: 0;
   right:0;
}
#borderLefttop  {
  border-left: 4px solid yellow;
   position: absolute;
   top: 0;
   bottom: 50%;
}
#borderRighttop{
   border-right: 4px solid yellow;
   position: absolute;
   top: 0;
   bottom: 50%;
   right:0;
}

HTML

<div id="mainDiv"><img src="https://www.google.com/images/srpr/logo11w.png" alt="google" />
     <div id="borderLeftbottom"></div>
     <div id="borderRightbottom"></div>
     <div id="borderLefttop"></div>
     <div id="borderRighttop"></div>
</div>

【讨论】:

  • 感谢有用!您可以使用此代码。
  • 是的,这非常有效。非常感谢:)
  • 欢迎...很高兴为您提供帮助。请采纳答案
【解决方案2】:

任何图像的完全可重复使用的解决方案 - 只需将其与类 .multipleBorder 的 div 包装在一起

FIDDLE

1) 将图像包裹在一个 div 中。

2) 给 div 填充:说 12px - 10px 用于外边框,2px 用于内边框

3) 创建伪元素 :before 和 :after div - 每个都有 50% 的高度

4) 为每个伪元素设置边框和背景(背景作为内边框)

5) 移除顶部元素的下边框和底部元素的上边框。

完成!

标记

<div class="multipleBorder">
    <img src="http://placehold.it/600x150" alt="" width="600px" height="150px" />
</div>

CSS

.multipleBorder
{
    position: relative;
    display: inline-block;
    padding: 12px;
}
.multipleBorder:before, .multipleBorder:after
{
    content: '';
    position: absolute;
    top:0;
    left:0;
    width:100%;
    height: 50%;
    border: 10px solid silver;
    border-bottom: none;
    background: maroon;
    z-index: -1;
    -moz-box-sizing: border-box;
    box-sizing: border-box;  
}
.multipleBorder:after
{
    bottom:0;
    top: auto;
    border: 10px solid maroon;
    border-top: none;
    background: silver;
}

【讨论】:

  • 我喜欢使用 :before 和 :after +1
  • 是的,它的美妙之处在于我们在标记中只有 2 个元素!
猜你喜欢
  • 2023-03-07
  • 1970-01-01
  • 2017-08-08
  • 1970-01-01
  • 2011-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-22
相关资源
最近更新 更多