2017-07-27 80 views
2

我想只用CSS创建此背景/边框,但我有一些困难: design original如何在图像周围创建两个边框或框阴影?

我的代码:

.profile-userpic img { 
    width: 80%; 
    background-color: transparent; 
    box-shadow: -10px -10px 0 0px #291026, 10px 10px 0 0px #f00; 
} 
<div class="profile-userpic"> 
    <img src="{% get_avatar_url usuario %}" class="img-responsive " alt=""> 
</div> 

其实我得到这个: my work

我只需要将带有边框的透明对象中的红色背景变形,就像原始设计一样

图片需要有响应,我需要在其他元素(如按钮或div)中使用此“边框/背景”。

回答

1

这里是一个小提琴,应该帮助。 :before,:afterz-index对于这样的事情是有价值的。

CSS

.profile-userpic { 
    position: relative; 
    display: inline-block; 
} 

.profile-userpic:before, 
.profile-userpic:after { 
    z-index: 1; 
    content: ""; 
    position: absolute; 
    display: block; 
    width: 100%; 
    height: 100%; 
} 

.profile-userpic:before { 
    background-color: red; 
    top: -8px; 
    left: -12px; 
} 

.profile-userpic:after { 
    background-color: #fff; 
    border: 1px solid red; 
    bottom: -25px; 
    right: -25px; 
} 

.profile-userpic img { 
    z-index: 2; 
    position: relative; 
} 

https://jsfiddle.net/d6tv5jp3/3/

+0

thxx人,这是完美的! –

1

.ctn { 
 
    width: 400px; 
 
    height: 400px; 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
    
 
} 
 

 
.picture { 
 
    width: 200px; 
 
    height: 200px; 
 
    background-color: purple; 
 
    position: relative; 
 
} 
 

 
.picture:before { 
 
    position: absolute; 
 
    background: red; 
 
    content:''; 
 
    width: 100%; 
 
    height: 108%; 
 
    top:-12px; 
 
    left:-12px; 
 
    z-index: -1; 
 
} 
 

 
.picture:after { 
 
    position: absolute; 
 
    background: transparent; 
 
    border: 2px solid red; 
 
    content:''; 
 
    width: 105%; 
 
    height: 107%; 
 
    top:-6px; 
 
    left:10px; 
 
    z-index: -1; 
 
}
<div class="ctn"> 
 
    
 
    <div class="picture"></div> 
 
    
 
</div>

你有没有考虑过使用:before:after元素代替:

看看这个示例中,我提出:

https://jsfiddle.net/bo2nn6kk/

所有你需要做的是适当的位置和a调整宽度和高度。

+0

@Grasper我的昵称从黑金属吉他手天回:) – Varin

2

这应该让你开始,没有反应,但显示了它可以完成的一种方式。

.profile-userpic img { 
 
    transform:translateY(20px) translateX(30px); 
 
} 
 
.profile-userpic:before { 
 
    content:''; 
 
    display:block; 
 
    width:250px; 
 
    height:280px; 
 
    background:black; 
 
    position:absolute; 
 
    z-index:-1; 
 
} 
 
.profile-userpic:after { 
 
    content:''; 
 
    display:block; 
 
    width:250px; 
 
    height:280px; 
 
    border:1px solid black; 
 
    position:absolute; 
 
    z-index:-1; 
 
    top:22px; 
 
    left:60px; 
 
}
<div class="profile-userpic"> 
 
    <img src="http://placehold.it/250" class="img-responsive " alt=""> 
 
</div>

相关问题