Diagonal edge at the corners of the page

Asked

Viewed 476 times

4

I am studying about diagonal edges and intend to apply an effect like this on my page:

borda diagonal

Until now I found little material about it and the closest was this:

html, body {
  height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  background: tomato;
}

.box {
  position: relative;
  max-width: 700px;
  min-height: 400px;
  margin: auto;
  top: 50%;
  -webkit-transform: translateY(-50%) translateZ(0);
          transform: translateY(-50%) translateZ(0);
  overflow: hidden;
  padding: 20px 20px 0 0;
}
.box:before {
  content: '';
  display: block;
  position: absolute;
  z-index: -1;
  width: 774px;
  height: 500%;
  background-image: linear-gradient(90deg, transparent 50%, white 50%);
  background-size: 8px 10000px;
  -webkit-transform: rotate(45deg) translateY(-50px) translateX(-598px);
          transform: rotate(45deg) translateY(-50px) translateX(-598px);
}

.content {
  position: relative;
  background: white;
  display: block;
  min-height: 380px;
  padding: 2em;
}

.centered {
  position: relative;
  text-align: center;
  font-family: sans-serif;
  font-size: 1rem;
  color: tomato;
  line-height: 1.5;
  max-width: 400px;
  margin: 0 auto;
}
<div class="box">
  <div class="content">
    <div class="centered">
      pseudo isometric diagonal stripe border woop!
    </div>
  </div>
</div>

CODEPEN

But I can’t apply or understand this logic.

  • This has more expensive than a div (or pseudoelement) with lists and other white div inside. It has infinite ways to do what you want, it would be important to [Dit] the post and better specify the context. Probably a [mcve] of what tried would be a good starting point.

  • 1

    I was going to post it as a reply, but as you already have enough: https://codepen.io/anon/pen/Begjya

2 answers

3


There are several ways to do this, I used here two techniques basically, a pseudo-elemento and put in it a repeating-linear-gradient. The main element has white background color, and the stripes are only in the pseudo element with the repeating-linear-gradient in -45deg to get inclined

.box {
    position: relative;
    width: 300px;
    height: 160px;
    background-color: #fff;
    box-sizing: border-box;
    padding: 5px;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}
.box::after {
    content: "";
    position: absolute;
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    top: -10px;
    left: -10px;
    z-index: -1;
    background-image: repeating-linear-gradient(-45deg, black 0px, black 10px, yellow 10px, yellow 20px);
}
<div class="box">
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsa unde enim culpa consectetur ut expedita quia adipisci repudiandae voluptate quisquam architecto, iste totam autem optio ipsam rem accusantium sint magni!
</div>

  • 1

    gave to understand perfectly, thank you!

  • 1

    @Patriquealves I’m glad I helped! If you want to read more about linear gradient here is a didactic link https://www.w3schools.com/css/css3_gradients.asp

3

Create a father and daughter div and put a background linear-gradient with two colors in the father div, and in the daughter div you put a white background. The padding in father div will give the effect that it is an edge:

.pai{
   width: 300px;
   padding: 20px; /* largura da borda */
   background: repeating-linear-gradient(
     -45deg,
     #F3F900,
     #F3F900 10px,
     #000 10px,
     #000 20px
   );
}

.filho{
   padding: 20px;
   background: #fff;
}
<div class="pai">
   <div class="filho">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
   </div>
</div>

You can change the colors and width of the tracks (where you have 10px).

  • 1

    got the logic now, thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.