Home > Back-end >  How to insert icon before text?
How to insert icon before text?

Time:10-23

I have a problem, I can't insert an icon in front of the text this is how it should be:enter image description here (I add code on snippet) I am a beginner coder, so there may be mistakes and I just want to add a trading basket icon in front of the logo with text of the same color as the logo itself, I searched for a long time on the Internet and on other forums, but everything that was there did not help me or did not work

body {
    margin: 0;
    font-family: Helvetica, sans-serif;
    background-color: #f4f4f4;
  }
  
  a {
    color: #000;
  }
  
  /* header */
  
  .header {
    background-color: #fff;
    box-shadow: 1px 1px 4px 0 rgba(0,0,0,.1);
    position: fixed;
    width: 100%;
    z-index: 3;
  }
  
  .header ul {
    margin: 0;
    padding: 0;
    list-style: none;
    overflow: hidden;
    background-color: #fff;
  }
  
  .header li a {
    display: block;
    padding: 20px 20px;
    border-right: 1px solid #f4f4f4;
    text-decoration: none;
  }
  
  .header li a:hover,
  .header .menu-btn:hover {
    color:green;
  }

  /* Big coder moment, да я гений просто зеленим залив без хекса */
  
  .header .logo {
    display: block;
    float: left;
    font-size: 2em;
    padding: 10px 20px;
    text-decoration: none;
    color:green;
    
  }
  
  /* menu */
  
  .header .menu {
    clear: both;
    max-height: 0;
    transition: max-height .2s ease-out;
  }
  
  /* menu icon */
  
  .header .menu-icon {
    cursor: pointer;
    display: inline-block;
    float: right;
    padding: 28px 20px;
    position: relative;
    user-select: none;
  }
  
  .header .menu-icon .navicon {
    background: #333;
    display: block;
    height: 2px;
    position: relative;
    transition: background .2s ease-out;
    width: 18px;
  }
  
  .header .menu-icon .navicon:before,
  .header .menu-icon .navicon:after {
    background: #333;
    content: '';
    display: block;
    height: 100%;
    position: absolute;
    transition: all .2s ease-out;
    width: 100%;
  }
  
  .header .menu-icon .navicon:before {
    top: 5px;
  }
  
  .header .menu-icon .navicon:after {
    top: -5px;
  }
  
  /* menu btn */
  
  .header .menu-btn {
    display: none;
  }
  
  .header .menu-btn:checked ~ .menu {
    max-height: 240px;
  }
  
  .header .menu-btn:checked ~ .menu-icon .navicon {
    background: transparent;
  }
  
  .header .menu-btn:checked ~ .menu-icon .navicon:before {
    transform: rotate(-45deg);
  }
  
  .header .menu-btn:checked ~ .menu-icon .navicon:after {
    transform: rotate(45deg);
  }
  
  .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before,
  .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
    top: 0;
  }
  
  /* 48em = 768px */
  
  @media (min-width: 48em) {
    .header li {
      float: left;
    }
    .header li a {
      padding: 20px 30px;
    }
    .header .menu {
      clear: none;
      float: center;
      max-height: none;
    }
    .header .menu-icon {
      display: none;
    }
  }
  
  logo:before {
      content:url(images/quotemarks.png);
  }
  
  
  
<!DOCTYPE html>
<html lang="en">
<head>
  <header >
  <a href="" >Fresh market</a>
  <input  type="checkbox" id="menu-btn" />
  <link rel="stylesheet" href="style.css">
  <label  for="menu-btn"><span ></span></label>
  <ul >
    <li><a href="#work">Home</a></li>
    <li><a href="#about">Shop</a></li>
    <li><a href="#careers">About</a></li>
    <li><a href="#contact">Contact</a></li>
  </ul>
</header>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Shop</title>
</head>
<body>
  
</body>
</html>
thanks in advance :) enter image description here

some wrong :(

CodePudding user response:

You can use the ::before psuedo-element to insert content before an element. The code below code sets the content of the p::before element to an image using the url() function. display: inline-block lets you set a width and height of the p::before content.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Sample</title>
  <style>
      p::before {
        content: url('https://www.svgrepo.com/show/2460/cherry.svg');
        width: 20px;
        height: auto;
        display: inline-block;
      }
  </style>
</head>

<body>
  <p>Logo Text</p>
</body>
<html>

CodePudding user response:

p{
  color:green;
  font-size:25px;
  font-weight: bold;
 
}
 p:before {
   font-family: "Font Awesome 5 Free"; 
content:url(' add image link');
        display: inline-block;
        padding-right: 3px;
        vertical-align: middle;
        font-weight: 900;
      }
<p >Fresh Market</p>

it's esay you can use .css :before and :after element like this

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <link rel="stylesheet" type="text/css" href="//use.fontawesome.com/releases/v5.7.2/css/all.css">
    <style>
      body {
        font-family: Arial;
        font-size: 15px;
      }
      a {
        text-decoration: none;
        color: #000000;
      }
      a:before {
        font-family: "Font Awesome 5 Free";
        content: "\f00c";
        display: inline-block;
        padding-right: 3px;
        vertical-align: middle;
        font-weight: 900;
      }
    </style>
  </head>
  <body>
    <a href="#">Here is a link</a>
  </body>
</html>

  • Related