Irregular Div Distortion only one corner

How do I create a div like this? I read a lot of technique but I couldn't figure it out. There is some text inside the div that shouldn't be distorted.

Every method is welcome, it doesn't have to be pure css.

My HTML structure:

<div class="intro">
                <div class="intro-header">
                    <h1>Headline WOW</h1>
                </div>
                <div class="intro-text">
                    <p>Mieleni minun tekevi, aivoni ajattelevi lähteäni laulamahan, saa'ani sanelemasaa'ani sanelema sanelemasaa'ani sanelema </p>
                </div>
</div>

      

enter image description here

+3


source to share


3 answers


a few malformed pseudo-elements can be used for this:

.first,
.last {
  text-align: center;
  line-height: 80px;
  height: 80px;
  background: green;
  position: relative;
  display: inline-block;
  width: 400px;
  margin-bottom: 20px;
}
.first:after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  height: 50%;
  width: 100%;
  transform: SkewY(2deg);
  transform-origin: bottom left;
  background: inherit;
}
.last:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 50%;
  width: 100%;
  transform: SkewY(2deg);
  transform-origin: bottom right;
  background: inherit;
}
      

<div class="first">FIRST LINE</div>

<div class="last">LAST LINE</div>
      

Run codeHide result





An alternative (perhaps) would be to use a gradient (although this can lead to jagged edges). Solution for Harry

body {
  background: -webkit-linear-gradient(0deg, crimson, indianred, purple);
}
div {
  height: 400px;
  width: 400px;
  background: -webkit-linear-gradient(75deg, lightseagreen 45%, transparent 45%, transparent 55%, lightseagreen 55%);
}
      

<div></div>
      

Run codeHide result


+4


source


You can do this with the border disabled.

As an example:



.top {
  height: 300px;
  background: red;
  position: relative;
  width: 300px
}
.top:before {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  border-bottom: 10px solid white;
  border-right: 300px solid red;
  width: 0;
}
.bottom {
  height: 300px;
  background: red;
  position: relative;
  width: 300px;
  padding-top: 10px;
  margin-top: 0px;
}
.bottom:before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  border-top: 10px solid white;
  border-left: 300px solid red;
  width: 0;
}
      

<div class="top">Text</div>
<div class="bottom">Text</div>
      

Run codeHide result


+4


source


This should do it.

html,body{
  margin:0;
  height:100%;
}
.intro{
  width:400px;
  display:inline-block;
  background:red;
  padding:50px;
}
.intro-header,.intro-text{
  width:100%;
  display:inline-block;
  background:#ccc;
  text-align:center;
  position:relative;
}
.intro-header{
  margin-bottom:50px;
}
.intro-header:after{
  position:absolute;
  left:0;
  content:"";
    width: 0; 
    height: 0; 
    border-left: 400px solid transparent;
    border-top: 20px solid #ccc;  
}
.intro-text:after{
  position:absolute;
  top:-20px;
  left:0;
  content:"";
    width: 0; 
    height: 0; 
    border-right: 400px solid transparent;
    border-bottom: 20px solid #ccc;  
}

      

Example: CodePen

+1


source







All Articles