I am trying to create error label for div with arrow, but have problem with centering.
I get:
I need something like:
HTML:
<div class="error-label-arrow"></div>
<div class="error-label">This field is required.</div>
CSS:
div.error-label{
padding: 7px 10px 0 4px;
color: #fff;
background-color: #DA362A;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
div.error-label-arrow{
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right:10px solid #DA362A;
float: left;
}
Is it possible?
Here is the fiddle
You can use CSS Pseudo classes to do this, therefore you won't need an "arrow" element:
div.error-label {
padding: 10px;
color: #fff;
background-color: #DA362A;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
width: 190px;
margin: 30px;
}
div.error-label:before {
content: ' ';
height: 0;
position: absolute;
width: 0;
left: 18px;
border: 10px solid transparent;
border-right-color: #DA362A;
}
<div class="error-label">This field is required.</div>
Here is the solution
div.error-label{
padding: 7px 10px 0 4px;
color: #fff;
background-color: #DA362A;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
width: 150px;
margin-left: 5px;
}
div.error-label-arrow{
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right:10px solid #DA362A;
float: left;
height: 1px;
margin-top: 3px;
}
<div class="error-label-arrow"></div>
<div class="error-label">This field is required.</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With