Suppose I've the background like this:
And the normal repeated background look like this:
Now I want the inversely repeated of background-image should look like this:
And even if possible again repeat inversely like this:
Anyway the third option is unnecessary coz we can make like that by taking repeated image
Try this type of image so u get cross related look like you mentioned on last picture
I don't think there is a proper way with css.
The easiest might be for you to edit your picture like this:
and repeat it then.
It is possible to add multiple background to one div. However there is no background transform property, thus not support the multiple backgrounds.
I'm not sure if this would work for you, but you can use :after psuedo-class for this:
div
{
width: 400px;
height: 200px;
background: url('http://placehold.it/400x200');
background-repeat: no-repeat;
position: relative;
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
}
div:after
{
content: '';
display: block;
position: absolute;
width: 400px;
height: 200px;
background: url('http://placehold.it/400x200');
background-repeat: no-repeat;
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
top: -200px;
}
Where the second background is re-inverted and the first background inverted. Of course you can edit this to your wishes.
jsFiddle 2 backgrounds
Where you can even do this with 3 backgrounds
jsFiddle 3 backgrounds
I hope you can work with this!
it is posible to flip the image once with CSS, However css3 does not support(afaik) doing alternating repeated background image.
You will have to use the second image that you posted as the background. This conatins the whole pattern that you want repeated.
For Firefox only you could use -moz-element
<div class="repeated-background"></div>
<div id="mybackground">
<img src="myimage.png" />
<img src="myimage.png" class="vflip" />
</div>
css:
.repeated-background {
background: -moz-element(#mybackground) repeat;
}
.vflip {
-moz-transform: scaleY(-1);
-o-transform: scaleY(-1);
-webkit-transform: scaleY(-1);
transform: scaleY(-1);
}
But that's not really a sane way to approach things :)
Related
I have jquery adding a class to scale a div in certain circumstances:
$("#wrapper").addClass("doubleDiv");
The css:
.doubleDiv{ transform: scale(2); }
#wrapper { height:100%; position:relative; z-index:2; background-color:#111; max-width:320px; min-height:480px; margin:0px auto; }
It doubles the size fine, but the div's content gets shifted up past the top of the browser, so that roughly the top third is hidden, and you cannot scroll further up.
I removed each of the styles in #wrapper one by one, until none were left. Apart from screwing up the layout, the same thing happens when the scale is carried out.
To eliminate the chance of any of my jquery causing it, I coded
alert('stop1');
$("#wrapper").addClass("doubleDiv");
alert('stop2');
The display problem occurs before 'stop2' is displayed.
What else could cause this?
Cheers
Demo
you need to add transform-origin
css
.doubleDiv {
transform: scale(2);
transform-origin:50% 0%;
-ms-transform-origin:50% 0%;/* IE 9 */
-webkit-transform-origin:50% 0%; /* Chrome, Safari, Opera */
}
Transform scale scales the object in place. Use transform-origin to define from where you want to scale. Because scaling does not affect positioning at all and the default scaling point is center centre, it moves off screen. Check the follow code to see how it solves this problem:
<html>
<head>
<style type="text/css">
#div {
-webkit-transform: scale(2,2);
-webkit-transform-origin: top left;
background: red;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="div"></div>
</body>
</html>
I made a page consisting of several sections with different background colors and a transparent background image with noise (transparent "PNG file"). At the top of each section I placed a triangular shaped div with the color of the section above. I would also like to add the noise image to the triangles but I can't figure out how.
I've tried the border-image attribute in "CSS" but that just erases the whole triangular shape for some reason..
I would be grateful if you could help me out. "This" is the site I'm working on.
You can use a rotated pseudo element :
Generic solution:
FIDDLE
HTML:
<div></div>
CSS:
div {
width:200px;
height:200px;
overflow:hidden;
}
div:before {
content:"";
display:block;
width:70%;
height:70%;
background-image: url(/*Path to your image*/);
transform: rotate(-45deg);
transform-origin:0 0;
-ms-transform: rotate(-45deg);
-ms-transform-origin:0 0;
-webkit-transform: rotate(-45deg);
-webkit-transform-origin:0 0;
}
EDIT: Your use case
In your use case, you can consider just rotating .arrow-down by 45deg and set overflow:hidden; on the sections. (you also need to remove the existing borders on .arrow-down and give it desired dimensions)
I am trying to create a box with a jagged edge, that can actually be used as a HTML element should be, and can resize etc.
Finally got my head around border-image, got it looking nice, and then when I rotate it, it gets a gap between the border-image and the main fill:
I googled it, and found an answer on SO telling someone to set
-webkit-backface-visibility: hidden;
This cleared it up, but obviously only in webkit browsers.
I tried using -moz-backface-visibility as well, but it didn't clear the issue up in Firefox.
Any suggestions?
jsFiddle
e: I actually thought I may be able to fix it by setting a background color, and then setting the background-clip to padding-box, but honestly it just left me in the same position.
One trick that fixes the problem both in Webkit and FF is setting perspective (instead of backface visibility)
.box.one {
-webkit-transform: perspective(999px) rotate(1deg);
-moz-transform: rotate(1deg);
-ms-transform: rotate(1deg);
-o-transform: rotate(1deg);
transform: perspective(999px) rotate(1deg);
}
fiddle
Adding an after pseudo class with negative margin seems to fix the Firefox issue.
.rough:after {
content: "";
display: block;
margin: -1px;
height: 302px;
background: black;
}
Fiddle demo: http://jsfiddle.net/Wkk7W/3/
Note that the display:block seems to be an essential part of my hack/fix.
Update: Depending on your plans for content inside the div, that exact example might not suit. However, I think the concept could be tweaked depending on your requirements - e.g. using a 3px wide black border instead of a background fill, and using position:absolute to allow other text to be layered on top of the box.
Gonna answer myself, because this solution actually covers my needs of it being "as a html element should be, and can resize etc", even though I developed this solution from Grants answer.
http://jsfiddle.net/Wkk7W/6/
Set the element to position:absolute, then give it a pseudo element with:
content: "";
display: block;
position: absolute;
top: 0;
width: 102%;
margin: -1px 0 0 -1%;
height: 102%;
background: black;
z-index: -1;
This way it keeps the elements width and height, z-index: -1 to put it behind the text. It might not require the display:block, i didn't check.
There are still a few tiny gaps but they are basically impossible to cover and I am happy with it the way it is.
Hi I have two columns of content within a container, the first column has text and the second is a span with a background sprite image. The problem is when I get to smaller screen resolutions, I want the background sprite image to have a width in percentage to be able to scale it along with the H5 with a percentage width, is there a way to do this?
h5{
float:left;
display:block;
width:800px;
}
.sprite{
background-image: url("assets/img/website_sprite_a.png");
background-position: -60px -60px;
float:left;
display:block;
width:64px;
}
<div class="container">
<h5>Title
</h5>
<span class="sprite">
</span>
</div>
In your case I would go with a single background-image, but in the case you will have a lot of images or you really want to do this you can use the background-size property.
From MDN:
The background-size CSS property specifies the size of the background images. The size of the image can be fully constrained or only partially in order to preserve its intrinsic ratio.
.sprite{
background-image: url("assets/img/website_sprite_a.png");
background-position: -30% -30%; //use % instead pixels
float:left;
display:block;
width:64px;
background-size: 100%; //play with this
}
You also should read this:
Scaling background images
I have played a little bit with this on JSFIddle. Resize the browser to see the effect.
nearly a year too late, but I was trying to figure out the same and wasn't able to come up with or find a direct answer. After a little fooling around with multiple pieces of advice, I figured it out. Haven't had a chance to test this on IE8 yet, and stopped bothering with IE6/7, so please bear that in mind.
The trick I found is to use a combination of background-position (using percentages—of the sprite image—as mentioned before), padding-top (again, using percentages—this is the percentage of the total width of the sprite image), and background-size: cover.
Play around with it at jsfiddle.
#wrapper {
position: relative;
width: 100%;
}
.div {
position: absolute;
top: 0;
left: 0;
background-image: url('http://upload.wikimedia.org/wikipedia/en/2/2e/Sprite_logo.jpg');
background-repeat: no-repeat;
background-position: 0% 0%;
background-size: cover;
padding: 50% 0 0 0;
width: 40%;
}
<div id="wrapper">
<div class="div"></div>
</div>
I am working on a website on which we have use parallax effect. In that there are some images which are triangle shaped, like this
& the image is transparent because it overlaps the above DIV. I am trying so many things with css. but didn't get the desired result. I achieve that desired result with fixed width. Check this http://jsfiddle.net/eJ7Sf/2/ but does not work with fluid width. Check what i still try but didn't work
http://jsfiddle.net/ceGGN/3/
http://jsfiddle.net/eJ7Sf/1/
NOTE: i know about css3 MASK property but it's not work in firefox previous browsers. I want the capability till firefox 3.6.13
Updated Answer (Pure CSS3)
Extreme requirements sometimes need extreme solutions. I've built upon my original answer (below) to make a pure css solution that works (and can be made to work better, if you want to invest the time in it). The current example is a bit "choppy" in rendering, which may be okay for you, but if not, you will need to extend the already obscene number of #media queries that are driving it (it would likely be much easier to implement using LESS or SASS; I put together a formula driven excel spreadsheet to help rapidly generate the numbers). It uses this code:
HTML
<div class="box">
<img src="yourImage.jpg" />
</div>
CSS
.box{
height:300px;
min-width: 100px; /*could be different, but you ought to have some min*/
overflow:hidden;
}
.box img {
height: 100%;
width: 100%;
-ms-transform-origin: 100% 100%; /* IE 9 */
-webkit-transform-origin: 100% 100%; /* Safari and Chrome */
-moz-transform-origin: 100% 100%; /* Firefox */
-o-transform-origin: 100% 100%; /* Opera */
transform-origin: 100% 100%;
}
/*Sample... you need alot of these--my fiddle example has 51*/
#media screen and (min-width: 100px) {
.box {
-ms-transform:skewY(45deg);
-moz-transform:skewY(45deg);
-webkit-transform:skewY(45deg);
-o-transform:skewY(45deg);
transform:skewY(45deg);
}
.box img {
-ms-transform:skewY(-90deg);
-moz-transform:skewY(-90deg);
-webkit-transform:skewY(-90deg);
-o-transform:skewY(-90deg);
transform:skewY(-90deg);
}
}
Here's how to calculate the degrees
Assuming height: 300px with the narrow side approximately 100px tall and equal angles on the trapezoid. This means the upper and lower offset is (300px - 100px) / 2 = 100px. Then the .box angles are set off the #media query min-width amounts according to this formula:
Angle = arctan(100/min-width) /*100 is the upper/lower offset as above*/
For the .box img angle take the Angle and multiply by -2. So that will yield your .box and .box img media queries and transforms as this pseudocode:
#media screen and (min-width: [your target min-width]) {
.box {transform: skewY(Angle)}
.box img {transform: skewY(-2*Angle)}
}
How smooth it functions depends completely upon how micro scale you make your changes to min-width to get a new angle setting. As I stated in my comment in the CSS code above, my example uses 51 media query calls and still has some choppiness to it.
Would it be better to use some javascript solution instead... probably, but that is totally up to the designer, so I offer this here as purely a proof of concept that it can be made to work with pure css.
Original Answer
This seems to be achieving a fluid width. I don't know how much control you want of either how much or what part of the image is being shown, so it may not entirely fit your needs, but it does make a flexible width image using transforms to give it a fake perspective look.
With SVG clip-path
You can achieve this shape with an inline SVG and the clipPath element :
<svg viewbox="0 0 10 6.7">
<defs>
<clipPath id="clip">
<polygon points="10 0, 10 6.7, 0 4.7, 0 2" />
</clipPath>
</defs>
<image xlink:href="http://i.imgur.com/RECDV24.jpg" x="0" y="0" height="6.7" width="10" clip-path="url(#clip)"/>
</svg>
With CSS clip-path
You can also achieve this shape with the CSS clip-path property. Browser support is pretty low (see canIuse) but it is an easy approach.
Here is an example :
img{
-webkit-clip-path:polygon(0% 20%, 100% 0%,100% 100%,0% 80%);
clip-path:polygon(0% 20%, 100% 0%,100% 100%,0% 80%);
}
<img src="http://i.imgur.com/5NK0H1e.jpg" alt=""/>
If you play a bit with pseudoelements and 2DTransforms (supported since Firefox 3.5) you can achieve this effect : http://jsfiddle.net/fcalderan/T5KPA/1/
I tried on Chrome and Firefox. For Opera and IE9 you need to add proprietary prefixes.
Markup is really essential:
<figure class="triangle">
<img src="http://cssglobe.com/lab/angled/img.jpg">
</figure>
and the css to obtain this effect:
img { display: block; }
.triangle {
position : relative;
overflow : hidden;
padding : 0; margin: 0;
display : inline-block;
}
.triangle:after,
.triangle:before {
content : "";
position : absolute;
z-index : 2;
left : -50%;
width : 200%;
height : 40%;
display : block;
background : #fff;
}
.triangle:before {
top: -24%;
-webkit-transform: rotate(-10deg);
-moz-transform: rotate(-10deg);
transform: rotate(-10deg);
}
.triangle:after {
bottom: -24%;
-webkit-transform: rotate(10deg);
-moz-transform: rotate(10deg);
transform: rotate(10deg);
}
I coloured the rotated pseudoelements using white but, of course, you can change the color so it fits the real background color