如何使用CSS翻轉任何背景圖片?可能嗎?如何使用CSS翻轉背景圖片?
currenty我在CSS
使用該箭頭圖像中的一個li
background-image
:visited
我需要水平翻轉這個箭頭。我能做到這一點,使箭頭但的另一個形象,我只是好奇,想知道是否有可能在翻轉的CSS圖像:visited
如何使用CSS翻轉任何背景圖片?可能嗎?如何使用CSS翻轉背景圖片?
currenty我在CSS
使用該箭頭圖像中的一個li
background-image
:visited
我需要水平翻轉這個箭頭。我能做到這一點,使箭頭但的另一個形象,我只是好奇,想知道是否有可能在翻轉的CSS圖像:visited
我發現我的方式只看到一個線索翻轉亞歷克斯的答案後,只翻轉背景不是整個元素。感謝亞歷克斯你的答案
HTML
<div class="prev"><a href="">Previous</a></div>
<div class="next"><a href="">Next</a></div>
CSS
.next a, .prev a {width:200px;background:#fff}
.next {float:left}
.prev {float:right}
.prev a:before,
.next a:before {
content:"";
width:16px;
height:16px;
margin:0 5px 0 0;
background:url(http://i.stack.imgur.com/ah0iN.png) no-repeat 0 0; display:inline-block
}
.next a:before {
margin:0 0 0 5px;
transform:scaleX(-1);
}
這工作奇蹟!很酷。謝謝 – AshBrad 2012-03-23 16:56:52
@Jitendra你能否檢查Jsfiddle網址。我認爲它沒有相同的代碼,你發佈在你的答案+它不工作.. – sachinjain024 2013-04-03 14:45:19
你的帖子jsfiddle代碼是文本文件?這是你想要的,還是隻是背景圖片? – mandza 2014-09-11 13:00:21
你可以用CSS水平翻轉...
a:visited {
-moz-transform: scaleX(-1);
-o-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter: "FlipH";
}
如果要垂直翻轉而不是...
a:visited {
-moz-transform: scaleY(-1);
-o-transform: scaleY(-1);
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
filter: FlipV;
-ms-filter: "FlipV";
}
如果我只考慮Web-kit瀏覽器,那麼只有'-webkit-transform:scaleX(-1);'就夠了? – 2011-04-24 06:32:18
@Jitendra它應該是,加上非供應商的前綴屬性。 – alex 2011-04-24 06:34:21
@alex - 這是一個問題。它翻轉''內的文字,我只想翻轉背景圖像。你給的代碼是翻轉整個元素 – 2011-04-24 06:41:39
對於什麼是值得例如,對於基於Gecko的瀏覽器,你不能調節這個東西由於導致隱私泄漏,因此關閉了:visited
。見http://hacks.mozilla.org/2010/03/privacy-related-changes-coming-to-css-vistited/
感謝您的信息+1 – 2011-04-24 15:22:12
感謝您的信息 – K6t 2012-07-03 12:02:18
據W3Schools的:在Internet Explorer 10,火狐和Opera支持 http://www.w3schools.com/cssref/css3_pr_transform.asp
變換屬性。 Internet Explorer 9支持另一種-ms-transform屬性(僅限2D變換)。 Safari和Chrome支持替代方案-webkit-transform屬性(3D和2D轉換)。 Opera僅支持2D變換。
這是一個2D轉換,所以它應該可以在Chrome,Firefox,Opera,Safari和IE9 +上使用供應商前綴。
使用的其他答案:在停止翻轉內部內容之前。我用這對我的頁腳(垂直鏡從我的頭圖像):
HTML:
<footer>
<p><a href="page">Footer Link</a></p>
<p>© 2014 Company</p>
</footer>
CSS:
footer {
background:url(/img/headerbg.png) repeat-x 0 0;
/* flip background vertically */
-webkit-transform:scaleY(-1);
-moz-transform:scaleY(-1);
-ms-transform:scaleY(-1);
-o-transform:scaleY(-1);
transform:scaleY(-1);
}
/* undo the vertical flip for all child elements */
footer * {
-webkit-transform:scaleY(-1);
-moz-transform:scaleY(-1);
-ms-transform:scaleY(-1);
-o-transform:scaleY(-1);
transform:scaleY(-1);
}
所以,你最終翻轉的元素,然後再 - 翻轉所有的孩子。也適用於嵌套元素。
感謝您的回答!這對我來說效果最好,因爲其他人要麼翻轉所有的孩子,要麼需要更復雜的技巧來扭轉翻轉。 – Salgat 2015-11-22 20:06:45
您可以在同一時間
-moz-transform: scaleX(-1) scaleY(-1);
-o-transform: scaleX(-1) scaleY(-1);
-webkit-transform: scaleX(-1) scaleY(-1);
transform: scaleX(-1) scaleY(-1);
並與過渡財產翻轉垂直和水平你可以得到一個涼爽翻轉
-webkit-transition: transform .4s ease-out 0ms;
-moz-transition: transform .4s ease-out 0ms;
-o-transition: transform .4s ease-out 0ms;
transition: transform .4s ease-out 0ms;
transition-property: transform;
transition-duration: .4s;
transition-timing-function: ease-out;
transition-delay: 0ms;
其實它翻轉全元素,而不僅僅是background-image
摘要:SNIPPET
function flip(){
\t var myDiv = document.getElementById('myDiv');
\t if (myDiv.className == 'myFlipedDiv'){
\t \t myDiv.className = '';
\t }else{
\t \t myDiv.className = 'myFlipedDiv';
\t }
}
#myDiv{
display:inline-block;
width:200px;
height:20px;
padding:90px;
background-color:red;
text-align:center;
-webkit-transition:transform .4s ease-out 0ms;
-moz-transition:transform .4s ease-out 0ms;
-o-transition:transform .4s ease-out 0ms;
transition:transform .4s ease-out 0ms;
transition-property:transform;
transition-duration:.4s;
transition-timing-function:ease-out;
transition-delay:0ms;
}
.myFlipedDiv{
-moz-transform:scaleX(-1) scaleY(-1);
-o-transform:scaleX(-1) scaleY(-1);
-webkit-transform:scaleX(-1) scaleY(-1);
transform:scaleX(-1) scaleY(-1);
}
<div id="myDiv">Some content here</div>
<button onclick="flip()">Click to flip</button>
「同時翻轉垂直和水平」的效果與將圖像旋轉180度的效果相同,效果很好,正是我所尋找的, – Stonecrusher 2016-04-21 12:53:20
很好的問題!這可以在許多不同的情況下派上用場。 – AshBrad 2012-03-23 16:57:30
@AshBrad - 感謝您的評論。是的,它可能在許多條件下有用 – 2012-03-24 06:05:06