[英]How to rotate button element background but not the button itself
I am trying to rotate the background-image inside of my button but I seem to only be getting the background color I specify, not the background-image over the top. 我正在尝试旋转按钮内部的背景图像,但似乎只获得指定的背景颜色,而不是顶部的背景图像。 I have a transparent part of the photo to create an arch-like look on the button. 我有照片的透明部分,可以在按钮上创建类似拱形的外观。 Here is my css: 这是我的CSS:
#sign-in-button > div > button.btn.btn-default {
color: #fff;
background-color: #da1a32;
position: relative;
overflow: hidden;'
/* background-image: url('/images/arch-red-flip.png'); */
/* background-repeat: no-repeat; */
/* background-size: cover; */
}
#sign-in-button > div > button.btn.btn-default:before {
content: "";
position: absolute;
z-index: -1;
background-size: cover;
transform: rotate(30deg);
background-image: url('/images/arch-red-flip.png') 0 0 no-repeat;
}
<div class="col-sm-12">
<div class="col-sm-6" id="right-border">
<div class="row" id="sign-in-button">
<div class="col-xs-3"></div>
<div class="col-xs-4"></div>
<div class="col-xs-5">
<button type="button" class="btn btn-default">SIGN IN</button>
</div>
</div>
</div>
</div>
It's because you are using the background
shorthand notation on background-image
property. 这是因为您在background-image
属性上使用了background
速记符号。
button.btn.btn-default { color: #fff; background-color: #da1a32; position: relative; overflow: hidden; padding: 3em; } button.btn.btn-default::before { content: ""; position: absolute; height: 100%; width: 100%; top: 0; left: 0; transform: rotate(30deg); background: url(https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded) 0 0 no-repeat; background-size: contain; }
<button type="button" class="btn btn-default">SIGN IN</button>
Note however that the image will be on top of the text and using z-index:-1
will cause the pseudo-element to be placed under the button...I would recommend an internal span to solve this. 但是请注意,图像将位于文本的顶部,使用z-index:-1
会将伪元素放置在按钮下方 ...我建议使用内部跨度来解决此问题。
button.btn.btn-default { color: #fff; background-color: #da1a32; position: relative; overflow: hidden; padding: 3em; } button.btn.btn-default span { position: relative; } button.btn.btn-default::before { content: ""; position: absolute; height: 100%; width: 100%; top: 0; left: 0; transform: rotate(30deg); background: url(https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded) 0 0 no-repeat; background-size: contain; }
<button type="button" class="btn btn-default"><span>SIGN IN</span></button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.