Are your box-sizing and media queries failing to function properly?

I am struggling to create a responsive page that has specific layout specifications based on screen width. My goal is to:

  1. Hide the right chat info box when the page is under 1000px wide

Additionally, I want to:

  1. Hide both the right chat box and left sidebar when the page is under 600px;

Despite my efforts, I can't seem to get the media queries to work properly in my code.

Another issue I'm facing is with the searchbox in the left sidebar overflowing its parent container even after applying "box-sizing: border" CSS property.

Lastly, I'm looking for a way to make the vertical side borders of the boxes extend to the full height of the page without creating a side scroll bar, which is not allowed in this project.

Please take a look at my code snippet below and provide any insights you may have, thank you:

@media screen and (max-width: 1400px) {
  .groupsettings,
  .search {
    width: 300px;
  }
}
@media screen and (max-width: 1000px) {
  .groupsettings {
    display: none;
  }
}
@media screen and (max-width: 600px) {
  .search {
    display: none;
  }
}
.avatar {
  border-radius: 50%;
  height: 25px;
  margin-left: 0;
  margin-right: 10px;
  width: 25px;
}
.chatroom {
  border-right: 1px solid lightgray;
  grid-column: 2/3;
  grid-row: 2/3;
}
.groupprofile {
  border-bottom: 1px solid lightgray;
  padding: 10px;
}
.groupsettings {
  grid-column: 3/4;
  grid-row: 2/3;
  min-width: 300px;
}
.grouptitle {
  grid-column: 2/4;
  grid-row: 1/2;
}
.his {
  background-color: lightgray;
}
.his,
.mine {
  border-bottom-left-radius: 50px;
  border-bottom-right-radius: 50px;
  border-top-left-radius: 50px;
  border-top-right-radius: 50px;
  font-size: 14px;
  width: max-content;
  padding: 5px 10px 7px;
}
.loading {
  color: lightgray;
  font-size: 14px;
  text-align: center;
}
.logo {
  border-radius: 50%;
  height: 40px;
  vertical-align: middle;
  width: 40px;
}
.messenger {
  border-top: 1px solid lightgray;
  display: grid;
  grid-template-columns: 3fr 4fr 3fr;
  grid-template-rows: auto 1fr;
}
.mine {
  align-self: right;
  background-color: #0097f7;
  color: white;
  margin-left: auto;
  margin-right: 10px;
}
.name {
  color: lightgray;
  font-size: 12px;
  margin: 0;
  text-indent: 10%;
}
.normal {
  font-size: 14px;
  margin-left: 5px;
}
.options {
  color: gray;
  font-size: 14px;
  margin-left: 10px;
  margin-top: 10px;
}
.search {
  border-right: 1px solid lightgray;
  grid-column: 1/2;
  grid-row: 1/3;
  min-width: 300px;
}
.searchbox {
  background-color: lightgray;
  border: none;
  border-radius: 2px;
  box-sizing: border-box;
  color: gray;
  font-size: 12px;
  margin: 10px;
  padding-bottom: 5px;
  padding-top: 5px;
  text-align: center;
  width: 100%;
}
.searchbox:focus {
  border: none;
  padding-left: 10px;
  text-align: left;
}
.settings {
  padding: 0px;
}
.steve {
  display: flex;
  align-items: center;
  margin-left: 10px;
}
body {
  font-family: "SFUIText-Regular", "Segoe UI", "Helvetica Neue", Helvetica,
    Arial, sans-serif;
  margin: 5px 0 0;
}
strong {
  border-bottom: 1px solid lightgray;
  display: block;
  text-align: center;
  padding-bottom: 10px;
  padding-top: 10px;
}</coade></pre>
<pre><code><html>
  <head>
    <title>Messenger</title>
  </head>
  <body>
    <div class="messenger">
      <div class="search">
        <strong>Messenger</strong>
        <input class="searchbox" placeholder="Search Messenger" />
      </div>
      <div class="grouptitle"><strong>normal group chat</strong></div>
      <div class="chatroom">
        <p class="mine">Hey man, hope everything's okay!</p>
        <p class="name">Steve</p>
        <div class="steve">
          <img
            class="avatar"
            alt="mine-craft-chara"
            src="https://i.imgur.com/R10B80x.png"
          /><span class="his"
            >All good man, those stacks of diamonds coming in hot!</span
          >
        </div>
        <p class="mine">Nice - make sure to save me some haha :D</p>
      </div>
      <div class="groupsettings">
        <div class="groupprofile">
          <img
            class="logo"
            alt="mine-craft-logo"
            src="https://i.imgur.com/vWJzAsu.jpg"
          />
          <span class="normal">normal group chat</span>
        </div>
        <div class="settings">
          <p class="options">Options</p>
          <p class="loading">Loading...</p>
        </div>
      </div>
    </div>
  </body>
