Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to create two divs like in image. both can have background images. Any one can help?
Two divs http://development.230i.com/tsips_new/v2/images/Untitled.png
There are several ways to do this.
Old School
One way would be to crop the overlaid image so that it has a triangle cut off and replaced by transparency. This would work in any browser that supported .pngs, however, the downside would be that for each image you'd need to create a new crop. A photo-shop batch process or server side image processing job on upload would cover this best, depending on whether you have full control over the images (photoshop) or are dealing with user uploaded images (server side processing)
Masking
By using css masks you could create a mask for the overlaying div that forced transparency through the overlaying div to the div beneath it. You'd want an image where the triangle cut-out is black and the rest transparent. The black area is the area that is retained, while the rest of the div is transparent, revealing the div underneath.
This answer here gives a working example, though the shape is different.
The syntax is pretty simple, you just define a -mask-image with a url that works like a background image. Prefixes are required and support is still a bit limited.
Clip Path
Clip path allows you to clip the overlaying div to let a div underneath show through. You can use this tool to set it up. I've nicked the following css from their output that defines a triangle on the bottom:
-webkit-clip-path: polygon(100% 38%, 42% 100%, 100% 100%);
clip-path: polygon(100% 38%, 42% 100%, 100% 100%);
In this example, the overlaying div is clipped to the triangle shape allowing the white background to show through. Again, support is limited.
More about clip-path and masking.
With all examples
It's possible with all examples to swap the overlaying div to be the triangle or the square with a corner cut off. It makes no difference to the result.
Also, in all cases you'd need to use position to overlay the two divs on top of each other exactly. Like this:
.container {
position: relative;
}
.div1,
.div2 {
position: absolute;
}
Related
I am rather new to CSS, and I was wondering if it is possible to crop an image to make dynamic shapes on my website. Instead of just having a rectangle or square for the photo, I want to be able to cut into it diagonally that matches the color of the sidebar, along with angled text right under. Is it possible for me to dynamically crop the image like this? Or would I have to make use of shapes and overlay them over the image?
An example of a mockup I made, I would like to be able to either crop the image to be slanted like this or overlay a shape to make it look more dynamic.
As #tacoshy mentioned you can use clip-path for creating in place image clipping, a pretty cool tool that can help you with creating complex clipping paths is https://bennettfeely.com/clippy/
Example:
.image-shape {
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
<img class="image-shape" src="https://image.uniqlo.com/UQ/ST3/eu/imagesother/2020/ut/gaming/pc-ut-hero-mario-35.jpg" alt="Mario" />
More info about the clip-path property https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path
This question already has answers here:
Flip vertically a background-image every time it repeat-y
(5 answers)
Closed 6 years ago.
I have an image
If I set this image as a background with window being larger than the image,
I get "broken" background, where each picture stands out. Basically that:
Is there a away to created a continuous background below programmatically, so that the pattern would continue, as the window gets bigger in CSS (just flipping and adding the same image over and over again):
Thank you.
The answer is: You can't. You can not flip a background image using just CSS.
Possible Solutions for you :
Looking at your problem, if you do not want to repeat your image, then set
background-repeat: no-repeat
And you can also set
background-size: cover;
so that the image covers 100% of your container.
And if you want the flipped image at the bottom of your container then edit the existing image in photoshop and use that as the background image.
In CSS I can set multiple background images to appear one after another using the background: attribute, but when these images appear on the page there is no transition and the edge between them looks quite ugly. Is there a way to implement a shadowed border line between two consecutive backgrounds?
e.g.
#main-body{
background: #222222 url(background.jpg), url(background2.jpg);
}
This code will set two images to the background, when one image ends as you scroll down the page the next one immediately begins. There is no visual transition between the two, it's just two images one after another and doesn't look visually appealing.
The best way to handle the situation here is to draw borders on the top and bottom of your image with desired color and desired width. You can use any image editor to do this and this will also make your task simpler.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'd like to know how you would create the effect of the background-image showing under the text.
Here's an example: chevalblanc.com. I imagine two <sections>, the first one has that cut out text background image, the second section has a photo or something in the background.
I noticed they used a png where they "cut out" the letters and used it as background, but how do you create the scrolling effect?
Update: I found out how to do it, actually it's pretty easy. You have to give two background images to your <section>or <div> and you set the image you want to have in the very background "fixed". For Example: .yoursection { width: xx %; height: xx %;
background-image: url(images/backgroundimage.jpg) center center no-repeat fixed, url(images/foregroundimage.jpg) center center no-repeat;
}
Worked fine for me.
An alternative to the CSS 3D transforms would be to use parallax scrolling (an example of which below)
http://prinzhorn.github.io/skrollr/
Basically, with Skrollr you can transform. scale, skew and rotate the heck out of any element, all done in layers and transitioning is smooth. So essentially I would say just find a tutorial about the usage of Skrollr (or just experiment), create your elements, which in this instance would be a background with transparent text, and then another background image beneath the transparent text background element.
This is purely crafted with combination of CSS3 and Jquery. Yes I can see they are using png transparent mask (mask05.png). To answer your question how the scrolling is achieved please read through http://24ways.org/2010/intro-to-css-3d-transforms/
the transparent text you are watching it is not text its a solid image
here is a link for it
http://www.chevalblanc.com/randheli/medias/images/intro/1400/maskintro-en.png
and for scrolling there is a plugin called snapscroll
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
i want to have the gradient as background image like this
how can i achieve that
EDIT:
I want to stretch down to bottom , but if i repeat it then i see the top bar gain , i want that dark portion remain at bottom and central part expands
http://gradients.glrzad.com/
OR
http://www.w3schools.com/css/css_background.asp
If you really-really need to achieve this with background image, here is an example.
Of course it doesn't work everywhere — you need JS polyfill to make browser that don't support background-size property happy. I would recommend jQuery Backstretch for this.
But, what you really want to do (I hope so, at least) is to make it as flexible as possible and thus, you should take a look at this or this CSS gradients tutorial instead of the image. And, of course, you can use one of the CSS gradients generator like:
http://gradients.glrzad.com/
http://www.colorzilla.com/gradient-editor/
http://css3please.com/. This one is useful for CSS3 in general.
I would do it using a div or other element at the top of the page to give you the 'bar' and use a gradient background image, attached to the body in your css, aligned to the bottom and repeated.
body{
background:url(yoururl.png) repeat-x bottom;
}
For the 'bar', use the following CSS for the same style effect...
.topbar{
position:relative;
top:0px;
left:0px;
height:30px; /* or whatever height you want */
}
Apply your colours and borders to the bar however you see fit.