What is the best way to adjust the size of a form element to be 600px wide only when the window width exceeds 600px?

As part of the application process for a coding bootcamp, I have been asked to complete an HTML/CSS assessment. After submitting my code, I received feedback stating that there was no 'form' element set to 600px when the window width exceeded 600px. This feedback has left me puzzled as I made it clear in the code that no element should exceed 600px regardless of screen size. With limited attempts at this assessment and a tight deadline, any assistance would be greatly appreciated.

form {
  width: auto;
}
@media screen and (min-width: 600px) {
  /* big */
  .form {
      max-width: 600px;
      display: block;
      /* display: block;  is a maybe */
      grid-template-columns: 1fr;
      /* grid-template-columns: 1fr;  is also a maybe  */
    }

  label {
    display: block;
    margin: 0;
    text-align: left;
    width: auto;
  }

  input,
  select,
  textarea {
    width: 100%;
  }

  .center {
    margin: auto;
    width: 50%;
    border: 3px;
  }

  .wrapper {
    display: grid;
    grid-template-columns: repeat(1fr);
    gap: 12px;
  }

  .one {
    grid-row: 1;
    max-width: 600px;
  }

  .two {
    grid-row: 2;
    max-width: 600px;
  }

  .three {
    grid-row: 3;
    max-width: 600px; /*added later*/
  }

  .four {
    grid-row: 4;
    max-width: 600px;
  }

  .five {
    grid-row: 5;
    max-width: 600px;
  }

  .card {
    width: 344px;
    background-color: #E0E0E0;
    padding: 5px;
    margin: 0;
  }

  .desertIm {
    height: 194px;
    width: 100%;
  }

  .title {
    color: #000;
    font-size: 22px;
  }

  .secondarytxt {
    color: #232F34;
  }

  .bodytxt {
    font-size: 11px;
    color: #232F34;
    margin: 16px;
  }

  .avatar {
    height: 40px;
    width: 40px;
    border-radius: 50%;
    position: relative;
    top: 20%;
    left: 15%;
  }
}


/* divider */

.item1 {
  grid-area: header;
} 
.item2 {
  grid-area: avatar;
}
.item3 {
  grid-area: sec;
}
.item4 {
  grid-area: title;
}
.item5 {
  grid-area: body;
}

.card {
  display: grid;
  grid-template-areas:
    "header header header header header header"
    "avatar title title title title title"
    "avatar sec sec sec sec sec"
    "body body body body body body";
}

.card > div {
  text-align: left;
  background-color: white;
}

.card:hover {
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
}

/* divider */

@media screen and (max-width: 600px) {
  form {
    width: 100%;
  }

  label {
    display: block;
    margin: 0;
    text-align: left;
    width: auto;
  }

  input,
  select,
  textarea {
    width: 100%;
  }

  .card {
    width: 344px;
    background-color: #E0E0E0;
    padding: 5px;
    margin: 0;
  }

  .desertIm {
    height: 194px;
    width: 100%;
  }

  .title {
    color: #000;
    font-size: 22px;
  }

  .secondarytxt {
    color: #232f34;
  }

  .bodytxt {
    font-size: 11px;
    color: #232f34;
    margin: 16px;
  }

  .avatar {
    height: 40px;
    width: 40px;
    border-radius: 50%;
    position: relative;
    top: 20%;
    left: 15%;
  }

  .item1 {
    grid-area: header;
  } 
  .item2 {
    grid-area: avatar;
  }
  .item3 {
    grid-area: sec;
  }
  .item4 {
    grid-area: title;
  }
  .item5 {
    grid-area: body;
  }
  
  .card {
    display: grid;
    grid-template-areas:
      "header header header header header header"
      "avatar title title title title title"
      "avatar sec sec sec sec sec"
      "body body body body body body";
  }
  
  .card > div {
    text-align: left;
    background-color: white;
  }
  
  .card:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
  }
}
<html>
  <body>

    <div class="center wrapper form">
      <form action="/pets" method="post">
      </form>


      <div class="one">
        <label for="name">Name</label>
        <input type="text" id="name" name="pet_name">
      </div>

      <div class="two">
        <label for="type">Type
          <select name="pet_type" id="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>
        </label>
      </div>

      <div class="three">
        <label for="biography">Biography</label>
        <textarea id="bio" name="pet_bio" rows="4" cols="50">
        </textarea>
      </div>

      <div class="four">
        <label for="email">Owner's Email</label>
        <input type="email" id="owner-email" name="pet_owner_email">
      </div>

      <div class="five">
        <button type="submit" id="new-pet-submit-button">Create new pet</button>
        <button type="reset">Reset</button>
      </div>



     <!-- divider -->

      <div class="card">
        <div class="item1"><img src="images/desert.jpg" class ="desertIm"></div>
        <div class="item2"><img src="images/person-avatar.jpg" class="avatar"></div>
        <div class="item3"><body><p class="secondarytxt">Secondary text</p></body></div>  
        <div class="item4"><h4><b class="title">Title goes here</b></h4></div>
        <div class="item5"><body><p class="bodytxt">Greyhound divisively hello coldly
          wonderfully marginally far upon excluding.</p></body></div>
      </div>
    </div>  
  </body>