</html>

Answer №1

Don't forget to remove the semi-colons after specifying the max-width.

@media screen and (max-width: 1400px) {
  .groupsettings,
  .search {
    width: 300px;
  }
}
@media screen and (max-width: 1000px) {
  .groupsettings {
    display: none;
  }
}
@media screen and (max-width: 600px) {
  .search {
    display: none;
  }
}
.avatar {
  border-radius: 50%;
  height: 25px;
  margin-left: 0;
  margin-right: 10px;
  width: 25px;
}
.chatroom {
  border-right: 1px solid lightgray;
  grid-column: 2/3;
  grid-row: 2/3;
}
.groupprofile {
  border-bottom: 1px solid lightgray;
  padding: 10px;
}
.groupsettings {
  grid-column: 3/4;
  grid-row: 2/3;
  min-width: 300px;
}
.grouptitle {
  grid-column: 2/4;
  grid-row: 1/2;
}
.his {
  background-color: lightgray;
}
.his,
.mine {
  border-bottom-left-radius: 50px;
  border-bottom-right-radius: 50px;
  border-top-left-radius: 50px;
  border-top-right-radius: 50px;
  font-size: 14px;
  width: max-content;
  padding: 5px 10px 7px;
}
.loading {
  color: lightgray;
  font-size: 14px;
  text-align: center;
}
.logo {
  border-radius: 50%;
  height: 40px;
  vertical-align: middle;
  width: 40px;
}
.messenger {
  border-top: 1px solid lightgray;
  display: grid;
  grid-template-columns: 3fr 4fr 3fr;
  grid-template-rows: auto 1fr;
}
.mine {
  align-self: right;
  background-color: #0097f7;
  color: white;
  margin-left: auto;
  margin-right: 10px;
}
.name {
  color: lightgray;
  font-size: 12px;
  margin: 0;
  text-indent: 10%;
}
.normal {
  font-size: 14px;
  margin-left: 5px;
}
.options {
  color: gray;
  font-size: 14px;
  margin-left: 10px;
  margin-top: 10px;
}
.search {
  border-right: 1px solid lightgray;
  grid-column: 1/2;
  grid-row: 1/3;
  min-width: 300px;
}

.searchbox-container {
  padding: 10px;
  box-sizing: border-box;
  width: 100%;
}
  
.searchbox {
  background-color: lightgray;
  border: none;
  border-radius: 2px;
  box-sizing: border-box;
  color: gray;
  font-size: 12px;
  padding-bottom: 5px;
  padding-top: 5px;
  text-align: center;
  width: 100%;
}
.searchbox:focus {
  border: none;
  padding-left: 10px;
  text-align: left;
}
.settings {
  padding: 0px;
}
.steve {
  display: flex;
  align-items: center;
  margin-left: 10px;
}
body {
  font-family: "SFUIText-Regular", "Segoe UI", "Helvetica Neue", Helvetica,
    Arial, sans-serif;
  margin: 5px 0 0;
}
strong {
  border-bottom: 1px solid lightgray;
  display: block;
  text-align: center;
  padding-bottom: 10px;
  padding-top: 10px;
}
<html>
  <head>
    <title>Messenger</title>
  </head>
  <body>
    <div class="messenger">
      <div class="search">
        <strong>Messenger</strong>
        <div class='searchbox-container'>
          <input class="searchbox" placeholder="Search Messenger" />
        </div>
      </div>
      <div class="grouptitle"><strong>normal group chat</strong></div>
      <div class="chatroom">
        <p class="mine">Hey man, hope everything's okay!</p>
        <p class="name">Steve</p>
        <div class="steve">
          <img
            class="avatar"
            alt="mine-craft-chara"
            src="https://i.imgur.com/R10B80x.png"
          /><span class="his"
            >All good man, those stacks of diamonds coming in hot!</span
          >
        </div>
        <p class="mine">Nice - make sure to save me some haha :D</p>
      </div>
      <div class="groupsettings">
        <div class="groupprofile">
          <img
            class="logo"
            alt="mine-craft-logo"
            src="https://i.imgur.com/vWJzAsu.jpg"
          />
          <span class="normal">normal group chat</span>
        </div>
        <div class="settings">
          <p class="options">Options</p>
          <p class="loading">Loading...</p>
        </div>
      </div>
    </div>
  </body>
</html>

Answer №2

it is recommended to include the following code in your HTML head section

<meta name="viewport" content="width=device-width, initial-scale=1.0">

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

Adhesive Bottom Navigation, Top Banner, and Full-Height Page Content

Trying to create a header, sticky footer, and content section with 100% height, but facing issues with the middle height. Below is the code and jsfiddles provided. Using HTML 4.0 strict in IE7 without the option to change. jsfiddle without 100% height: ht ...

Flask URL Error - Failed to construct URL for endpoint

