I want to reproduce my mockup : http://imgur.com/ZsR88fe
But I don't know how to skew my background image, only at the bottom. For nom I try the transform skew but all the image is skewed and The top of the page look ugly :
http://imgur.com/TkUgppW
What can I do to fix it ?
Thanks in advance
Skewed or Slanted div, hero or landing pages could be made quickly using the clip-path CSS property with polygon function.
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); //This makes a complete square
The skew could be made reducing the percentage in each angle.
Here's how to make skew on any components.
.skew {
height: 50vh;
width: 100%;
clip-path: polygon(0px 0px, 100% 0px, 100% 80%, 0px 100%);
background:#0a3;
}
<div class="skew">
<h1> Hey there </h1>
</div>
To make a bottom skew for your image with CSS, you're gonna need a few wrappers:
Content div for all the text
Image wrapper that will create the skew and hide the skewed area
Image div that contains nothing but the hero picture
Then you need to apply the opposite skew to the image div to make it not distorted. After that you have to mess around with positioning to ensure that as much of the image is visible and the top skew is hidden. Maybe there's a more clever solution, I just use hardcoded pixel values.
Here's the demo, and here's the important bits:
HTML
<div class="hero">
<div class="bg-img-wrapper">
<div class="bg-img"></div>
</div>
<div class="hero-content">
<h1>Cool company slogan</h1>
<p>Catchy subslogan</p>
</div>
</div>
SCSS (you can just replace the variables and it will be valid CSS, but they help with readability here)
$skewDeg: 5deg;
$offset: 70px;
.hero {
height: 100vh; // Make the hero area take 100% height
overflow: hidden; // Child's skew will cause overflow, so we hide it here
position: relative; // Children will be positioned absolutely relative to this
}
.bg-img-wrapper {
transform: skewY($skewDeg);
position: absolute;
top: -$offset; // Move the top skew offscreen
bottom: $offset; // Move the skewed area up a bit so more of it is visible
right: 0;
left: 0;
overflow: hidden; // Hide the areas that we skewed away
}
.bg-img {
background: url('https://unsplash.it/1280/720/?random') center no-repeat;
background-size: cover;
position: absolute;
top: $offset; // Move the image down by the amount of the parent that's being rendered offscreen
bottom: -$offset;
right: 0;
left: 0;
transform: skewY(-$skewDeg); // Skew the opposite amount of the parent to make the image straight again
}
.hero-content {
position: relative; // Relative positioning here makes the hero content visible
}
Related
I am working on a promo site with angular 7,
the designer gave me 2 background pictures that complete each other, 1 of them is a real footage with a highlighted part (already in the photo) that should be aligned with the other background.
1) What i should do in order to align between the two and make them responsive.
also should i use img tag or background css.
2) What is the better approach for this kind of issues (should i ask the designer to give me the full background with all elements?)
The last thing i tried is using the img tag which was fine until i added some text with z-index to be on top of the image. i used position: absolute and position:relative in order to insert the elements on top of the background but that scramble everything.
Here is the html:
<div class="main-page-container">
<div class="join-company-container">
<img src="assets/img/photo-bg.jpg" class="responsive" alt="Standing">
<app-join-company class="app-join-company"></app-join-company>
</div>
<div>
<img src="assets/img/rectangle-fill-left.svg" class="responsive-image-left" alt="Smiley face">
</div>
</div>
Here is the css:
.main-page-container {
height: auto;
}
.responsive {
width: 100%;
height: auto;
z-index: -1;
position: absolute;
}
.responsive-image-left {
width: 29.2%;
height: auto;
z-index: -1;
}
.app-join-company {
position:relative;
z-index:1;
}
** app-join-company - is the component that has the text + other elements on top of the first background.
Please note that you don't have any class app-join-company . Only a component called like that (you only have class join-company-app ). I am guessing there is the text. But the text is not actually positioned relative due to the typo.
Also you don't use the class responsive-image-right anywhere.
In adition to this z-index only works on positioned elements(position: absolute, position: relative, position: fixed, or position: sticky). So it won't work for .responsive-image-right or .responsive-image-left.
Inside the body, pass the urls of the background images separated by commas, set the size of each image in the background-size property (separated by commas). Position the background images as needed using the background-position property by setting the top/bottom and left/right for each image (the first value sets the position of the first image and so on).
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background-position:
top 16vh left -9vw,
top 77vh left 24vw,
top -30vh right -10vh,
top 91vh right 8vw,
bottom -126vh left 0em
;
background-size: 30%, 20%, 56%, 25%, 100%;
background-repeat: no-repeat;
background-image:
url('/assets/images/img1.svg'),
url('/assets/images/img2.svg'),
url('/assets/images/img3.svg'),
url('/assets/images/img4.svg'),
url('/assets/images/img5.svg')
;
}
I have a background picture with size: cover, I also have a part of this image cut out, made lighter and positioned on top of other divs.
The structure is the following
(grey - background, purple - part of this background cut out and positioned on top, pink - menu which is partly(!) covered by that image so I can interact with it)
The problem is that I want cover image to always match with its background when resizing browser window
I set up top and left manually to match background but it still doesn't when height/width ratio changes
<section class="main">
<div class="container">
<div class="content">
Main page content
</div>
<side-container></side-container>
</div>
<img class="cover-image" src="../../assets/img/img-shoes#2x.png" alt="sneakers">
</section>
SASS:
.main
background-color: black
background-image: url('../../assets/img/bg.png')
background-size: cover
background-repeat: no-repeat
overflow: hidden
.cover-image
position: absolute
z-index: 30
width: 31vw
height: auto
left: 4.5vw
top: 15vh
bottom: 0
right: 0
margin: auto
I couldn't figure the problem out due to lack of a demo link or an online version to see what's happening.
but I think this is going to work for you:
.cover-image
position: absolute
z-index: 30
width: 31vw
height: auto
top: 50%
left: 50%
transform: translate( -50%, -50% )
margin: auto
It uses transform to change the position of that <img> according to its width and height, not parent's.
Example to best describe question:
I have an image, lets call it background (blue in example). In this example the image is
2000px wide / 1000px high
has width: 100% set and will rescale with the browser window.
I also have another image, let's call it green. It's a square which is
200px x 200px (width is 10% of the size of the background).
What I want to achieve is that I want green to rescale and reposition accordingly and fully cover the pink target position of the background, regardless of current viewport width (in other words: it should be "responsive").
The rescaling part is easy, as it's just to set the width to 10%. The positioning is a harder nut to crack. The following code is as far as I get. As I'm using position: absolute I'm removing the element from it's natural flow and top: 40% will be 40% of 0 and the green square will stay at the top.
Same example code is available as a CodePen for easier editing: http://codepen.io/emiloberg/pen/vGdNaX?editors=1100#
Is this simply not possible with pure CSS? If not, one possible workaround could be to use the image element of a svg.
.wrapper {
position: relative;
}
.bg {
position: absolute;
width: 100%;
}
.green {
position: absolute;
width: 10%;
left: 60%;
top: 40%; /* This isn't working */
}
<div class="wrapper">
<img class="bg" src="https://dl.dropboxusercontent.com/u/3378286/solayout/bg.png">
<img class="green" src="https://dl.dropboxusercontent.com/u/3378286/solayout/green.png">
</div>
(I had a hard time finding a suitable title for this question. Feel free to edit it)
Explanation: http://www.w3schools.com/css/css_positioning.asp
CSS:
.bg {
position: relative;
width: 100%;
}
The setup of my problem is simple: I want a background image on an element to be positioned with its left edge halfway between left and right side of its container. So like
HTML
<div class="image-on-right" id="this-dude">
<div class="text-holder">
<p>His arms spaghetti, knees weak, palms spaghetti. There's spaghetti on his sweater already, mom's spaghetti. He's nervous, but on the surface he looks calm spaghetti.
</div>
</div>
CSS
.image-on-right { background-repeat: no-repeat; background-position-x: 50%; background-size: contain; }
.image-on-right > .text-holder { width: 50%; }
#this-dude { background-image: url(http://i.ytimg.com/vi/mEPV2I6dgRM/hqdefault.jpg); }
(https://jsfiddle.net/e78xbuna/)
except there the background image has its center at the 50% mark, not it's left side at the 50% mark. So if there existed a property I could apply like background-position-translate: translateX(-50%); that would be what I'm looking for.
Here is one way of realizing this layout.
First, using a background image will not work (unless you specify a with for the image, which is probably too restrictive).
If I were doing it, I would use absolute positioning to place the image to the right of .text-holder.
You can do this by specifying position: relative to .image-on-right, the parent block, and then position: absolute to .img-holder, with offsets top: 0 and bottom: 0 to match the height of the text in .text-holder, and then left: 50% to get the left edge of the image where it is needed.
I applied width: 50%, but this is not strictly needed.
Finally, to get the image to scale to the height of the absolute positioned container, use height: 100%, and the width will adjust accordingly.
This may not look elegant, but it works. Alternatively, you could place the image as a background image for the .img-holder element, but the net result is the same and you still the .img-holder element.
Note: I assumed that you did not want the text to overlap the image, otherwise, the background image technique would have worked (approximately).
.image-on-right {
outline: 1px dotted blue;
position: relative;
}
.image-on-right > .text-holder {
width: 50%;
}
.image-on-right .img-holder {
position: absolute;
left: 50%;
top: 0;
bottom: 0;
width: 50%;
}
img {
height: 100%;
}
p {
margin: 0;
}
<div class="image-on-right">
<div class="text-holder">
<p>His arms spaghetti, knees weak, palms spaghetti. There's spaghetti on his sweater already, mom's spaghetti. He's nervous, but on the surface he looks calm spaghetti.</p>
</div>
<div class="img-holder"><img src="http://i.ytimg.com/vi/mEPV2I6dgRM/hqdefault.jpg"></div>
</div>
Is there a CSS way to stop a repeating background image at a specific position?
HTML:
<div class="container bgimage">
This is the content
</div>
CSS:
.container
{
height:100%;
}
.bgimage
{
background-image:url('bg.png');
background-repeat:repeat;
}
I want to repeat the image horizontally and vertically at position 0 and stop repeating when the repeating image is reaching vertical height: 400px, like a max-height but only for the background and without shrinking the .container DIV.
I know how this can be done with gradient backgrounds, but is there also a solution for repeating image backgrounds when the .container DIV is even higher than 400px?
Example CSS Gradient:
linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, #FFFFFF 400px) repeat fixed 0 0 rgba(255, 255, 255, 0)
...
Now I want to do the same with an image, and stop it at 400px.
hope it will help you
.youclass:after{
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:url(path/image.png) repeat-y;
}
demo
Although I don't know if what you're asking for is possible, I have a solution that may work for what you need.
What you can do is create a div outside of your container div that will serve as your 400px high repeated background.
HTML:
<div class="tile-background"></div>
<div class="container">
Hello, Luigi.
</div>
CSS:
.container {
z-index: 0; /* MAKES the container appear on top of other elements */
position: absolute; /* REQUIRED for z-index */
}
.tile-background {
/* REQUIRED FOR Z-INDEX ... positions the div in reference to the window */
position: absolute;
top: 0px; /* positions div's top at the top edge of the window */
left: 0px; /* positions div's left side at the left edge of the window */
width: 100%;
height: 400px;
background-image: url(bg.png);
background-repeat: repeat;
}
Here is a preview of the the code does:
http://jsfiddle.net/Ember_Hawk/WP5Zu/1/
Essentially, you create a div that appears behind all other elements and does not affect their positioning.
If you need the background to start where the container div starts with respect to its position on the y-axis, you just change the "top" attribute of the "tile-background" class.
If you have an element with dynamically changing height that lies above your container, then this really wouldn't work without some help.
Hope I helped! Good luck! =)