1

Hi I was wondering how to give a datalist and the corresponding input the same width. I tried the following :

input {
   width: 100%; 
   padding: 12px 20px 12px 40px;
   border: 1px solid #ddd;
   margin-bottom: 12px;
  }
  datalist,option{
    width: 100%;
  }
<input list="myList"/>
<datalist id="myList">
 <option> This is a great option</option>
</datalist>

The datalist is not the input width when I use the code above. Does anyone know how to make a datalist with the same length as the input he belongs to. Thanks in advance.

1 Answer 1

-1

You could try something like this. Assign a class to each and style with CSS.

CSS

.input {
       width: 100%; 
       padding: 12px 20px 12px 40px;
       border: 1px solid #ddd;
       margin-bottom: 12px;
      }

.Option {
   width: 100%;
}

HTML

<input list="myList"/>
<datalist id="myList">
 <option class="Option"> This is a great option</option>
</datalist>

It might give you the desired outcome.

Sign up to request clarification or add additional context in comments.

2 Comments

There is no element with a class of .input.
Tried it doesn't work unfortunately but your comment is useful sometimes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.