skip to Main Content

I am trying to implement a design from figma but notice it isnt always accurate:

This is the input field i want to create:

enter image description here

Notice how the thin the text is. These are the values from figma:

color: var(--heading-black, #222);
/* Button/16/Regular */
font-family: Inter;
font-size: 16px;
font-style: normal;
font-weight: 400;
line-height: 16px;

I also use the same color and font-weight, I even tried using 100 instead of 400, yet my result is:

enter image description here

My text is much thicker and I dont know why. This is my css code for my input field:

.search-field {
    margin-left: 65px;
    width: 429px;
    height: 44px;   
    font-size: 16px;
    font-weight: 400;
    padding-left: 46px;
    background: url("../../../assets/icons/search.png") no-repeat;
    background-color: white;
    background-size: 21px;
    background-position: 14px center;
    border: none;
    border-radius: 4px;
    outline: none;
    color: #222;
}

and html:

<input type="text" class="search-field" value placeholder="Booking.com, Expedia, Otto...">

What am I doing wrong?

3

Answers


  1. I think your input is getting its weight from another class or tag.
    Try using !important for the font-weight and see if it works:

    font-weight: 400 !important;
    
    Login or Signup to reply.
  2. If you’re getting the same result even if you change the font-weight value, it means you’re having one of these problems:

    1. Your font does not have or you have not imported the desired weight value (example: you want 100 but the closest value you have included in the @font face is 400 );
    2. Check that there are no other rules that are not overwriting it;

    Last thing, in this case you want to change the appearance of the placeholder so you will have to use the pseudo element ::placeholder so you can change only the style of the placeholder without running the risk of having other problems.

    In the code, I provided the placeholder with a lighter color so as to simulate the result.

    .search-input{
        box-sizing: border-box;
        background-color: #21A668;
        padding: 10px;
    }
    
    .search-field{
        width: 429px;
        height: 44px;   
        font-size: 16px;
        font-weight: 400;
        padding: 0 10px 0 46px;
        background: url("../../../assets/icons/search.png") no-repeat;
        background-color: white;
        background-size: 21px;
        border: none;
        border-radius: 4px;
        outline: none;
        color: #222;
    }
    
    .search-field::placeholder{
        color: #bdbdbd;
    }
        <div class="search-input">
            <input type="text" class="search-field" value placeholder="Booking.com, Expedia, Otto...">
        </div>
    Login or Signup to reply.
  3. Try adding the font-family property and it’s value in your selector and also use the cdn I used here cause it has all the available font-weights embedded in it.

    @import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&family=Open+Sans&family=Plus+Jakarta+Sans:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,200;1,300;1,400;1,500;1,600;1,700;1,800&display=swap');
    
    .search-field{font-family: 'Inter', sans-serif;}
    
    @import url('https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&family=Open+Sans&family=Plus+Jakarta+Sans:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,200;1,300;1,400;1,500;1,600;1,700;1,800&display=swap');
    
    body{
      background: green;
    }
    
    .search-field {
        margin-left: 65px;
        width: 429px;
        height: 44px;
        font-family: 'Inter', sans-serif;
        font-size: 16px;
        font-weight: 400;
        padding-left: 46px;
        background: url("../../../assets/icons/search.png") no-repeat;
        background-color: white;
        background-size: 21px;
        background-position: 14px center;
        border: none;
        border-radius: 4px;
        outline: none;
        color: #222;
    }
    <input type="text" class="search-field" value placeholder="Booking.com, Expedia, Otto...">
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search