I want to attach ears to messages, like in Whatsapp, how to do it using css?
CodePudding user response:
https://codepen.io/ezenith/pen/pJLypJ
Look at this
This is the first request from Google
@import url(https://fonts.googleapis.com/css?family=Open Sans:300,400);
.container {
width: 400px;
padding: 10px;
}
.message-blue {
position: relative;
margin-left: 20px;
margin-bottom: 10px;
padding: 10px;
background-color: #A8DDFD;
width: 200px;
height: 50px;
text-align: left;
font: 400 .9em 'Open Sans', sans-serif;
border: 1px solid #97C6E3;
border-radius: 10px;
}
.message-orange {
position: relative;
margin-bottom: 10px;
margin-left: calc(100% - 240px);
padding: 10px;
background-color: #f8e896;
width: 200px;
height: 50px;
text-align: left;
font: 400 .9em 'Open Sans', sans-serif;
border: 1px solid #dfd087;
border-radius: 10px;
}
.message-content {
padding: 0;
margin: 0;
}
.message-timestamp-right {
position: absolute;
font-size: .85em;
font-weight: 300;
bottom: 5px;
right: 5px;
}
.message-timestamp-left {
position: absolute;
font-size: .85em;
font-weight: 300;
bottom: 5px;
left: 5px;
}
.message-blue:after {
content: '';
position: absolute;
width: 0;
height: 0;
border-top: 15px solid #A8DDFD;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
top: 0;
left: -15px;
}
.message-blue:before {
content: '';
position: absolute;
width: 0;
height: 0;
border-top: 17px solid #97C6E3;
border-left: 16px solid transparent;
border-right: 16px solid transparent;
top: -1px;
left: -17px;
}
.message-orange:after {
content: '';
position: absolute;
width: 0;
height: 0;
border-bottom: 15px solid #f8e896;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
bottom: 0;
right: -15px;
}
.message-orange:before {
content: '';
position: absolute;
width: 0;
height: 0;
border-bottom: 17px solid #dfd087;
border-left: 16px solid transparent;
border-right: 16px solid transparent;
bottom: -1px;
right: -17px;
}
<div class="container">
<div class="message-blue">
<p class="message-content">This is an awesome message!</p>
<div class="message-timestamp-left">SMS 13:37</div>
</div>
<div class="message-orange">
<p class="message-content">I agree that your message is awesome!</p>
<div class="message-timestamp-right">SMS 13:37</div>
</div>
<div class="message-blue">
<p class="message-content">Thanks!</p>
<div class="message-timestamp-left">SMS 13:37</div>
</div>
</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
You can achieve this using Pseudo-element
.message{
margin: 30px;
font-family: arial;
background: red;
display: inline-block;
padding: 5px 20px;
color: #fff;
border-radius: 7px;
position: relative;
}
.message:before {
content: "";
border-bottom: 16px solid transparent;
border-right: 15px solid red;
border-top: 0px solid transparent;
position: absolute;
left: -10px;
top: 0px;
}
<div class="message">hello</div>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
.container {
clear: both;
position: relative;
}
.container .arrow {
width: 14px;
height: 20px;
overflow: hidden;
position: relative;
float: left;
top: -7px;
right: -4px;
transform: rotate(26deg);
}
.container .arrow .outer {
width: 0;
height: 0;
border-right: 20px solid #000000;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
position: absolute;
top: 0;
left: 0;
}
.container .arrow .inner {
width: 0;
height: 0;
border-right: 20px solid #ffffff;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
position: absolute;
top: 0;
left: 2px;
}
.container .message-body {
float: left;
width: 300px;
height: auto;
border: 1px solid #CCC;
background-color: #ffffff;
border: 1px solid #000000;
padding: 6px 8px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
}
.container .message-body p {
margin: 0;
}
<div class="container">
<div class="arrow">
<div class="outer"></div>
<div class="inner"></div>
</div>
<div class="message-body">
<p>Hello world! This is a test message to show how to make an arrow on the side of the box.</p>
</div>
</div>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>