Having trouble with a Python code that is supposed to retrieve data from a database. @app.route('/studentsearch', methods = ['POST', 'GET']) def searchstudent(): """ Shows the student search page on the site """ curso ...

sIFR version 3.6 - Hyperlink not functioning in Opera browser - appearing as plain text in Internet Explorer

I am experiencing a challenge with sIFR in Opera and IE. In Opera, the link is not functioning properly, while in Internet Explorer sIFR does not appear at all, displaying only regular text. This issue does not occur in either Firefox or Google Chrome. W ...

How can I integrate custom PHP pages into Odoo Community 12?

I am looking for a way to integrate my custom PHP webpages with the login page of Odoo Community that is already set up and functioning on my server. I want specific users to be redirected to my custom pages after logging in. Any suggestions on how to ac ...

The JavaScript function is not executing the Node.js code as expected

Currently, I am utilizing Twilio to send a sample message when running the provided code in the terminal: var accountSid = '...'; var authToken = '...'; var twilio = require('twilio'); var client = new twilio(acco ...

achieving outcomes beyond iframe boundaries

I currently have an IFRAME that is responsible for loading my login page. Here is the code: <iframe src="loginForm.html"></iframe> Once the form in the IFRAME is submitted, I am looking for a way to retrieve and display the results on the p ...

Display a unique button and apply a strike-through effect specifically for that individual list item

I've encountered an issue with my code that is causing problems specifically with nested LI elements under the targeted li element: $('#comment-section .comment-box a#un-do').hide(); $('#comment-section ul li[data-is-archived="true"]& ...

Ways to stop a ngFor loop in TypeScript

I'm currently working on a Hybrid app using Ionic-3. I have a function in my Typescript file that is being called from the Html, but it seems like the function is being executed multiple times causing my browser and application to hang. Below are the ...

Basic JavaScript code for converting text input in an HTML textbox. Fails when attempted a second time

When using the replace method, I've noticed that only the first occurrence of "test" is being converted to "good" when I input "test test". Can anyone explain why this is happening? Also, if I wanted to replace 20 different words, would I need to crea ...

Need help setting up automatic audio playback on your Android device?

I'm aware that autoplay of audio is not supported on Android devices. However, I recently found a website that successfully autoplays music on an Android device: Can someone explain how this is being achieved? ...

Accessing variables from child controllers with populated select inputs in Angular

I'm currently facing an issue involving 3 controllers: Parent Controller: DocumentController Child Controller1: XdataController Child Controller2: CompanyController The child controllers are used to populate data in three Selector inputs on the fron ...

Angular 4.3 - Best Practices for Utilizing Enums in a Nested Component

Today, I encountered an issue trying to access the selected value from an enum in my contact.component file. This enum is a part of a form. Here is how I set up the enum: contact.component.ts (extract of relevant code only) import { Component, OnI ...

Change the font style of individual characters within a string using CSS or JavaScript, instead of applying it to the entire

Is it feasible to assign a specific font to a particular character? I would like: #test_id{ font-family: "digitalfont"; font-family-of-, : "HelveticaNeue-Light"; } In order to set a font for a comma and a separate font for the rest, do I need to ...

Simply drag your files onto the form for quick and easy uploading upon submission

Would like to know how to enable drag-and-drop file selection for uploading files synchronously upon form submission. Understanding the basics of file uploading using HTML and PHP, I am seeking a way to process these files in PHP along with those in the $_ ...

Collecting, gathering content repeatedly

Hey there, just checking in. I'm currently working on extracting information related to CEO Pay Ratio and compiling links to this section for processing by a function. My goal is for the function to capture content starting from a specified tag and en ...

Tips for positioning cards in html

I'm working on a layout with a container containing multiple cards. I want each card to align from the left border of the container to the right border, similar to the code snippet below. <html> <style> .container { display: flex; ...

Is there a way for me to customize the WordPress image page layout?

Whenever I upload images to WordPress, I notice that I can easily click on "View" while hovering over the images. This takes me to a page with a permalink that uses the image title as the URL and follows the default post format. Surprisingly, these image ...

The Typewriter Effect does not appear alongside the heading

For my portfolio website, I am using React to create a unique typewriter effect showcasing some of my hobbies. Currently, the code is set up like this: "I like to" [hobbies] However, I want it to display like this: "I like to" [h ...

Having trouble removing a DOM element with jQuery?

Hey there, I need your help with a jQuery issue I'm facing. I am currently working on cloning a div element that contains a span with a click event attached to it. The purpose of the click event is to remove the newly cloned section from the DOM. Whil ...

Tips for incorporating AngularJS with dynamically added elements

Essentially, I have a structure similar to this example The formula for every cell in the last column should be: value[i][2] = value[i-1][2] + value[i][0] - value[i][1] I'm currently facing two issues. The first one arises when attempting to progra ...