I currently have 2 underlines that I want to join in the middle of the word
how to move the underline in the middle of the word? when I try it goes down + the word
.err {
border-top: 2px dotted red;
display: inline-block;
position: relative;
top: 5px;
z-index: 2;
}
.err:after {
content: '';
width: 100%;
border-top: 2px dotted red;
position: absolute;
font-size: 16px;
top: 5px;
left: -2px;
display: block;
height: 4px;
}
<div>hola
<div class="err">mundo</div> informatico</div>
The underline should simulate an Error line, but in the middle of the word
I have the underline located above that simulates to be an ERROR line, but I want to center it in the middle
.err {
border-top: 2px dotted red;
display: inline-block;
position: relative;
top: -1px;
z-index: 2;
}
.err:after {
content: '';
width: 100%;
border-bottom: 2px dotted red;
position: absolute;
font-size: 16px;
top: -5px;
left: -2px;
display: block;
height: 4px;
}
<div>hola
<div class="err">mundo</div> informatico</div>
Just as you are using the after pseudo-element, you can use the before pseudo-element, you could even use calc() to give it a more suitable location depending on what you want to achieve.
Don't add the second "error" line in the element, but in another pseudo element, like so:
To put it in the middle, assign the
top
to 50% of the word and raise it a bit withtransform: translateY(-50%)
.For the second line position it however you want using
calc
andleft
, example:Was this what he needed? Place the word in low opacity, so that it makes better contrast, with black, the red lines are hardly visible.
I know you already have solutions using pseudo-elements, I'm going to give you a solution without using them. You can decorate the text directly so that it has a line above the text (with the value "line-through" for
text-decoration-line
), and that line is wavy (with the value "wavy" fortext-decoration-style
).Here you can see it:
But this solution has a couple of problems (at least for now):