</html>

Answer №1

Your code seems to be correct; when the screen width exceeds 600px, the form stays at a maximum width of 600px.

form {
  width: 100%;
}
@media screen and (min-width: 600px) {
  /* big */
  .form {
      max-width: 600px;
      display: block;
      /* display: block;  is a maybe */
      grid-template-columns: 1fr;
      /* grid-template-columns: 1fr;  is also a maybe  */
    }

  label {
    display: block;
    margin: 0;
    text-align: left;
    width: auto;
  }

  input,
  select,
  textarea {
    width: 100%;
  }

  .center {
    margin: auto;
    width: 50%;
    border: 3px;
  }

  .wrapper {
    display: grid;
    grid-template-columns: repeat(1fr);
    gap: 12px;
  }

  .one {
    grid-row: 1;
    max-width: 600px;
  }

  .two {
    grid-row: 2;
    max-width: 600px;
  }

  .three {
    grid-row: 3;
    max-width: 600px; /*added later*/
  }

  .four {
    grid-row: 4;
    max-width: 600px;
  }

  .five {
    grid-row: 5;
    max-width: 600px;
  }

  .card {
    width: 344px;
    background-color: #E0E0E0;
    padding: 5px;
    margin: 0;
  }

  .desertIm {
    height: 194px;
    width: 100%;
  }

  .title {
    color: #000;
    font-size: 22px;
  }

  .secondarytxt {
    color: #232F34;
  }

  .bodytxt {
    font-size: 11px;
    color: #232F34;
    margin: 16px;
  }

  .avatar {
    height: 40px;
    width: 40px;
    border-radius: 50%;
    position: relative;
    top: 20%;
    left: 15%;
  }
}


/* divider */

.item1 {
  grid-area: header;
} 
.item2 {
  grid-area: avatar;
}
.item3 {
  grid-area: sec;
}
.item4 {
  grid-area: title;
}
.item5 {
  grid-area: body;
}

.card {
  display: grid;
  grid-template-areas:
    "header header header header header header"
    "avatar title title title title title"
    "avatar sec sec sec sec sec"
    "body body body body body body";
}

.card > div {
  text-align: left;
  background-color: white;
}

.card:hover {
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
}

/* divider */

@media screen and (max-width: 600px) {
  form {
    width: 100%;
  }

  label {
    display: block;
    margin: 0;
    text-align: left;
    width: auto;
  }

  input,
  select,
  textarea {
    width: 100%;
  }

  .card {
    width: 344px;
    background-color: #E0E0E0;
    padding: 5px;
    margin: 0;
  }

  .desertIm {
    height: 194px;
    width: 100%;
  }

  .title {
    color: #000;
    font-size: 22px;
  }

  .secondarytxt {
    color: #232f34;
  }

  .bodytxt {
    font-size: 11px;
    color: #232f34;
    margin: 16px;
  }

  .avatar {
    height: 40px;
    width: 40px;
    border-radius: 50%;
    position: relative;
    top: 20%;
    left: 15%;
  }

  .item1 {
    grid-area: header;
  } 
  .item2 {
    grid-area: avatar;
  }
  .item3 {
    grid-area: sec;
  }
  .item4 {
    grid-area: title;
  }
  .item5 {
    grid-area: body;
  }
  
  .card {
    display: grid;
    grid-template-areas:
      "header header header header header header"
      "avatar title title title title title"
      "avatar sec sec sec sec sec"
      "body body body body body body";
  }
  
  .card > div {
    text-align: left;
    background-color: white;
  }
  
  .card:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
  }
}
<body>

  <div class="center wrapper form">
    <form action="/pets" method="post">
    </form>


    <div class="one">
      <label for="name">Name</label>
      <input type="text" id="name" name="pet_name">
    </div>

    <div class="two">
      <label for="type">Type
        <select name="pet_type" id="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>
      </label>
    </div>

    <div class="three">
      <label for="biography">Biography</label>
      <textarea id="bio" name="pet_bio" rows="4" cols="50">
      </textarea>
    </div>

    <div class="four">
      <label for="email">Owner's Email</label>
      <input type="email" id="owner-email" name="pet_owner_email">
    </div>

    <div class="five">
      <button type="submit" id="new-pet-submit-button">Create new pet</button>
      <button type="reset">Reset</button>
    </div>
    
    

   <!-- divider -->

    <div class="card">
      <div class="item1"><img src="images/desert.jpg" class ="desertIm"></div>
      <div class="item2"><img src="images/person-avatar.jpg" class="avatar"></div>
      <div class="item3"><body><p class="secondarytxt">Secondary text</p></body></div>  
      <div class="item4"><h4><b class="title">Title goes here</b></h4></div>
      <div class="item5"><body><p class="bodytxt">Greyhound divisively hello coldly
        wonderfully marginally far upon excluding.</p></body></div>
    </div>
  </div>  
</body>

</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The parent node is returning a child element

Currently working on a website using Vue 3.0 and Element+ and encountering an inconsistency. There is a div displayed on the page (an array of objects) and the goal is to remove the object from the array when a button is clicked. The issue arises when som ...

