Currently, I am working on designing a chat bubble using CSS and HTML.
If the chat bubble does not contain any text, I prefer that it remains hidden from view.
I have managed to make the body of the chat bubble disappear when empty by utilizing the :empty
pseudo-class. However, I am facing difficulty in making the triangle part of the chatbox vanish as it is created using the :before
pseudo-selector with content: ''
.
Below you can find my code snippet. Do you know of any way to hide this little triangle if the h4
element is without content?
/* CSS talk bubble */
.myFeedback h4:empty {
display: none;
}
.talk-bubble {
margin-top: 220px;
left: 390px;
display: inline-block;
position: absolute;
width: 200px;
height: auto;
background-color: purple;
}
.round {
border-radius: 10px;
}
.tri-right.right-in:before {
content: '';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -20px;
top: 38px;
bottom: auto;
border: 12px solid;
border-color: purple transparent transparent purple;
}
/* talk bubble contents */
.talktext {
padding: 10px;
text-align: center;
line-height: 1.5em;
}
.talktext p {
/* remove webkit p margins */
-webkit-margin-before: 0em;
-webkit-margin-after: 0em;
}
/* end of talk bubble stuff */
<div class="myFeedback">
<div id='guess-feedback' class="talk-bubble tri-right round right-in">
<h4 class="talktext"></h4>
</div>
</div>