我怎样才能使背景图片这个样子的 背景图片边框样式通过CSS
-5
A
回答
1
有我的知识做这个的3种方式 -
- 老办法 - 在
:after
使用秩序和:before
.bg-box {
position: relative;
background: url(https://static.pexels.com/photos/20974/pexels-photo.jpg) no-repeat 100%;
width: 500px;
height: 400px;
;
display: inline-block;
}
.bg-box:after,
.bg-box:before {
content: '';
position: absolute;
}
.bg-box:before {
top: 0px;
left: 0px;
border-right: 500px solid rgba(221, 221, 221, 0);
border-top: 60px solid #fff;
}
.bg-box:after {
bottom: 0px;
left: 0px;
border-right: 500px solid #fff;
border-top: 60px solid rgba(243, 245, 246, 0);
}
<div class="bg-box"></div>
- 使用
transform: matrix
到的元素。 - 使用
transform: matrix
到元素的:after
和:before
为最好的结果。
.bg-box-2 {
position: relative;
background: url(https://scontent.fmaa1-1.fna.fbcdn.net/v/t1.0-0/s480x480/10492499_766836143367679_5870385788438363650_n.jpg?oh=8c5e7a0b24c74fea881b7c9c5bbcc246&oe=5A424EF7) no-repeat 100%;
width: 500px;
height: 400px;
;
display: inline-block;
/* IE 9 */
-ms-transform: matrix(1, -0.1, 0, 1, 0, 0) ;
/* Safari */
-webkit-transform: matrix(1, -0.1, 0, 1, 0, 0);
/* Standard syntax */
transform: matrix(1, -0.1, 0, 1, 0, 0)
}
<div class="bg-box-2"></div>
.bg-box-3{
position: relative;
background: url(http://webneel.com/wallpaper/sites/default/files/images/04-2013/island-beach-scenery-wallpaper.preview.jpg) no-repeat 100%;
width: 500px;
height: 400px;
;
display: inline-block;
overflow:hidden;
}
.bg-box-3:after,
.bg-box-3:before {
content: '';
position: absolute;
width:100%;
height:20%;
background:#fff;
}
.bg-box-3:before{
top: -3%;
/* IE 9 */
-ms-transform: matrix(1, -0.1, 0, 1, 0, 0);
/* Safari */
-webkit-transform: matrix(1, -0.1, 0, 1, 0, 0);
/* Standard syntax */
transform: matrix(1, -0.1, 0, 1, 0, 0);
}
.bg-box-3:after{
bottom:-3%;
/* IE 9 */
-ms-transform: matrix(1, -0.1, 0, 1, 0, 0);
/* Safari */
-webkit-transform: matrix(1, -0.1, 0, 1, 0, 0);
/* Standard syntax */
transform: matrix(1, -0.1, 0, 1, 0, 0);
}
<div class="bg-box-3"></div>
您可以使用方法较受欢迎的链接在您的项目。希望这有助于你理解这个窍门。
+1
非常感谢你@weBer – Slan
0
可以实现与倾斜位置由pseudo-elements
帮助这个效果
body {
height: 100%;
background: #fff;
font-family: sans-serif;
}
.image-container {
background: #fff;
position: relative;
z-index: 1;
height: 500px;
max-width: 500px;
margin: 0 auto;
color: #fff;
}
.image-container:before, .image-container:after {
background: #fff;
content: '';
display: block;
height: 30%;
left: 0;
position: absolute;
right: 0;
z-index: -1;
-webkit-backface-visibility: hidden;
}
.image-container:before {
top: 0;
-webkit-transform: skewY(-3deg);
transform: skewY(-3deg);
-webkit-transform-origin: -100% 0;
transform-origin: -100% 0;
}
.image-container:after {
bottom: 0;
-webkit-transform: skewY(-3deg);
transform: skewY(-3deg);
-webkit-transform-origin: 100%;
transform-origin: 100%;
}
.text-content {
position: absolute;
bottom: 30%;
left: 30px;
}
<div class="image-container" style="background: url('http://images.all-free-download.com/images/graphiclarge/beautiful_nature_landscape_02_hd_picture_166206.jpg') no-repeat; background-size: cover">
<div class="text-content">
<h1>Lorem ipsum title</h1>
<p>Dummy contents</p>
</div>
</div>
0
如果你想玩border
s,那么这将帮助你:
#header {
\t background-image: url("http://via.placeholder.com/350x150");
\t height: 150px;
\t width: 350px;
\t position: relative;
}
#header::before {
content: "";
width: 100%;
border-left: 350px solid red;
position: absolute;
box-sizing: border-box;
border-bottom: 65px solid transparent;
}
#header::after {
content: "";
width: 100%;
border-right: 350px solid red;
position: absolute;
box-sizing: border-box;
border-top: 65px solid transparent;
\t right: 0;
\t bottom: 0;
}
<div id="header">
</div>
如果你想知道如何工作,看看这个codepen由克里斯Coyier。
0
对于CSS,你可以使用
#myelement {
background-image: url("image path");
height:x px;
width:y px;
position: relative;
overflow: hidden;
-webkit-transform: rotate(30deg);
transform: rotate(30deg);
}
相关问题
- 1. CSS背景边框样式和位置
- 2. 边框背景图片
- 3. xPages复选框样式背景图片
- 4. 通过css添加背景图片
- 5. CSS - 右边填充的背景图片
- 6. 背景CSS图片
- 7. CSS背景图片
- 8. 通过ID选择器不应用CSS背景图像样式
- 9. 应用边框背景图片
- 10. 围绕CSS背景图像的边框
- 11. ASP.NET主页CSS背景图像边框
- 12. 带有动态背景的CSS中的穿孔样式边框
- 13. 边框半径和背景颜色的IE CSS样式
- 14. 背景图片上的CSS边框(相同的div?)
- 15. 创建叠加边框的CSS背景图片?
- 16. 框内的背景图片HTML,CSS
- 17. CSS背景图像边界
- 18. CSS背景图片和默认背景?
- 19. CSS过滤器背景图片
- 20. 边框背景图片不会跨越整个边框
- 21. 覆盖内嵌样式背景图片
- 22. 隐藏背景图片内嵌样式
- 23. 覆盖背景图像的CSS样式
- 24. CSS/Javascript背景样式
- 25. 使用Scrapy获取CSS样式表上的背景图片
- 26. CSS - 旋转背景图片
- 27. Jekyll CSS背景图片
- 28. CSS中的背景图片
- 29. CSS背景图片错误?
- 30. CSS透明背景图片
https://www.w3schools.com/cssref/css3_pr_border-image.asp –