Survey Form - Build a Survey Form

So, if I open the .html file with the stylesheet locally in a browser tab (on Chrome), the selection box and the submit button don’t align at the right border with the text-based input and the text area.
Not sure what’s wrong so I would appreciate someone to take a look at my code and, also, would love to hear ways I can improve my code overall!

Thank you in advance to anyone who answers this question!

Screenshots

CSS code

body {
  background-image: url(https://media.nationalgeographic.org/assets/photos/957/798/480e8645-fc3f-48dc-b17a-e81038d3ee97_c158-0-1842-1333_r800x633.jpg?eff12d8bcc1b3653b5f5a0c5ed1619838922d9af);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed;
  color: rgb(245, 255, 250);
  font-family: Perpetua;
  font-size: 24px;
}

h1, p {
  text-align: center;
}

h1 {
  margin-top: 2rem;
  margin-bottom: 0;
}

p {
  margin-top: 0;
  margin-bottom: 2rem;
}

.established {
  font-style: italic;
}

form {
  background-color: rgba(45, 0, 100, 0.9);
  color: rgb(245, 255, 250);
  border-radius: 5px;
  box-shadow: 0 0 10px rgb(255, 215, 0);
  width: 60vw;
  max-width: 700px;
  min-width: 350px;
  margin: 0 auto;
  padding: 15px 15px 25px 15px;
}

label {
  display: block;
}

fieldset {
  border: none;
}

input,
select,
textarea {
  width: 100%;
  margin: 0.1em 0 1em 0;
  min-height: 2em;
  font-size: 0.67em;
}

input,
select {
  border-radius: 5px;
}

textarea {
  min-height: 6.33em;
  resize: vertical;
}

input[type="submit"] {
  background-color: rgb(139, 0, 139);
  border-color: rgb(255, 215, 0);
  color: rgb(245, 255, 250);
  font-size: 1.33rem;
  min-height: 2.5em;
}

input[type="submit"]:hover {
  outline: none !important;
  border: 2px solid rgb(0, 255, 255);
  box-shadow: 0 0 10px rgb(0, 127, 127);
  cursor: pointer;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none !important;
  box-shadow: 0 0 7px rgb(0, 255, 255);
}

.inline {
  width: unset;
  margin: 0 0.5em 0 0;
  min-height: unset;
  vertical-align: middle;
}

HTML code

<!DOCTYPE html>
<html lang="en">
  <header>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css" />
    <title>freeCodeCamp Survey Form</title>
  </header>
  <body>
    <h1 id="title">freeCodeCamp Survey Form</h1>
    <p id="description" class="established">Thank you for taking the time to help us improve the platform</p>
    <form id="survey-form" action='https://survey-form.freecodecamp.rocks/?name=Jan&email=jan.mlinaric%40gmail.com&age=22&role=student&user-recommend=definitely&mostLike=challenges&prefer=back-end-projects&comment=a'>
      <fieldset>
        <label id="name-label">Name<input id="name" type="text" placeholder="Enter your name" required /></label>
        <label id="email-label">Email<input id="email" type="email" placeholder="Enter your Email" required /></label>
        <label id="number-label">Age <small>(optional)</small> <input id="number" type="number" min="10" max="99" placeholder="Age" /  ></label>
        <label> Which option best describes your current role
          <select id="dropdown">
            <option value="">Select current role</option>
            <option value="1">Student</option>
            <option value="2">Full Time Job</option>
            <option value="3">Full Time Learner</option>
            <option value="4">Prefer not to say</option>
            <option value="5">Other</option>
          </select>
        </label>
      </fieldset>
      <fieldset>
        <label> Would you recommend freeCodeCamp to a friend?</label>
          <label><input type="radio" class="inline" name="attribute" value="1" checked /> Definitely</label>
          <label><input type="radio" class="inline" name="attribute" value="2" /> Maybe</label>
          <label><input type="radio" class="inline" name="attribute" value="3" /> Not sure</label>
      </fieldset>
      <fieldset>
        <label> What is your favorite feature of freeCodeCamp?
          <select id="dropdown2">
            <option value="">Select an option</option>
            <option value="1">Challenges</option>
            <option value="2">Projects</option>
            <option value="3">Community</option>
            <option value="4">Open Source</option>
          </select>
        </label>
      </fieldset>
      <fieldset>
        <label>What would you like to see improved? <small>(Check all that apply)</small> </label>
        <label><input type="checkbox" class="inline" value="front-end-projects" /> Front-end Projects</label>
        <label><input type="checkbox" class="inline" value="back-end-projects" /> Back-end Projects</label>
        <label><input type="checkbox" class="inline" value="data-visualization" /> Data visualization</label>
        <label><input type="checkbox" class="inline" value="challenges" /> Challenges</label>
        <label><input type="checkbox" class="inline" value="open-source-community" /> Open Source Community</label>
        <label><input type="checkbox" class="inline" value="gitter-help-rooms" /> Gitter help rooms</label>
        <label><input type="checkbox" class="inline" value="videos" /> Videos</label>
        <label><input type="checkbox" class="inline" value="city-meetups" /> City Meetups</label>
        <label><input type="checkbox" class="inline" value="wiki" /> Wiki</label>
        <label><input type="checkbox" class="inline" value="forum" /> Forum</label>
        <label><input type="checkbox" class="inline" value="additional-courses" /> Additional Courses</label>
      </fieldset>
      <fieldset>
        <label> Any comments or suggestions?
          <textarea rows="5" cols="50" placeholder="Enter your comment here..."></textarea>
        </label>
      </fieldset>
      <fieldset>
        <input type="submit" value="Submit" id="submit" />
      </fieldset>
    </form>
  </body>
</html>

Challenge: Survey Form - Build a Survey Form

Link to the challenge:

hello,

Are you familiar with how to use developer tools on Chrome?
Basically point your mouse to the input field you are interested in examining, then right-click and choose “Inspect”
This will open a new window for you to examine how this element is being interpreted by the browser. For eg. it can show you the size, and it can show you the css styles that you have applied. You can also play with these values by editing them directly in the the browser tools so you can see their effect.
I would encourage you to try this tool to see what you can learn about your page and the issues you described.

2 Likes

Hi,
thank you kindly for your answer.

The only solution I could come up with is to set the width of the selection box and submit elements to a little more than 100%, like 101.5%,

select,
input[type="submit"] {
  width: 101.5%;
}

but that doesn’t seem like good practice or a solution at all.

So, still not exactly sure how to fix it.

okay so I needed to download your code so I can play with it as well.
I found one piece of good news. The reason that the first 3 inputs are longer is because of your css selector for these inputs is setting a padding value. If you remove that padding on the left and right (by explicitly setting it to 0px) then the fields become closer in size to the bottom two.
I guess there is more tweaking to be done though…

1 Like


This is how it looks for me now

maybe you can add some padding to the smaller fields… (to make them match the others)

If you want the fields to resize well, don’t use px units, just use some other relative unit when setting the padding.

Ok so,
to me it still seems to be a bit off :sweat_smile:
Anyway, I added

input,
style,
textarea {
  ...
  ...
  ...
  box-sizing: border-box;
}

so that all the paddings, margins and borders I added get taken into account and that seems to fix it!

Thank you for your time and help :grinning:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.