0

HTML:

<ul class="nav">
  <li><a>+7123123123132</a></li>
</ul>

CSS:

.nav .li {
  background: url(../images/phone.svg) no-repeat left center;
  background-position: left 5.9375rem center;
  background-size: 16px 16px;
}

Result:

Phone icon goes very close to number

If i switch to XS - phone icons overlaps the phone number, but if i go for the larger resolution, then it's ok.

Maybe i'm not using correct approach to add a menu icon?

Alexander Kim
  • 17,304
  • 23
  • 100
  • 157
  • Why should you use background-image? It is much easier and expressive if you use an `img` – mahan May 18 '18 at 07:30
  • I would have considered an inline element such as a `` in the `a` tag and targeted that but it is somewhat opinionated and there are lots of opinions. Note that bootstrap often shows examples with the extra tag like that. – Mark Schultheiss May 18 '18 at 11:15
  • @MarkSchultheiss can you point to a bootstrap example with a tag? – Alexander Kim May 18 '18 at 11:51
  • Not 100% a match but https://getbootstrap.com/docs/4.0/components/input-group/ and badge https://getbootstrap.com/docs/4.0/components/badge/ and on here https://stackoverflow.com/a/37762338/125981 – Mark Schultheiss May 18 '18 at 13:03

2 Answers2

0

Try using ::before

.nav a::before {
    content: '';
    background: url ( '../images/phone.svg');
    width: 16px;
    height: 16px;
    display: inline-flex;
}

Was that what you wanted?

User
  • 194
  • 2
  • 12
0

Check this. You can use pseudo class

.phone {
  position: relative;
  padding-left: 20px;
}

.phone:before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 16px;
  height: 16px;
  background: url(https://use.fontawesome.com/releases/v5.0.13/svgs/solid/phone.svg);
  background-size: 16px 16px;
}

.nav {
  margin: 0;
  padding: 0;
  list-style: none;
}
<ul class="nav">
  <li class='phone'><a>+7123123123132</a></li>
</ul>

Here is link

Ram kumar
  • 3,152
  • 6
  • 32
  • 49