Jump to content

Unable to style dropdown-form? (HTML/CSS beginner)

Go to solution Solved by FliP0x,

Did some research, the way it should work is like:

 

<input list="fname, lname" name="inputlist">

Instead of an ID, an input list wants a name.

 

CSS:
 

input[name="inputlist"]{
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;}

 

Hi I'm using a .html file

Languages: HTML, CSS
Level: Beginner

 

Problem:

Trying to style my dropdown-form yellow aka same as password

 

Problem.jpg

Spoiler

image.png.9ea18038cfd824524719b8dbfb2b338f.png

Correct.jpg

Spoiler

image.png.cf15ce4d3e95a02f0c2d6736f36af6aa.png

HTML

Spoiler
<label for="fname, lname">
Förnamn&Efternamn:
</label>
<br>
<input list="fname, lname">
<datalist id="fname, lname" name="fname, lname">
<option value="Simon SNIP"></option>
<option value="Magnus SNIP"></option>
</datalist>
<br>
<label for="pwd">
Lösenord:
</label>
<br>
<input type="password" id="pwd" name="pwd">
<br>
<input type="submit" value="Logga in">
<input type="reset">
<hr class="hr1">

 

CSS

Spoiler
input[type=list]{
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;}

input[type=password]{
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;}

PC  Specs 2022:

Spoiler
  • CPU
    AMD Ryzen R9 5900x @ 5.1GHz - Auto OC
  • Curve Optimizer Magnitude: -20
  • Motherboard
    ASUS ROG STRIX x570-F Gaming
  • RAM
                                        Kingston Fury 32GB DDR4 3200MHz 16x2GB
  • GPU
    MSI 3070 8GB Ventus 2x OC
  • Case
    LIAN LI LANCOOL MESH II Mesh RGB Black
  • Storage
    Kingston NV1 2TB M.2. NVMe
  • PSU
    Seasonic Focus GX 850w 
  • Display(s)
    MSI OPTIX MAG 251RX IPS 240hz & ASUS MG248Q Vertical 144hz & Dell 60hz
  • Cooling
    NZXT Kraken x73 360mm
  • Keyboard
    Tt eSports Meka G1
  • Mouse
    Logitech G Pro Wireless
  • Operating System
    -Windows 10 Professional 64bit
Link to post
Share on other sites

Try to give the input list an ID that you can work with, for example:
 

<input list="fname, lname" id="inputlist">

Then you can define the ID inputlist in CSS and style it to your liking.

 

Try if this works:
 

inputlist{
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;}

 

NZXT S340 | Ryzen 7 5900X | B550 AORUS PRO V2 | TridentZ RGB 2x8GB 3200 | RTX 4070
Nintendo Switch (2x), Nintendo *New* 3DS, PSP-1000, PSP-2000 (Crisis Core Limited Edition)

MacBook Pro 14 (2021), 16GB RAM, 512GB ROM

Link to post
Share on other sites

6 minutes ago, FliP0x said:

Try to give the input list an ID that you can work with, for example:
 

SNIP

Then you can define the ID inputlist in CSS and style it to your liking.

 

Try if this works:
 

SNIP

 

Hi, thanks for answer. This did not work.

 

HTML

Spoiler
<input list="fname, lname" id="inputlist">
<datalist id="fname, lname" name="fname, lname">
<option value="Simon SNIP"></option>
<option value="Magnus SNIP"></option>
</datalist>

CSS

Spoiler
.inputlist{
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;}

input[type=password]{
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;}

Fail.jpg

Spoiler

image.png.8ae23db23559bd2b7e40d330298ceb4b.png

I'll try to use datalist id instead I suppose.

PC  Specs 2022:

Spoiler
  • CPU
    AMD Ryzen R9 5900x @ 5.1GHz - Auto OC
  • Curve Optimizer Magnitude: -20
  • Motherboard
    ASUS ROG STRIX x570-F Gaming
  • RAM
                                        Kingston Fury 32GB DDR4 3200MHz 16x2GB
  • GPU
    MSI 3070 8GB Ventus 2x OC
  • Case
    LIAN LI LANCOOL MESH II Mesh RGB Black
  • Storage
    Kingston NV1 2TB M.2. NVMe
  • PSU
    Seasonic Focus GX 850w 
  • Display(s)
    MSI OPTIX MAG 251RX IPS 240hz & ASUS MG248Q Vertical 144hz & Dell 60hz
  • Cooling
    NZXT Kraken x73 360mm
  • Keyboard
    Tt eSports Meka G1
  • Mouse
    Logitech G Pro Wireless
  • Operating System
    -Windows 10 Professional 64bit
Link to post
Share on other sites

Did some research, the way it should work is like:

 

<input list="fname, lname" name="inputlist">

Instead of an ID, an input list wants a name.

 

CSS:
 

input[name="inputlist"]{
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;}

 

NZXT S340 | Ryzen 7 5900X | B550 AORUS PRO V2 | TridentZ RGB 2x8GB 3200 | RTX 4070
Nintendo Switch (2x), Nintendo *New* 3DS, PSP-1000, PSP-2000 (Crisis Core Limited Edition)

MacBook Pro 14 (2021), 16GB RAM, 512GB ROM

Link to post
Share on other sites

2 minutes ago, FliP0x said:

Did some research, the way it should work is like:

 

SNIP

Instead of an ID, an input list wants a name.

 

CSS:
 

SNIP

 

I actually just found this out.
Thanks, this works great - It also works with ID!

 

CSS

Spoiler
input[id="inputlist"]{
    width: 150px;
    display: block;
    margin-bottom: 10px;
    background-color: yellow;}

 

PC  Specs 2022:

Spoiler
  • CPU
    AMD Ryzen R9 5900x @ 5.1GHz - Auto OC
  • Curve Optimizer Magnitude: -20
  • Motherboard
    ASUS ROG STRIX x570-F Gaming
  • RAM
                                        Kingston Fury 32GB DDR4 3200MHz 16x2GB
  • GPU
    MSI 3070 8GB Ventus 2x OC
  • Case
    LIAN LI LANCOOL MESH II Mesh RGB Black
  • Storage
    Kingston NV1 2TB M.2. NVMe
  • PSU
    Seasonic Focus GX 850w 
  • Display(s)
    MSI OPTIX MAG 251RX IPS 240hz & ASUS MG248Q Vertical 144hz & Dell 60hz
  • Cooling
    NZXT Kraken x73 360mm
  • Keyboard
    Tt eSports Meka G1
  • Mouse
    Logitech G Pro Wireless
  • Operating System
    -Windows 10 Professional 64bit
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×