.container{
max-width: 80%;
margin:auto;
}
.section1{
background: #541A81;
padding: 60px 0;
}
.content{
background:#ffffff;
/* clip-path: polygon(0 90px, 100% 0, 100% 100%, 0 100%); */
border: 7px dashed #FFFD54;
border-radius: 50px;
padding: 168px 60px 92px;
transform: skew(10deg, 0);
}
<div class="section1">
<div class="container">
<div class="content">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit ad hic distinctio laboriosam iste neque quibusdam, adipisci sed magni explicabo nemo delectus nesciunt numquam non ducimus enim voluptatem ipsam! Esse!
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus dolorum unde debitis quos velit repudiandae. Explicabo, veniam, totam? Consectetur eum ab veniam, consequatur nemo, beatae soluta blanditiis quas quos dicta.</p>
</div>
</div>
</div>
I tried skewing it, but it seems to be skewing the whole axis, I have also tried the clip-path approach (code is commented there), however, this clip method is also removing the border as well.
I certainly wouldn't recommend this, however you theoretically could achieve something similar using pseudo elements - albeit it could get a bit messy with the perspective css property to skew in 3D.
Using pseudo elements, you could stop the actual text becoming skewed as you only apply these to the pseudo elements rather than the whole element.
body {
background: #541A81;
}
.wrap,
.light {
perspective: 300px;
}
.light {
position: absolute;
top: 50px;
left: 50px;
display: inline-block;
min-height: 200px;
width: 500px;
border-radius: 30px;
padding: 30px;
}
.light:before,
.light:after {
content: "";
position: absolute;
border-radius: inherit;
}
.light:after {
top: 30px;
left: 10px;
height: calc(100% - 20px);
width: 90%;
background: rgba(0, 0, 0, 0.8);
transform: rotateY(10deg) rotate(5deg);
z-index: -5;
}
.light:before {
top: 0;
left: -50px;
height: 100%;
width: calc(100% + 55px);
background: white;
border: 7px dashed #FFFD54;
box-sizing: border-box;
transform: rotateY(-5deg) rotateX(2deg);
z-index: -2;
}
<div class="wrap">
<div class="light">
hello! This text won't be skewed or messed up.
</div>
</div>
Related
I want to centre the content on my page. I have a button and a paragraph of text on my page.
I'm new to css so I don't know what I should try.
body {
margin: 0 auto;
}
button {
top: 921px;
left: 400px;
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
top: 2639px;
left: 1014px;
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis
necessitatibus sed officiis repellat illo ratione libero recusandae
tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum
officiis exercitationem esse!
</p>
You can use display: flex;
body,
html {
height: 100%;
}
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
p {
text-align: center;
}
button {
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
<div class="container">
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis necessitatibus sed officiis repellat illo ratione libero recusandae tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum officiis exercitationem esse!
</p>
</div>
Used flexbox for that:
body {
margin: 0 auto;
}
.wrapper {
display: flex;
align-items:center;
flex-direction: column;
justify-content: center;
height: 100vh;
}
button {
top: 921px;
left: 400px;
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
top: 2639px;
left: 1014px;
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
<div class="wrapper">
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis
necessitatibus sed officiis repellat illo ratione libero recusandae
tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum
officiis exercitationem esse!
</p>
</div>
You can use flexbox. Take a look at this https://css-tricks.com/snippets/css/a-guide-to-flexbox/.
Here is the solution for your current problem.
html,body, .wrapper {
margin: 0;
height: 100%;
}
.wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
button {
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
<div class="wrapper">
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis necessitatibus sed officiis repellat illo ratione libero recusandae tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum officiis exercitationem esse!
</p>
</div>
You can use flexbox technique as they say in other comments or you can add some lines to you code.
Add to body text-align: center; and add to p.text margin: 0 auto;
Your CSS code will become like that:
body {
margin: 0 auto;
text-align: center;
}
button {
top: 921px;
left: 400px;
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
margin: 0 auto;
top: 2639px;
left: 1014px;
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
See demo here
Just add
text-align: center;
and remember to remove the
text-align: left;
from your p.text
Some things to consider;
You are using top and left rules without giving a position rule value other than static (the default value). In your case you should use position: absolute
Don't use positioning with absolute values, if you don't need to. Absolute values (px unit) are not flexible enough to adjust to window size. Use relative units like % or vw/vh
For your contents to act as a group of elements, you should wrap it with a container element, which you then position accordingly (I used <div class="center"></div>)
I positioned this center container element absolutely using top: 50vh and left: 50vw. 100vh is 100 per cent of the view height, i.e. the inner window height and 100vw is 100 per cent of the view width likewise
This positioning is not enough, because it will position the top left corner of the .center element at the center of the window. We need to have a correction. I use transform: translate(-50%, -50%). This will shift an element 50% of its width to the left and 50% of its height to the top, making it perfectly centered.
There are alternatives like flexbox mentioned in the other posts, but this one is a little bit more straightforward for a beginner like you. Nonetheless it is recommended to learn flexbox. You might want to read A complete guide to flexbox on css-tricks.com
body {
margin: 0 auto;
}
.center {
position: absolute;
top: 50vh;
left: 50vw;
transform: translate(-50%, -50%);
}
button {
width: 180px;
height: 60px;
background: #ff9b52 0% 0% no-repeat padding-box;
border-radius: 30px;
opacity: 1;
}
p.text {
width: 398px;
height: 88px;
text-align: left;
font: Regular 20px/27px Segoe UI;
letter-spacing: 0;
color: #39316c;
opacity: 1;
}
<div class="center">
<button>Click Me</button>
<p class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quis necessitatibus sed officiis repellat illo ratione libero recusandae tempora dolorum excepturi. Velit odio mollitia nam vel, nulla nostrum officiis exercitationem esse!
</p>
</div>
I want to display my website by three parts: header, page and footer. Now I can fixed my header and my footer, but the header shields a part of page and the page dont put down my footer(some content of my page displays behind my footer )
My template code:
<div class="fixed-header">
<...>
</div>
<div class="page">
<...>
</div>
<div class="fixed-footer">
<...>
</div>
My Css is :
.fixed-header {
position: fixed;
top: 0;
left: 0;
z-index: 2;
width: 100% !important;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
color: white;
text-align: center;
}
Anyone knows how to fix this problem?
Add padding on the top and bottom of the .page
.page {
padding-top: x // height of header
padding-bottom: x // height of footer
}
.fixed-header {
position: fixed;
top: 0;
left: 0;
z-index: 2;
background: red;
width: 100% !important;
height: 20px;
}
.fixed-footer {
background: blue;
position: fixed;
left: 0;
bottom: 0;
width: 100%;
color: white;
text-align: center;
height: 20px;
}
.page {
margin: 20px 0;
background: pink;
width: 100px;
}
#media (max-width: 767px) {
.fixed-header, .fixed-footer {
height: 40px;
}
.page {
margin: 40px 0;
}
}
<div class="fixed-header">
<...>
</div>
<div class="page">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi odio, est rerum quod nisi ipsam laboriosam quam eius doloremque exercitationem. Laboriosam aut consequatur atque natus beatae explicabo sunt. Quam, labore.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eligendi odio, est rerum quod nisi ipsam laboriosam quam eius doloremque exercitationem. Laboriosam aut consequatur atque natus beatae explicabo sunt. Quam, labore.
</div>
<div class="fixed-footer">
<...>
</div>
I'm facing the following issue with my angled top and bottom div. It should be something like on the picture which I'm providing here. I want to use before pseudo element for the top part of the div and after for the bottom part of the div and the bottom is kinda working but I have only problem with the top.
Any ideas how I can accomplish that effect using my code?
I want it to look like this:
Here's what I have so far:
.example {
width: 100%;
height: 700px;
position: relative;
background: red;
}
.example:after {
content: "";
width: 100%;
height: 100%;
position: absolute;
background: inherit;
z-index: -1;
bottom: 0;
transform-origin: left bottom;
transform: skewY(-10deg);
}
.example:before {
content: "";
width: 100%;
height: 100%;
position: absolute;
background: inherit;
z-index: -1;
top: 0;
transform-origin: top left;
transform: skewY(5deg);
}
<div class="example">
<h1>SOME CONTENT</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit eius excepturi at voluptates, est enim amet. Architecto eaque est assumenda, placeat ipsam repellendus atque nihil dolores, eos, commodi, provident sunt. Lorem ipsum dolor sit amet, consectetur
adipisicing elit. In dicta ut corrupti beatae maiores, officiis saepe omnis voluptatem facilis eveniet ex voluptate, ipsam libero! Recusandae ipsam, provident quam enim rem!</p>
<h2>More Content</h2>
</div>
View on JSFiddle
The issue you are having is due to the position:absolute setting of the pseudo-elements (before/after). When you set the position to absolute the element no longer has any container boundaries to conform to and is positioned based on the html body left,right,top and bottom values.
Now your main container example div's position starts from the top and your after pseudo element needs to be a bit above it to show the angled background but as the pseudo element is not a block element to actually move the main div down due to it's position:absolute setting. You need to add top margin to move the main div down so that the pseudo element set above it is shown.
Here is another way of doing it using css border properties instead of css3 transform property.
https://codepen.io/Nasir_T/pen/GNKLNQ
Hope this explains you the reason of using margins to adjust absolute positioned pseudo-elements.
I added a 150px of margin to the top of you div
EDIT I also changed the skew degree to -5% and 5% rather than +-10%
.example {
width: 100%;
h height: 700px;
position: relative;
background: red;
margin-top: 150px;
}
.example:after {
content: "";
width: 100%;
height: 100%;
position: absolute;
background: inherit;
z-index: -1;
bottom: 0;
transform-origin: left bottom;
transform: skewY(-5deg);
}
.example:before {
content: "";
width: 100%;
height: 100%;
position: absolute;
background: inherit;
z-index: -1;
top: 0;
transform-origin: top left;
transform: skewY(5deg);
}
I think it'd be easiest to skew white divs in :before and :after and then use z-index to bring your content to the front like so. Also added a margin-top to h1 which can be adjusted as needed.
.example {
width: 100%;
height: 700px;
position: relative;
background: red;
overflow: hidden;
}
.example:after {
content: "";
width: 110%;
height: 25%;
top: 0;
position: absolute;
background: white;
z-index: 1;
transform-origin: left bottom;
transform: skewY(-5deg);
}
.example:before {
content: "";
width: 110%;
height: 25%;
bottom: 0;
position: absolute;
background: white;
z-index: 1;
transform-origin: left bottom;
transform: skewY(5deg);
}
.example h1, .example p {
position: relative;
z-index: 5;
}
.example h1 {
margin-top: 205px;
}
<div class="example">
<h1>SOME CONTENT</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit eius excepturi at voluptates, est enim amet. Architecto eaque est assumenda, placeat ipsam repellendus atque nihil dolores, eos, commodi, provident sunt. Lorem ipsum dolor sit amet, consectetur adipisicing elit. In dicta ut corrupti beatae maiores, officiis saepe omnis voluptatem facilis eveniet ex voluptate, ipsam libero! Recusandae ipsam, provident quam enim rem!</p>
<h2>More Content</h2>
</div>
IF there's a static width, the effect is a LOT easier to create & control using borders:
.example {
width: 500px;
height: 700px;
position: relative;
background: red;
padding:100px 0px;
}
.example:after,
.example:before {
content:'';
position:absolute;
border-right:solid 500px transparent;
}
.example:before {
top:0px;
border-top:solid 100px #FFF;
}
.example:after {
bottom:0px;
border-bottom:solid 100px #FFF;
}
<div class="example">
<h1>SOME CONTENT</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit eius excepturi at voluptates, est enim amet. Architecto eaque est assumenda, placeat ipsam repellendus atque nihil dolores, eos, commodi, provident sunt. Lorem ipsum dolor sit amet, consectetur
adipisicing elit. In dicta ut corrupti beatae maiores, officiis saepe omnis voluptatem facilis eveniet ex voluptate, ipsam libero! Recusandae ipsam, provident quam enim rem!</p>
<h2>More Content</h2>
</div>
I need to create the following shape on the image. Where is the photo there will variable content as a slider. What I tried so far is create it with border-width, but the problem is that I'm not able to put the small triangle under photo because of the bigger triangle.
What I've done you can find here on live demo. Maybe I have to use other approaches? Does someone how to solve it?
.header {
float: left;
width: 100%;
background: red;
padding-top: 50px;
padding-bottom: 200px; }
.content {
float: left;
width: 100%;
background: blue;
padding: 50px 0; }
.shape {
position: relative;
float: left;
width: 100%; }
.shape--1:before {
border-top-color: yellow;
border-right-color: transparent;
border-left-color: transparent;
border-bottom-color: transparent;
border-style: solid;
border-width: 160px 330px 0 0;
content: " ";
height: 0;
position: absolute;
top: -130px;
width: 0;
z-index: 30; }
.shape--2:before {
background: transparent;
border-bottom-color: transparent;
border-left-color: blue;
border-right-color: transparent;
border-style: solid;
border-top-color: transparent;
border-width: 130px 0 0 100vw;
content: " ";
height: 0;
position: absolute;
top: -130px;
width: 0;
z-index: 20; }
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam accusamus, quis labore sapiente et ab at! Repudiandae commodi nam quod? - There will be slider with different background, same color should be also in the shape.
</div>
<div class="shape">
<div class="shape--1"></div>
<div class="shape--2"></div>
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente eos maiores repellendus doloribus dignissimos iusto neque accusantium itaque. Aspernatur, cupiditate ab debitis placeat ad harum, nobis, iste deserunt impedit quaerat dicta nemo accusamus velit mollitia quis quos numquam labore distinctio eveniet. Consequatur culpa dicta harum quo quia similique, numquam tempore.
</div>
What I did is first create the element that holds the photo, then I created a rectangular shape in the body background color, rotated it and made it overflown. Then inside of it I placed another rectangular block that I rotated in the opposite way of the original triangle:
HTML:
<div class="photo"></div>
<div class="triangle"></div>
CSS:
body {
background: #fff;
overflow:hidden;
padding: 0;
margin: 0;
}
.photo {
width: 100%;
height: 200px;
background: red;
}
.triangle {
position: absolute;
background: #fff;
left: -100px;
right: -100px;
height: 300px;
transform: rotate(5deg);
transform-origin: 100% 100%;
overflow: hidden;
}
.triangle:after {
content: "";
display: block;
width: 400px;
height: 200px;
position: absolute;
background: orange;
left: 0;
top: -180px;
transform: rotate(-20deg)
}
And here is a working fiddle:
https://jsfiddle.net/62o7wqom/2/
Edit: Added overflow:hidden to the body tag to avoid having a horizontal scrollbar because of the absolutely positioned element...overflowing the body.
The easiest way of doing it would be setting a background-color on a containing div and use clip-path on the actual image. That would give you the effect you're looking for.
If you don't want the triangle to move with the slider you can either create another wrapper div or just create a pseudo after-element and position it on top of the image.
you may use some Pythagore stuff to calculate more precisely angles and sizes, but the idea is here.
.shape {
width: 100%;
height: 5em;
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 0, 25% 0, 0 100%);
}
.header {
text-align: center;
font-variant: small-caps;
font-size: 2em;
}
<div class=header>
<div class=shape style="background-image: url('http://backgrounds.mysitemyway.com/wp-content/uploads/2009/03/bamboo-001126-asparagus-fern-green.jpg')"></div>
awesome header
</div>
<div class=content>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente eos maiores repellendus doloribus dignissimos iusto neque accusantium itaque. Aspernatur, cupiditate ab debitis placeat ad harum, nobis, iste deserunt impedit quaerat dicta nemo accusamus velit mollitia quis quos numquam labore distinctio eveniet. Consequatur culpa dicta harum quo quia similique, numquam tempore.
</div>
One posibility using an inner element to contain the image.
This element is rotated, and inside a pseudo there is the image, counter-rotated.
.test {
font-size: 30px;
width: 400px;
height: 200px;
border: solid blue 1px;
background-size: 200px 200px;
background-repeat: no-repeat;
position: relative;
}
.inner {
position: absolute;
width: 140%;
height: 140%;
bottom: 0px;
right: 0px;
z-index: -1;
transform: rotate(26.4deg);
transform-origin: right bottom;
overflow: hidden;
}
.inner:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background-image: url(http://lorempixel.com/800/400);
background-size: cover;
transform: rotate(-26.4deg);
transform-origin: right bottom;
}
.triangle {
position: absolute;
width: 200px;
height: 200px;
top: 0px;
left: 0px;
background-image: linear-gradient(to right bottom, red 50%, transparent 50%);
z-index: -2;
}
<div class="test">Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..
<div class="inner"></div>
<div class="triangle"></div>
</div>
Here I made a jsfiddle take a look just with your answer I made some css changes. Hope it helps.
.shape-1{
width: 0;
height: 0;
border-top: 0 solid transparent;
border-bottom: 160px solid transparent;
border-left: 0vw solid green;
border-right: 97vw solid green;
position:relative;
top: -130px;
}
.shape-2{
width: 0;
height: 0;
border-top: 0 solid transparent;
border-bottom: 130px solid transparent;
border-left: 42vw solid yellow;
border-right: 0vw solid yellow;
position:relative;
top:0px;
}
.header{
position: absolute;
z-index: 1;
}
<div class="shape">
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsam
accusamus, quis labore sapiente et ab at! Repudiandae commodi nam quod?
</div>
<div class="shape-2"></div>
<div class="shape-1"></div>
</div>
I noticed that you have already accepted an answer, but I figured I would still post some code that could help. This would require some fine tuning given what else you may have going on in your project, but it could get the job done.
.LeftT {
position: absolute;
top: 0rem;
left: 0rem;
border-left: 30rem solid #02A698;
border-right: 6rem solid transparent;
border-bottom: 8rem solid transparent;
border-top: 0rem solid transparent;
}
.RightT {
position: absolute;
top: 0rem;
left: -5rem;
border-top: 0rem solid #004F49;
border-left: 0rem solid transparent;
border-bottom: 8rem solid transparent;
border-right: 45rem solid #004F49;
}
p{
position: absolute;
top: 0rem;
left: 15rem;
z-index: 1;
}
<div class="LeftT"></div>
<div class="RightT"></div>
<p style="color:white;text-align:right;padding-right:1rem;font-size:1.1rem;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in turpis velit.
</p>
I would like to create a div which has auto height based on the length of the text inside it (the text should be in the parent element so that it has 100% width. But also there should be 3 divs in the background each taking 1/3rd of the parent width and being 100% of the parent height.
This is an example of what I expect.
Any ideas how to create this?
I usually don't post questions like this one. But I just got stuck on how to do that and I needed help
You can use Flexbox for this
.content {
display: flex;
position: relative;
}
h1 {
text-transform: uppercase;
font-size: 45px;
margin: 0;
font-family: sans-serif;
word-spacing: 15px;
}
.divs {
position: absolute;
z-index: -1;
width: 100%;
top: 0;
left: 0;
height: 100%;
display: flex;
}
.el {
flex: 1;
border: 3px solid lightgreen;
}
.el:nth-child(1) {background: #DBEBD4;}
.el:nth-child(2) {background: #CEE2F4;}
.el:nth-child(3) {background: #D9D2EA;}
<div class="content">
<h1>Lorem ipsum dolor sit.</h1>
<div class="divs">
<div class="el"></div>
<div class="el"></div>
<div class="el"></div>
</div>
</div>
Have a container div absolutely positioned under the text and then have three child divs inside that.
The reason for the container div is that it avoids having to position each child separately.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.parent {
position: relative;
}
.underlay {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
display: flex;
border: 1px solid grey;
}
.child {
flex:1;
border:1px solid red;
background: rgba(255,0,255,0.25);
z-index:-1;
}
<div class="parent">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta sunt natus architecto deserunt eligendi repellat corporis doloribus fugit ipsam fugiat, eius vitae, magni? Quasi consequatur voluptatem eius excepturi eum qui dolores placeat maxime corporis
laborum hic, magnam ipsa voluptatibus doloremque. Dignissimos dolorum corporis sunt amet unde repellat, dolor consectetur earum.</p>
<div class="underlay">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
</div>