简体   繁体   English

如何在CSS中旋转背景?

[英]How to rotate background in CSS?

I want to achieve a skewed/rotated background div with solid color. 我想用纯色实现倾斜/旋转的背景div。

Just like this: 像这样:

http://img59.imageshack.us/img59/367/szabloni.gif

I know there is a trick with rotating your background to create chamfered corners but will it work out here? 我知道旋转背景来创建倒角是有技巧的,但是可以在这里解决吗? Or jQuery will do better? 还是jQuery会做得更好?

Second problem I might have with this is a content layer (marked as red) overlaying the two background div s. 我可能遇到的第二个问题是覆盖两个背景div的内容层(标记为红色)。

Can you help me please? 你能帮我吗?

Thanks in advance, and sorry for any language mistakes. 在此先感谢您,并感谢您的任何语言错误。

You can do this with pseudo elements. 您可以使用伪元素来执行此操作。

http://jsfiddle.net/JDcF3/ http://jsfiddle.net/JDcF3/

I changed the colours to make visible 我改变了颜色使其可见

<div class="foo"></div>

.foo {
    position: relative;
    width: 200px;
    height: 100px;
    background: blue;
}

.foo:after {
    content: '';
    display:block;
    height:100px;
    width: 100px;
   -webkit-transform: skew(30deg, 0deg);
    background: red;
    left: 150px;
    position:absolute;
    z-index: -1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM