-2

Thank you in advance - I am a complete beginner (1 week) to coding including HTML/CSS and have been unable to find a specific solution to the following criteria for a form I have built. I am trying to understand how to implement the following conditions in an external CSS file:

-the form is X pixels wide when the screen is greater than or equal to X pixels wide;

-the form uses a grid layout to layout labels and form elements when the screen is greater than or equal to X pixels wide;

-the form is the width of the screen when the screen is less than X pixels wide;

-the form lays out the labels and form elements as full width when the screen is less than X pixels wide

The above criteria is for an assessment which is why I have included a screenshot and not modifiable code (I am not looking for a handout), but I could really use some guidance on the basics needed in order to get started. I've tried several combinations of @media, class and max-width, and have watched several tutorials but these seem geared towards basic width and height modifications using class, which I still do not fully understand.

HTML Code

Thank you again and I appreciate any feedback - I'm excited to learn more!

1 Answers1

0

Consider looking into BootStrap which is a grid based system for dividing up the page intelligently based on the Viewport size.

https://getbootstrap.com/docs/4.0/components/forms/

Quick getting start intro:

https://getbootstrap.com/docs/4.4/getting-started/introduction/

You can include Bootstrap into your pages quickly using the CDN.

Some code:

<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

  <title>Hello, world!</title>
</head>

<body>
  <h1>Hello, world!</h1>

  <form>
    <div class="form-group">
      <label for="exampleInputEmail1">Pet Owner Email address</label>
      <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter pet owner email" name="pet_owner_email">
      <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
    </div>
    <div class="form-group">
      <label for="exampleInputPassword1">Password</label>
      <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password">
    </div>

    <div class="form-group">
      <label for="exampleFormControlSelect2">Pet Type:</label>
      <select multiple class="form-control" id="exampleFormControlSelect2" name="pet_type">
        <option value="cat">Cat</option>
        <option value="dog">Dog</option>
        <option value="hamster">Hamster</option>
        <option value="other">Other</option>
        <option value="zebra">Zebra</option>
      </select>
    </div>

    <div class="form-check">
      <input type="checkbox" class="form-check-input" id="exampleCheck1">
      <label class="form-check-label" for="exampleCheck1">Check me out</label>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>

  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>

</html>
Chris Medina
  • 338
  • 1
  • 10