Reputation: 661
I need implement custom text decoration, see image below:
It is simple to simulate -
row with next styles:
color: red;
border-bottom: 3px dashed; // 3px - just for example, 2.5 also looks fine.
But I can't find out how to implement underline using +
symbols.
Actually, I know that it is possible to have background-image
, but it wouldn't work if text would be long.
I would appreciate any help. Thank you in advance.
UPD: Simple code snippet to play with:
<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This was inserted.</span> More text <span class="deleted">This was deleted</span></p>
</main>
Upvotes: 2
Views: 269
Reputation: 2246
This is the most performant solution.
.added {
color: green;
position: relative;
}
.added:after {
left: 0;
right: 0;
top: 100%;
height: 5px;
content: '';
position: absolute;
background-size: contain;
background-repeat: repeat-x;
background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="24" fill="green" height="24" viewBox="0 0 24 24"%3E%3Cpath d="M24 10h-10v-10h-4v10h-10v4h10v10h4v-10h10z"/%3E%3C/svg%3E');
}
<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This was inserted.</span> More text <span class="deleted">This was deleted</span>
</p>
</main>
Upvotes: 2
Reputation: 301
The ideal way would use javascript, but with css is possible to do, and would have to adapt to be responsive, you will create a content with many +
and limit the size to occupy only the necessary, follow example
.add:after{
content: "++++++++++++++++++++++++++++++++++++++++++++++++++";
color: green;
font-size: 12px;
position: relative;
top: 17%;
overflow: hidden;
display: block;
}
.after-75:after{
width:75%;
}
.add{
width: fit-content;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1 class="add after-75">We need underline</h1>
Upvotes: 0
Reputation: 272965
You can do this with gradient like below:
.deleted {
background:
repeating-linear-gradient(to right,red 0 4px,transparent 4px 6px)
bottom/100% 2px no-repeat;
}
.added {
background:
repeating-linear-gradient(to right,green 0px 1px,transparent 1px 5px)
bottom 0 left 2px/100% 5px no-repeat,
linear-gradient(green,green) bottom 2px left 0/100% 1px no-repeat;
padding-bottom:4px;
}
<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This was inserted.</span> More text <span class="deleted">This was deleted</span></p>
</main>
If you want some spaces between the +
.deleted {
background:
repeating-linear-gradient(to right,red 0 4px,transparent 4px 6px)
bottom/100% 2px no-repeat;
}
.added {
background:
repeating-linear-gradient(to right,green 0 1px,transparent 1px 7px)
bottom 0 left 2px/100% 5px no-repeat,
repeating-linear-gradient(to right,green 0 5px,transparent 5px 7px)
bottom 2px left 0/100% 1px no-repeat;
padding-bottom:4px;
}
<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This was inserted.</span> More text <span class="deleted">This was deleted</span></p>
</main>
It will also work with multiline text:
.deleted {
background:
repeating-linear-gradient(to right,red 0 4px,transparent 4px 6px)
bottom/100% 2px no-repeat;
}
.added {
background:
repeating-linear-gradient(to right,green 0 1px,transparent 1px 7px)
bottom 0 left 2px/100% 5px no-repeat,
repeating-linear-gradient(to right,green 0 5px,transparent 5px 7px)
bottom 2px left 0/100% 1px no-repeat;
padding-bottom:4px;
}
<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This is long long long long long long long long long long text was inserted.</span> More text <span class="deleted">This was deleted</span></p>
</main>
Upvotes: 6