IvanIvanov
IvanIvanov

Reputation: 63

How to add a border to a pseudo-element: before?

Good afternoon, tell me please. I made up a block with a protruding corner on top of the block. On the whole block I have a corner that I made using box-shadow. How can I make exactly such a frame for a pseudo-element (.comment_text:before)

enter image description here

.comment{
  margin-top: 20px;
  padding: 0px 20px 0px 20px;
}
.comment_text{
  max-width: 680px;
  background-color: #f1fbff;
  padding: 10px;
  margin-top: 15px;
  color: #FFF;
  position: relative;
  font-size: 12px;
  line-height: 20px;
  -webkit-box-shadow: 0px 0px 0px 1.5px #cfcfcf;
  -moz-box-shadow: 0px 0px 0px 1.5px #cfcfcf;
  box-shadow: 0px 0px 0px 1.5px #cfcfcf;
  color: #333333;
  font-size: 12pt;
  font-family: Arial, sans-serif;
}
.comment_text:before {
  content: "";
  display: block;
  border-bottom: 15px solid #f2fbff;
  border-right: 20px solid transparent;
  border-left: 0px solid transparent; 
  position: absolute;
  top: -15px;
  left: 22px;
}
<div v-for='comment in comments' class="comment">
  <div class="comment_text">Some Text</div>
</div>

Upvotes: 0

Views: 1390

Answers (3)

Akash Singh
Akash Singh

Reputation: 137

.comment{
margin-top: 20px;
padding: 0px 20px 0px 20px;
}
.comment_text{
max-width: 680px;
background-color: #f1fbff;
padding: 10px;
margin-top: 15px;
color: #FFF;
position: relative;
font-size: 12px;
line-height: 20px;
-webkit-box-shadow: 0px 0px 0px 1.5px #cfcfcf;
-moz-box-shadow: 0px 0px 0px 1.5px #cfcfcf;
box-shadow: 0px 0px 0px 1.5px #cfcfcf;
color: #333333;
font-size: 12pt;
font-family: Arial, sans-serif;
}
.comment_text:before {
content: "";
display: block;
border-bottom: 15px solid #f2fbff;
border-right: 20px solid transparent;
border-left: 0px solid transparent; 
position: absolute;
top: -15px;
left: 22px;
box-shadow: -2px 0px 0px -0.5px #cfcfcf;  
}    
.comment_text:after {
content: "";
display: block;
width: 23px;
height: 0px;
top: -8px;
left: 20px;
box-shadow: 0px 0px 0px 1px #cfcfcf;
transform: rotate(35deg);
position: absolute;
}

Take A Look

Upvotes: 0

Md Junaid Alam
Md Junaid Alam

Reputation: 1359

You can create another psudo element (::after) and make it litter bigger. Add the color similar to your Div border.

    .comment{
    margin-top: 20px;
    padding: 0px 20px 0px 20px;
  }
  .comment_text{
    max-width: 680px;
    background-color: #f1fbff;
    padding: 10px;
    margin-top: 15px;
    color: #FFF;
    position: relative;
    font-size: 12px;
    line-height: 20px;
    -webkit-box-shadow: 0px 0px 0px 1.5px #cfcfcf;
    -moz-box-shadow: 0px 0px 0px 1.5px #cfcfcf;
    box-shadow: 0px 0px 0px 1.5px #cfcfcf;
    color: #333333;
    font-size: 12pt;
    font-family: Arial, sans-serif;
  }
  .comment_text:before {
    content: "";
    display: block;
    border-bottom: 15px solid #cfcfcf;
    border-right: 20px solid transparent;
    border-left: 0px solid transparent; 
    position: absolute;
    top: -15px;
    left: 22px;
  }
  .comment_text:after {
    content: "";
    display: block;
    border-bottom: 18px solid #f2fbff;
    border-right: 20px solid transparent;
    border-left: 0px solid transparent; 
    position: absolute;
    top: -12px;
    left: 24px;
  }
<div v-for='comment in comments' class="comment">
      <div class="comment_text">{{ comment.text }}</div>
    </div>

Upvotes: 3

Yorbj&#246;rn
Yorbj&#246;rn

Reputation: 456

Try adding Height and Width to it. and play with it until you have the desired effect. You can also add a background to define what color you want it in

  .comment_text:before {
    content: "";
    display: block;
    border-bottom: 15px solid #f2fbff;
    border-right: 20px solid transparent;
    border-left: 15px solid transparent; 
    position: absolute;
    top: -15px;
    left: 2px;
    height: 1px;
    width: 10px;
    background: blue;
  }

Upvotes: 0

Related Questions