Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can custom underline to a text

Tags:

css

How to get border-bottom like in image. I've tried text-underline for a h1 tag using text-decoration property.

enter image description here

h1 {
  color: #F16A70;
  text-transform: uppercase;
  font-size: 30;
  font-family: oswald text-decoration: underline;
}
h1:after {
  width: 60%;
  border-bottom: 2px solid #F16A70;
}
<div>
  <h1>navigation</h1>
</div>
like image 354
Prasath V Avatar asked Feb 01 '17 08:02

Prasath V


People also ask

How do I create a custom underline in CSS?

How to Underline a Title in CSS. To underline a title, you can use text-decoration: underline; but you can make it prettier if you use the border-bottom property. In the latter case, however, you need to add display: inline; so that the underline wouldn't be longer than the word itself.

How do you underline text in CSS?

The property text-decoration-line is used to underline the text. This property has three values that are overline, underline, or line-through. So, the value underline is used to underline the text in CSS. This value draws the underline beneath the inline text.


2 Answers

Here's one more solution:

h1{
    color: #F16A70;
    text-transform: uppercase;
    display: inline-block;
    font-size: 30;
    font-family: oswald;
    text-decoration: none;
    background-image: linear-gradient(to right, #F16A70, #F16A70);
    background-position: bottom left;
    background-repeat: no-repeat;
    background-size: 50% 2px;
    transition: background-size .5s ease;
}
h1:hover {
    background-size: 100% 2px;
}
<div>
<h1>navigation</h1>
</div>

Animation of :after pseudo-element - to get it visible you need to set position attribute for both h1 and h1:after:

h1 {
    color: #F16A70;
    position: relative;
    text-transform: uppercase;
    display: inline-block;
    font-size: 30;
    font-family: oswald;
    text-decoration: none;
}
h1:after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    height: 0;
    width: 30%;
    border-bottom: 2px solid #F16A70;
    transition: width 0.3s ease;
}
h1:hover:after {
    width: 100%;
}
<div>
<h1>navigation</h1>
</div>
like image 168
Banzay Avatar answered Sep 29 '22 15:09

Banzay


You can do it with css3 linear-gradient().

Steps:

  1. Create background image with linear-gradient().
  2. Adjust its size with css background-size property.
  3. Place it at the bottom left position of the element with background-position css property.

Necessary CSS:

h1 {
  background: linear-gradient(to right, #F16A70, #F16A70) no-repeat;
  background-size: 60% 3px;
  background-position: left bottom;
}

h1 {
  background: linear-gradient(to right, #F16A70, #F16A70) no-repeat;
  background-size: 60% 3px;
  background-position: left bottom;
  color: #F16A70;
  text-transform: uppercase;
  font-size: 30px;
  font-family: oswald, sans-serif;
  display: inline-block;
  vertical-align: top;
  padding-bottom: 10px;
}
<h1>Navigation</h1>
like image 25
Mohammad Usman Avatar answered Sep 29 '22 17:09

Mohammad Usman