I have a header image which uses clip-path to make it's lower section angled like so:
CSS:
.angled {
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, 0 96%);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 96%);
}
I then apply this class to any div I want to become angled, which works, however for divs inside that class that contain text, the text does not fit to the newly shaped div. I would like it so the first line- the large title, fits neatly under the angle.
(note that with codepen, the video doesn't clip for some reason- it works fine locally- this isn't a concern)
Here is my codepen
.angled {
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, 0 80%);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 80%);
}
.angled-inverted {
-webkit-clip-path: polygon(0 0, 100% 0, 100% 80%, 0 100%);
clip-path: polygon(0 0, 100% 0, 100% 80%, 0 100%);
}
header {
position: relative;
background-color: black;
height: 75vh;
min-height: 25rem;
width: 100%;
overflow: hidden;
}
header video {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: 0;
-ms-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
header .container {
position: relative;
z-index: 2;
}
header .overlay {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: black;
opacity: 0.5;
z-index: 1;
}
#media (pointer: coarse) and (hover: none) {
header {
background: url('https://source.unsplash.com/XT5OInaElMw/1600x900') black no-repeat center center scroll;
}
header video {
display: none;
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<header>
<div class="overlay angled"></div>
<video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop" class="angled">
<source src="https://storage.googleapis.com/coverr-main/mp4/Mt_Baker.mp4" type="video/mp4">
</video>
<div class="container h-100">
<div class="d-flex h-100 text-center align-items-center">
<div class="w-100 text-white">
<h1 class="display-3">Video Header</h1>
<p class="lead mb-0">With HTML5 Video and Bootstrap 4</p>
</div>
</div>
</div>
</header>
<section class="angled-inverted" style="background-color: grey; padding-top: -1rem; padding-bottom: 15rem;">
<div class="container-fluid" style="padding-left: 4rem">
<div class="row">
<div class="col">
<h1 style="font-size: 45pt">Angled Video Image</h1>
<p style="font-family:evogriaregular">The HTML5 video element uses an mp4 video as a source. Change the source video to add in your own background! The header text is vertically centered using flex utilities that are build into Bootstrap 4.</p>
<p>The overlay color can be changed by changing the <code>background-color</code> of the <code>.overlay</code> class in the CSS.</p>
<p>Set the mobile fallback image in the CSS by changing the background image of the header element within the media query at the bottom of the CSS snippet.</p>
<p>Set the mobile fallback image in the CSS by changing the background image of the header element within the media query at the bottom of the CSS snippet.</p>
<p>Set the mobile fallback image in the CSS by changing the background image of the header element within the media query at the bottom of the CSS snippet.</p>
<p>Set the mobile fallback image in the CSS by changing the background image of the header element within the media query at the bottom of the CSS snippet.</p>
<p>Set the mobile fallback image in the CSS by changing the background image of the header element within the media query at the bottom of the CSS snippet.</p>
</div>
</div>
</div>
</section>
clip path is not supported, is intended for images not for text,
if you set strict font size it can't change by itself,
padding cannot be negative,
unit pt shouldn't be used
and finally you spread css all around - external, inline arguing each other multi sub-layers
Any of the above cause problems.
Related
I'm trying to hide an element as I'm scrolling up in the page. I'm using clip-path and position:fixed to try achieve this. This is what I have so far. The text is hidden as I'm scrolling as intended. Wondering if it would be possible to start clipping it from the top as I'm scrolling vs the bottom as it is working right now.
I want the element to be clipped from the top as I'm scrolling down.
One idea I had was to rotate the text 180 degrees, and then rotate the clipped element back 180 degrees but I'm not too sure if that would work/how to implement it. Since transform creates a containing block I don't know how to get the scrolling to work.
#main-container {
position: relative;
height: 100px;
width: 100vw;
}
#clip-container {
position: absolute;
height: 80px;
width: 100vw;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
overflow: hidden;
background-color: rgba(255, 165, 0, 0.5);
margin-top: 10px;
}
.filler-div {
background-color: blue;
width: 100vw;
height: 100px;
}
#text {
position: fixed;
}
<div class="filler-div"></div>
<div id="main-container">
<div id="clip-container">
<div id="text">
<h1>TEXT GOES HERE</h1>
</div>
</div>
</div>
<div class="filler-div"></div>
Learn any of the javascript libraries below
scrollrevealjs.org
scrollmagic.io
I need to find a solution to keep the cropped image but have content sit inside with an opacity filter on the div. The problem I'm facing is that it wont match the angles and i cant use an overlap hidden, need to find a solution.... can anyone help with this shame you cant use an ::after on image to add filter div to darken a section :(
.promo {
position: relative;
}
.promo img {
-webkit-clip-path: polygon(0 16%, 100% 0, 100% 100%, 0% 84%);
clip-path: polygon(0 16%, 100% 0, 100% 100%, 0% 84%);
}
.promo__content {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 50%;
height: 100% color: #fff;
background: black;
}
<div class="promo">
<img src="https://i.picsum.photos/id/100/600/600.jpg" >
<div class="promo__content">
Content Here
</div>
</div>
Example of what I'm trying to do black box in the angled image the black box will be see through
Apply the clip-path to the whole container and not only the image to get what you want:
.container {
margin:50px 0;
clip-path:polygon(0 16%, 100% 0, 100% 100%, 0% 84%);
display:flex;
}
.box {
width:30%;
padding:80px;
box-sizing:border-box;
background:#000;
color:#fff;
}
.img {
width:70%;
background:url(https://i.picsum.photos/id/1074/1000/1000.jpg) center/cover;
}
<div class="container">
<div class="box">
some text here<br>
some text here<br>
some text here<br>
some text here<br>
some text here<br>
</div>
<div class="img"></div>
</div>
When I updated the octagon's background image, it seems to have stretched it. Before, with the same CSS and a different image, it was normal.
Here is the original photo. As you can see, it is NOT stretched:
Here is the octagon photo that is stretched:
Here is all the code affecting the octagon image:
img[Attributes Style] {
width: 300px;
height: 300px;
}
* {
box-sizing: border-box;
}
.octo {
transform: rotate(45deg);
}
.octo1 {
transform: rotate(-45deg);
}
.octo,
.octo div {
margin: 0 auto;
transform-origin: 50% 50%;
overflow: hidden;
width: 300px;
height: 300px;
}
<div class="octo">
<div class="octo1">
<img src="https://i.stack.imgur.com/5voQJ.jpg" alt="" width="300" height="300" />
</div>
</div>
Instead of using <img>, include the image as a background-image for a <span> element, and use background-size: cover on it. To position the image, adjust the background-position values.
.octo-image {
display: block;
width: 300px;
height: 300px;
background-position: center center;
background-size: cover;
}
* {
box-sizing: border-box;
}
.octo {
transform: rotate(45deg);
}
.octo1 {
transform: rotate(-45deg);
}
.octo, .octo div {
margin: 0 auto;
transform-origin: 50% 50%;
overflow: hidden;
width: 300px;
height: 300px;
}
<div class="octo">
<div class="octo1">
<span class="octo-image" style="background-image: url('https://i.stack.imgur.com/5voQJ.jpg')"></span>
</div>
</div>
Alternatively, you could use <img> with object-fit: cover as well, but then you have to use a polyfill to support IE11 and older:
.octo-image {
width: 300px;
height: 300px;
object-fit: cover;
object-position: center center;
}
* {
box-sizing: border-box;
}
.octo {
transform: rotate(45deg);
}
.octo1 {
transform: rotate(-45deg);
}
.octo, .octo div {
margin: 0 auto;
transform-origin: 50% 50%;
overflow: hidden;
width: 300px;
height: 300px;
}
<div class="octo">
<div class="octo1">
<img class="octo-image" src="https://i.stack.imgur.com/5voQJ.jpg"></span>
</div>
</div>
Use a square source image, not a landscape rectangle. Specifying the height and width of an image force it to be a square. Your image will get squished on the horizontal and stretched on the vertical since it is a landscape image. This has nothing to do with your octagon styling. See my below example:
<img src="https://i.stack.imgur.com/oiEvT.png" height="300" width="300" />
Alternatively, if you can't use a background image you could use the clip-path property to draw the octagon with a cleaner markup and a full-responsive behaviour
Codepen demo
Markup
<figure>
<img src="https://i.stack.imgur.com/5voQJ.jpg" alt=""/>
</figure>
CSS
/*
* The outer wrapper defines the shape and hides the overflow of the
* inner image. The max-width ensures the responsiveness.
*/
figure {
position: relative;
max-width: 300px;
overflow: hidden;
clip-path: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%,
70% 100%, 30% 100%, 0% 70%, 0% 30%);
}
/*
* This pseudoelement ensures to keep the correct aspect ratio
* through the padding-bottom property. Since the image should be
* squared, the padding must be 100% of the element width
*/
figure::before {
content: "";
display: inline-block;
padding-bottom: 100%;
}
/*
* Finally the image must be properly centered (it requires some
* adjustment if the subject it's not aligned in its canvas),
* the height is 100% of its container but the width is not
* specified so the image can scale, keeping its natural
* aspect ratio
*/
img {
position: absolute;
left: 45%;
height: 100%;
transform: translateX(-50%);
}
Final result
I've looked a bit for this, and can't find it on SO. I basically have to put together a design as follows...
I'm using Bootstrap4 and I'm pretty good at CSS, and this is still giving me a bit of an issue. It should be full-screen, but I'd be open to giving it a max-width of 1400px.
My Idea: I currently had the idea of doing an element with the two elements on the side, and then use transform to rotate, and then put another element inside that has the background image and then uses transform to un-rotate it.
Here's my codepen to show what I've tried -
https://codepen.io/Gwapedwink/pen/ZaPvyo?editors=1100
<section>
<div class="image-splitter">
<div class="inner left">
<span style="background-image:url('http://placehold.it/940x240/222222/fff&text=left"></span>
</div>
<div class="inner right">
<span style="background-image:url('http://placehold.it/940x240/b4d455/fff&text=right"></span>
</div>
</div>
</section>
with the CSS of:
.image-splitter {
background-color: #f1f1f1;
position: relative; /* allows for absolute inside */
height: 240px; /* height of this section is 240px */
width: 100%;
overflow: hidden; /* important for this idea */
}
.image-splitter .inner {
position: absolute;
width:1000px;
height: 500px;
top:50%;
transform:translateY(-50%);
-webkit-transform:translateY(-50%);
overflow:hidden;
}
.image-splitter .inner.left {
right: 50%;
transform: rotate(5deg) translateY(-50%);
z-index:10;
}
.image-splitter .inner.right {
left: 50%;
z-index:9;
}
.image-splitter .inner span {
display: block;
position: absolute;
top: 50%;
height:350px;
width: 100%;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
/* background image properties */
background-position: center;
background-size: cover;
}
.image-splitter .inner.left span {
right: -50px;
transform: rotate(-5deg) translateY(-50%);
-webkit-transform: rotate(-5deg) translateY(-50%);
}
.image-splitter .inner.right span {
left: 0;
}
You can see that there are so many issues already, and I want to know if I'm missing something that's available. You can see that the text in the codepen should be level, but it isn't.
Thanks in advance!
I think the vertical misalignment of the texts on the two sides is due to how placehold.it renders the text onto the images, and not related to your code. If you observe the two sample images –"left" and "right"– alone, you will notice that the baseline of the printed texts are already on different heights. Here is an overlay of the two images in question:
This thing happens because of the two strings have different overall heights. So by using texts of similar heights could solve your issue with the placeholder images. I would use square brackets to equalise the height like so: "[left]" and "[right]".
To demonstrate this, I used another approach to achieve your splitted image effect. This one makes use of the clip-path css property, which is not available on IE and Edge, so it might or might not work for you in production. On the other hand, this one simplifies the css big time.
body { margin: 0; }
.image-splitter {
position: relative;
}
.inner {
overflow: hidden;
width: 60%;
height: 240px;
background: transparent no-repeat center center / cover;
}
.right {
position: absolute;
top: 0;
right: 0;
-webkit-clip-path: polygon(calc(16.667% + 50px) 0%, 100% 0%, 100% 100%, 16.667% 100%);
clip-path: polygon(calc(16.667% + 50px) 0%, 100% 0%, 100% 100%, 16.667% 100%);
}
<section>
<div class="image-splitter">
<div class="inner left" style="background-image:url('http://placehold.it/940x240/222222/fff&text=[left]">
</div>
<div class="inner right" style="background-image:url('http://placehold.it/940x240/b4d455/fff&text=[right]">
</div>
</div>
</section>
After recommendations from #dference, it became clear to use clip-path. The issue is of browser compatibility.
So, I took his answer above and then converted it to using SVG - but also had to use foreignObject to allow Edge support.
<div class="image-splitter">
<div class="inner left" style="background-image:url('https://picsum.photos/760/240?image=1067"></div>
<div class="inner right">
<!-- SVG CLIP -->
<svg width="100%" height="240px">
<defs>
<clipPath id="clipPolygon">
<polygon points="0 240,2000 240,2000 0,50 0">
</polygon>
</clipPath>
</defs>
<foreignObject clip-path="url(#clipPolygon)" width="100%" height="100%">
<img src="https://picsum.photos/760/240?image=1049">
</foreignObject>
</svg>
<!-- / SVG CLIP -->
</div> <!-- /.inner.right -->
</div> <!-- /.image-splitter -->
Throw that in with the CSS
/* image splitter */
.image-splitter {
position: relative;
height: 230px;
overflow: hidden;
& .inner {
overflow: hidden;
width: 60%;
height: 240px;
background: transparent no-repeat center center / cover;
}
& .right {
position: absolute;
top: 0;
width:50%;
right: 0;
/*-webkit-clip-path: polygon(calc(16.667% + 50px) 0%, 100% 0%, 100% 100%, 16.667% 100%);
clip-path: polygon(calc(16.667% + 50px) 0%, 100% 0%, 100% 100%, 16.667% 100%);*/
/* Clipping */
-webkit-clip-path: polygon(0px 240px,2000px 240px,2000px 0px,50px 0px);
clip-path: url("#clipPolygon");
& img {
width: 100%;
min-height: 240px;
}
}
}
You can take a look at this at my codepen - and you can also see the neat way that I did the content splitter below also.
I am using bootstrap to create a simple webpage, here I have the photo of the webpage when it's full desktop width
http://imgur.com/a/QcC18
As I like it, it covers the entire page.
But when I resize Chrome to a smaller width, theres some white space at bottom, and I dont know why?
http://imgur.com/a/TuXdH
Whats even worse is that I do developer tools, and see that html only covers my div, so why is there extra space ?
html,
body {
margin: 0;
padding: 0;
overflow-x: hidden;
box-sizing: border-box;
}
/* SECTIONS */
section {
padding-top: 2%;
padding-bottom: 2%;
}
.main {
position: relative;
background-image: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
/* bottom, image */
url(img/background.jpg);
background-size: cover;
padding-bottom: 56.25%;
background-attachment: fixed;
}
.no-padding {
padding: 0;
}
/* HEADINGS */
.welcome-area {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
color: white;
}
.welcome-area h1 {
font-size: 500%;
}
<section class="main">
<div class="welcome-area">
<h1>Hello.</h1>
<div class="row text-center btn-main">
<button type="button" class="btn btn-primary btn-explore">EXPLORE</button>
</div>
<div class="row">
<img src="css/img/face.jpg" alt="face" class="img-responsive img-face">
</div>
</div>
</section>
Please add height: 100% to your css code for html, body and then add height: 100%; box-sizing: border-box; for element section.
Edit: and for the better effect you can remove padding-bottom for .main element.
try adding this to your css:
html, body{
width:100%;
height:100%
}
this stretches the page to fill the whole page in width and heigh