I've been running around trying to figure out how I can use grid to format the layout of a form. I seem to be doing exactly what other coders are doing to utilize grid in CSS but it's just not working. My goal is to put the "type" selector to the right of the pet name and the reset button to the right of the submit button. Could someone point out what I'm missing? my css code and what the form looks like
Asked
Active
Viewed 78 times
0
-
Please include code, **NOT** pictures of code. Preferably as a [MCVE] – Jon P Dec 17 '21 at 05:24
2 Answers
0
I think your issue might be because of the <div>
you have on both input and select tags. By default div
are block elements and browsers will start div
on a new line by placing a line break before and after a div.
- One quick fix is removing the
div
surrounding your Pet Name and Type. If you must, have both of them in a singlediv
. - Preferably use
1fr
in place of 50%. You will get this desired output

tea-codes
- 61
- 7
0
You are using seperate div for individual elements, that's why the elements are displaying one after another. You can put a common div for the elements which you want to display adjacent to each other.
<div class="grid">
<div>
<legend>Add pet</legend>
</div>
<div>
<label for="Name">Pet Name</label>
<input type="text" id="name" name="pet_name">
<label for="Type"></label>
<select id="type" name="pet_type">
<option value="Cat">Cat<option>
<option value="Dog">Dog<option>
<option value="Dog">Dog<option>
<option value="Dog">Dog<option>
</select>
</div>
<div>
<button type="submit" id="new_pet_submit_button">Create New Pet</button>
<button type="reset">Reset</button>
</div>
</div>

srinithi R
- 206
- 1
- 5