Incorporate a personalized div element for enhanced navigation in Google Maps API V2

Although I can successfully do this for V3, I am struggling to find any examples for V2. I am aiming to incorporate the following DIV content below. It would be ideal to keep it within a function for easy modification. function insertLogo() { r ...

Ways to decrease the space between lines of text within a single mat-option element

https://i.sstatic.net/Sr1cb.png ::ng-deep .mat-select-panel mat-option.mat-option { height: unset; } ::ng-deep .mat-option-text.mat-option-text { white-space: normal; } Currently, I have implemented this code to ensure that text in options wraps to t ...

Establishing a connection from PHP to an SQL server in HTML

I have an HTML form that I need to use to filter the data in a SQL file. I am having trouble connecting to a local MySQL server and cannot seem to get into the table() function. This is the code I am using: <form id="form_id" action="food_values.php" ...

What is the reason behind negative z-index causing non-statically positioned elements to lose their hovering capabilities?

I've recently discovered that when setting z-index:-1 to non-statically positioned elements, it can affect their hovering capabilities. Interestingly, the behavior of absolutely and fixed positioned elements varies under different conditions. ...

Ways to avoid single-sided border from overlapping with border radius

When adding a 2px bottom border to a text field with a 4px corner radius on the container, the border tends to curl around the edge due to the larger radius. I am looking for a solution to keep the bottom edge flat. [What I DON'T want: border wrappin ...

Activate dropdown menu link when tapped twice on tablet devices

I am trying to implement a dropdown navigation link feature on tablets where the child menu div drops down only on the second click. This functionality already works on iPads, but on Android and Windows tablets, the link is triggered at the same time as th ...

using ng-class or ng-style for displaying error messages when validating a text area content

I'm curious about the most effective "angular" method for changing the character count style for validation purposes. I have a text area with a 250-character limit. Instead of restricting users to exactly 250 characters, we want to allow them to excee ...

In a carousel slider, the height and width of divs are not set to specific dimensions

For a code snippet, you can visit this link: here The html: <html lang="en"> <head> <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,700i|Merriweather:300,400,700" rel="stylesheet"> <link href="https://ma ...

ways to dynamically retrieve input values in PHP

Is there a way to dynamically add and remove data fields, as well as increase and decrease fields dynamically in PHP? I am looking to retrieve the subject value in an array or JSON format using PHP only. https://i.stack.imgur.com/HqDCz.png <div data-ro ...

Can you explain the purpose of the spaces on the buttons?

mysterious button spacing issue <div class="buttons"> <button id="btn-search" type="submit">Search Engine</button> <button id="btn-lucky" type="submit">Feeling Lucky Today</button> </div> .buttons { max-width: 29 ...

Inject the css file into the PDFMake styling configuration

My current task involves converting a string with HTML markup into a PDF using the HTML-to-pdfmake and pdf make libraries. The HTML code includes numerous classes and ids, with corresponding styles defined in a CSS file. Rather than manually adding all the ...

When converting the .html file to a .php file, the CSS file fails to be linked correctly

The issue I'm facing seems to be specific to the index.html file. The CSS that functions properly with an html extension suddenly stops working when the extension is changed to php. Upon inspecting the reference link in both cases, I noticed that when ...

Adding a new entry to a database that involves many-to-many relationships

I recently inquired about executing a fetch query on a database with a many-to-many relationship. As I delve deeper into learning SQL + PHP, I encountered a rather intricate scenario: Within my database, I have the following tables: Songs Link ...

Are the buttons appearing within a pop-up display?

I am having an issue with my Javascript popup buttons. Whenever the popup appears, the buttons that come after the one clicked appear on top of the popup container, and the previous buttons appear behind it. How can I ensure that the popup container displa ...

Tips for expanding a text input field vertically, not horizontally like in Facebook, while typing or by holding down the Shift key and pressing Enter

I've come across numerous plugins that enable vertical resizing of a textarea and others that allow horizontal resizing of an input field. However, I have yet to find one that enables vertical resizing of an input field similar to Facebook's comm ...

Ways to add padding while ensuring the element remains responsive

Whenever I try to add padding to an element, it ends up losing its responsiveness when the window is resized. I am using Reactjs with React-bootstrap, and I believe the issue lies in the way I am setting the padding on the element. Interestingly, when I re ...

Selecting multiple items in jQuery based on different attributes is a useful feature that

I am looking to choose multiple items based on their data attribute. Each item has a unique data-id. <div class="foo" data-id="1"></div> <div class="foo" data-id="2"></div> <div class=" ...

What steps should be taken to prevent divs from overlapping a centrally positioned, unchanging div when the browser is resized

Looking to create a layout with two columns, featuring a fixed sidebar on the left and centering the main content area. The goal is for the centered content to remain in place when resized and not move further left than where it touches the nav bar (left: ...

JavaScript for creating dropdown menus using Twitter Bootstrap

I've been struggling to get the dropdown menus in my Twitter Bootstrap project to function properly. Below is the code I have for the navbar: <div class="container-fluid"> <div class="row-fluid"> <div class="span12"> < ...