我个人是不喜欢换wordpress背景图片,因为图大容易拖慢速度,但是有朋友需要添加背景图片,这里说说添加不透明的背景图和透明的背景图方法。
不透明的背景图
将以下css代码粘贴到主题的header文件"</head>"标签之前。
1 2 3 4 5 6 7 8 9 |
<style type="text/css"> body{ background-size: cover; background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-image: url(背景图片地址); } </style> |
这样的效果就是body上面的元素不会透明,只有body上面没有遮挡的元素背景图才会看得见。
透明的背景图
将以下css代码粘贴到主题的header文件"</head>"标签之前。
1 2 3 4 5 6 7 8 9 10 |
<style type="text/css"> body{ background-size: cover; background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-color: rgba(0, 0, 0, 0.5); background-image: url(图片地址); } </style> |
这样的效果是不管body上面有没有字体,遮挡元素,背景图始终可见。
评论