I'm trying to find out if it's possible to replicate this background with CSS.
I thought about using a skew (similar to the example below) but not having much luck so far.
http://jsfiddle.net/EA3RY/
#chevron {
position: relative;
text-align: center;
padding: 12px;
margin-bottom: 6px;
height: 60px;
width: 200px;
}
#chevron:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 51%;
background: #ccc;
-webkit-transform: skew(0deg, 6deg);
-moz-transform: skew(0deg, 6deg);
-ms-transform: skew(0deg, 6deg);
-o-transform: skew(0deg, 6deg);
transform: skew(0deg, 6deg);
}
#chevron:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 50%;
background: #ccc;
-webkit-transform: skew(0deg, -6deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, -6deg);
}
I guess my question #1 is it possible? and #2 is it good practice to use CSS in this situation? Maybe I'm just better off using a background image.
I don't think transform is the right tool for this job; it's a lot of work for the browser to do just to render a shape like that.
Alternative I'd suggest considering:
linear-gradient.
CSS Gradients can do a lot more than just easing from one colour to another. You can draw all kinds of patterns with them. Here's a page with some examples you might want to look at. None of them are exactly what you're looking for, but they do demonstrate some of the things you can do with gradients which you might not have appreciated.
SVG.
Using an SVG image for your background gives you complete flexibility over how it looks. Basically it's an image; it can be anything. But an SVG for an image like this should be pretty light-weight in terms of filesize, and you can include it directly in the CSS code as a data URL. Quick and easy.
I gave it a shot. It looks fine on Chrome and IE, but not in Firefox. Problem is any content you place in the top and bottom parts will appear in the same spot as the middle.
<div class="fancy-up"></div>
<div class="fancy">content in here!</div>
<div class="fancy-down"></div>
c
.fancy {
background-color: #FFA500;
height: 100px;
width: 500px;
}
.fancy-up {
border-right: 500px solid #FFA500;
border-top: 30px solid rgba(0, 0, 0, 0);
height: 0;
width: 0;
}
.fancy-down {
border-bottom: 30px solid rgba(0, 0, 0, 0);
border-right: 500px solid #FFA500;
height: 0;
width: 0;
}
Fiddle
Reference
Related
I created an X button using CSS only. It displays fine in all browsers besides on ie11. In ie11 the button stacks over a border but when it's clicked it moves slightly down to the correct place it's suppose to be. I have no clue on how to fix this and have tried a bunch of different ways. This code is scss btw.
button {
width: 50px;
height: 50px;
right: 15px;
top: 15px;
padding: 0;
position: absolute;
border: none;
background-color: transparent;
&:hover { cursor: pointer; }
&:before, &:after {
content: '';
width: 100%;
height: 2px;
background-color: blue;
display: block;
position: absolute;
}
&:before {
-webkit-transform: rotateZ(45deg);
-moz-transform: rotateZ(45deg);
-ms-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
&:after {
-webkit-transform: rotateZ(-45deg);
-moz-transform: rotateZ(-45deg);
-ms-transform: rotateZ(-45deg);
transform: rotateZ(-45deg);
}
}
}
I would use a media query plus a position property plus an !important (not recommended but we want to be absolutely sure) to forbid the button from moving anywhere if the browser is ie10 or higher. The code I would use would be something like this:
#media all and (-ms-high-contrast: none), (-ms-high-contrast: active) { /*media query for ie10+*/
button {
position:absolute !important;
}
}
Failing that, there is another question here which also mentions jumping elements but that was from ie8. The issue was solved by using display:block.
What version of IE11 are you using? The code runs well in my IE11 which version is 11.116.18362.0. I made a simple demo:
button {
width: 50px;
height: 50px;
right: 15px;
top: 15px;
padding: 0;
position: absolute;
border: none;
background-color: transparent; }
button:hover {
cursor: pointer; }
button:before, button:after {
content: '';
width: 100%;
height: 2px;
background-color: blue;
display: block;
position: absolute; }
button:before {
-webkit-transform: rotateZ(45deg);
-moz-transform: rotateZ(45deg);
-ms-transform: rotateZ(45deg);
transform: rotateZ(45deg); }
button:after {
-webkit-transform: rotateZ(-45deg);
-moz-transform: rotateZ(-45deg);
-ms-transform: rotateZ(-45deg);
transform: rotateZ(-45deg); }
<link rel="stylesheet" type="text/css" href="demo-style.css">
<button></button>
I use your scss to compile it down to css file and then import it into the page. The 'X' won't move in IE11. If you're using older version of IE11, I suggest that you could move to the latest version and try it again.
I am some time trying to make a complicated effect on the image, I made some attempts however not got it. I need this effect only in css without using javascript.
CSS
.container{
width: 500px;
background-color: #0c2f45;
}
.image-container {
background-color: #194c6e;
width: 266px;
}
.image-container img{
width: 250px;
-moz-transform: scaleX(-1);
-o-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter: "FlipH";
}
jsfiddle
You could achieve something like this through a couple of transformed pseudo elements*. By skewing the two pesudos, you can create the triangular effect.
A quick demo would be:
div {
height: 200px;
width: 300px;
background: url(http://lorempixel.com/300/200);
position: relative;
overflow: hidden;
}
div:before,
div:after {
content: "";
position: absolute;
height: 50%;
width: 20%;
background: tomato;
border-left: 10px solid firebrick;
left: 80%;
}
div:before {
top: 0;
transform: skewX(10deg);
}
div:after {
top: 50%;
transform: skewX(-10deg);
}
<div></div>
* this would assume you wish to have a solid colour on the right hand side
I'm not an expert with CSS and I'm gonna be struggled in order to achieve the following shape for my div:
And then I would like to insert text in the center.
How can I obtain this shape ?
Below here, some my attempts:
<div class="triangle-down-white" style="height:400px;">
try
</div>
and css
.triangle-down-white {
width: 100%;
height: 0;
padding-left:50%;
padding-top: 4%;
overflow: hidden;
background: rgba(140, 140, 140, 0.33);
}
.triangle-down-white:before,
.triangle-down-white:after {
content: "";
display: block;
height: 122px;
width: 122px;
margin-left:-1000px;
border-left: 1000px solid transparent;
border-right: 1000px solid transparent;
border-top: 100px solid rgba(140, 140, 140, 0.33);
}
.triangle-down-white:before
{ /* hide arrow tails background */
border-top: 100px solid white;
}
UPDATE
I added the new style chevron but the text appear behind the div. I'm using bootstrap and the html code is the following:
<div class="row">
<div class="col-sm-12" id="chevron">
<p>asdasdasdasasdaasdsadasadsadsasd</p>
</div>
</div>
The rest of the code is completely the standard one for bootstrap.
SOLVED
I added z-index: -1 at the new element.
Taken from this website here is the chevron shape you desire:
#chevron {
position: relative;
text-align: center;
padding: 12px;
margin-bottom: 6px;
height: 60px;
width: 200px;
}
#chevron:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 51%;
background: red;
-webkit-transform: skew(0deg, 6deg);
-moz-transform: skew(0deg, 6deg);
-ms-transform: skew(0deg, 6deg);
-o-transform: skew(0deg, 6deg);
transform: skew(0deg, 6deg);
}
#chevron:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 50%;
background: red;
-webkit-transform: skew(0deg, -6deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, -6deg);
}
p{
position: relative;
z-index: 1;
}
<div id="chevron"><p>Hello</p></div>
The pseudo :before works on Firefox, Safari but not in Chrome.
Its a square box rotated to form a diamond shape. But, using :before the bg is again rotated backwards and given a position fixed. It gives a really nice effect !
Check My Site :
www.wangeltmg.com
When you scroll at first, the background overlaps and creates blurry image to get cleared.. !
All i did is
#element3
{
width: 1000px;
height:1000px;
line-height: 5em;
margin: 0px auto;
border: 0px solid #666;
border-radius: 3px;
margin-top:150px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
position: absolute;
overflow: hidden;
left:0; right:0;
top:10%;
}
#element3:before
{
content: "";
position: absolute;
width: 200%;
height: 200%;
top: -50%;
left: -10%;
z-index: 0;
background: url(../img/custom11.jpg) 0 0 no-repeat fixed;
background-size:135% 135%;
background-position:140px -315px;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
Is there anything to work on regarding the compatibility with Chorme ?
I would love to have your answers fellas.
Thanks.
Your CSS background is behaving bizarre on chrome because you needed to add:
-webkit-transform CSS 3 transform with prefix for Chrome.
.parallax-two #element3 {
border: 0 solid #666666;
border-radius: 3px;
height: 1000px;
left: 0;
line-height: 5em;
margin: 150px auto 0;
overflow: hidden;
position: absolute;
right: 0;
top: 10%;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
width: 1000px;
}
http://fiddle.jshell.net/mmvdz/6
http://fiddle.jshell.net/mmvdz/6/show/
For Firefox, Chrome, Opera, IE etc. it is preferred to add the vendor prefix CSS3 versions as well. It is needed for older versions of Firefox as well for example.
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
If you use editor like Sublime Text to code manually. You have plugins which add this vendor prefix automatically.
http://www.hongkiat.com/blog/css-automatic-vendor-prefix/
I do see that you have another problem on Chrome. The fixed div has issues with z-index. And it seems it has to do with CSS 3 transform properties for webkit which makes the triangle appear above the fixed div but without the blur effect in Chrome.
#home-wrap {
-webkit-backface-visibility: hidden;
}
This question already has answers here:
Responsive CSS Trapezoid Shape
(2 answers)
Closed 3 years ago.
Does anyone know how to achieve skew like this:
Using CSS's new transform property?
As you can see I'm trying to skew both corners, anyone know if this is possible?
.red.box {
background-color: red;
transform: perspective( 600px ) rotateY( 45deg );
}
Then HTML:
<div class="box red"></div>
from http://desandro.github.com/3dtransforms/docs/perspective.html
CSS:
#box {
width: 200px;
height: 200px;
background: black;
position: relative;
-webkit-transition: all 300ms ease-in;
}
#box:hover {
-webkit-transform: rotate(-180deg) scale(0.8);
}
#box:after, #box:before {
display: block;
content: "\0020";
color: transparent;
width: 211px;
height: 45px;
background: white;
position: absolute;
left: 1px;
bottom: -20px;
-webkit-transform: rotate(-12deg);
-moz-transform: rotate(-12deg);
}
#box:before {
bottom: auto;
top: -20px;
-webkit-transform: rotate(12deg);
-moz-transform: rotate(12deg);
}
HTML:
<div id=box></div>
Works in Chrome and FF 4: http://jsfiddle.net/rudiedirkx/349x9/
This might help: http://jsfiddle.net/rudiedirkx/349x9/2880/
And this too (from Erwinus' comment): http://css-tricks.com/examples/ShapesOfCSS/
I think you mean webkit transform.. please check this URL out
http://www.the-art-of-web.com/css/3d-transforms/ it could help you.
You can use -webkit-perspective and -webkit-transform together.
<div style="-webkit-perspective:300;">
<div style="-webkit-transform:rotate3d(0, 1, 0, 30deg);width:200px;height:200px;background:#D73913;"></div>
</div>
This works only in Safari.
Use this css code. Set the numbers according to your need
-webkit-transform: translateX(16em) perspective(600px) rotateY(10deg);
-moz-transform: translateX(16em) perspective(600px) rotateY(10deg);
-ms-transform: translateX(16em) perspective(600px) rotateY(10deg);
-o-transform: translateX(16em) perspective(600px) rotateY(10deg);
transform: translateX(16em) perspective(600px) rotateY(10deg);
Just in case you want, use matrix 3d.
transform:matrix3d(
1,0,1,0.003,
0,1,0,0,
0,0,1,0,
0,0,0,1);
http://codepen.io/Logo/pen/jEMVpo
.size{
width: 200px;
height: 200px;
}
.boxContainer{
-webkit-perspective:100;
}
.box{
background: blue;
-webkit-transform-origin-x:0;
-webkit-transform: rotateY(10deg);
}
<div class="size boxContainer">
<div class="size box">
</div>
</div>
This worked for me.
2 more methods:
As seen on https://css-tricks.com/examples/ShapesOfCSS/#trapezoid you can use border:
#box {
border-left: 200px solid black;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
width: 0;
height: 100px;
}
but it can't have contents, because it's all border.
Example: http://jsfiddle.net/rudiedirkx/349x9/3112/
Use CSS' actual 'skew' transform:
#box {
width: 200px;
height: 170px;
margin-top: 30px;
background-color: black;
transform: skewY(10deg);
position: relative;
z-index: 1; /* doesn't work? */
}
#box:before {
content: "";
display: block;
width: 200px;
height: 80px;
position: absolute;
bottom: -40px;
left: 0;
background-color: black;
transform: skewY(-20deg);
z-index: -1; /* doesn't work? */
}
I can't seem to position the pseudo element behind the main element though, so the pseudo actually falls over the main element's content, if any.
Example: http://jsfiddle.net/rudiedirkx/349x9/3113/