On mobile, three divisions that are initially set to occupy 33.33% of the width each will expand to 100

I have a good handle on accomplishing this using JavaScript, but I'm now curious if there is some clever CSS trick that can achieve the same result. My goal is to have each div take up the entire screen when viewed on a mobile device. Below is what it currently looks like.

https://i.sstatic.net/epYMm.png

Below is the CSS code for each div:

.center{
  background-color:#ffffff;
  width:33.33%;
  height: 100%;
  display: inline-block;
}

.left{
  background-color:#ffffff;
  width:33.33%;
  height: 100%;
  float:left;
  overflow: hidden;
}

.right{
  background-color:#ffffff;
  width:33.33%;
  height: 100%;
  float:right;
  overflow: hidden; 
}

Answer №1

To determine the width at which you want the divs to occupy the entire screen, make use of media queries to apply different styles. You can refer to this guide on media queries for more information. Another approach is to follow the example set by Bootstrap.

Here's a simple demonstration using a 600px wide breakpoint:

@media (max-width: 600px) {
  .mybox {
    width:100%;
  }
}

Answer №2

There are certainly some 'stylish' techniques in CSS that you can utilize for the same purpose. One option is to incorporate the Bootstrap library to ensure your HTML is responsive. For more information, you can visit: http://getbootstrap.com/

Additionally, CSS media queries can help achieve a similar outcome. You can explore this concept further here: https://www.w3.org/TR/css3-mediaqueries/

Identify the resolution you desire and implement the appropriate CSS.

@media (min-width:320px)  { /* smartphones, iPhone, portrait 480x320 phones */ }
@media (min-width:481px)  { /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */ }
@media (min-width:641px)  { /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ }
@media (min-width:961px)  { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }

Answer №3

@media only screen and (max-width: 600px) {
    .center,
    .left,
    .right {
        width: 100%;
    }
}

When the screen width is less than 600px, the divs will stretch to 100% width.

Feel free to adjust the max-width value to suit your requirements.

Answer №4

If you want to implement conditional formatting using CSS, consider utilizing media queries. While there isn't a specific media query for mobile devices, you can still establish a maximum width as a workaround. Here is an example:

@media only screen and (max-width: 600px){
    ...
}

By doing this, any device with a screen width less than 600px will receive the specified CSS properties inside the ....

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

How can I ensure the carousel stays centered on a webpage even after resizing the browser window?

Currently in the process of developing a website, I have implemented a jquery-based carousel on the homepage sourced from here. However, substantial modifications were made to tailor its appearance specifically for the site. The issue at hand is that I hav ...

Maintain Bullet and Arrow Size with JSSOR Scaling Feature

I am currently utilizing the jssor image slider with jquery and overall, it is functioning well. However, I have encountered an issue when attempting to resize the slider. My goal is to dynamically resize the slider whenever the window width changes. The ...

Strange circle border appearance in Android / Chrome device

Having an issue with my code on a Samsung Galaxy S5 in Chrome 54.0.2840.85, Android 6.01. You can view the problematic codepen here: http://codepen.io/johnsonjpj/pen/jVpreB The border displays correctly on Firefox and iPhones, but not on my device. Trou ...

Merging distinct objects/values in AngularJS/Javascript to create a straightforward list

I possess a dynamically generated, multi-level nested object containing DISTINCT values. My goal is to flatten it (using either AngularJS or vanilla JS) and produce a straightforward array or object for each key/value pair. For example, if the object takes ...

What is the best way to add content to the ajax success code?

For my project, I have a lot of content in the success function of AJAX. I plan to move this content to a file called textcsc.js and use the include() method in AJAX. Initially, the code was working successfully: $(document).ready(function() { $(&apo ...

Auth0 Angular - No routes found to match

I recently set up an angular application and integrated it with Auth0 by following two helpful tutorials: https://auth0.com/docs/quickstart/spa/angular2/01-login https://auth0.com/docs/quickstart/spa/angular2/02-calling-an-api Here is a brief overview o ...

Tips on resolving duplicate items in dynamic loading pages through the use of jQuery

I need help resolving the issue of duplicate objects in dynamically loaded content. Please refer to the code below for a better understanding. Initial HTML Page With Dynamic Content <body> <div id="general-div"></div>> ...

What is the best method for deleting scripts to optimize for mobile responsiveness?

My current plugin.js file houses all my plugins for responsive design, but it is unnecessarily large and cumbersome for mobile devices. I am considering creating two separate plugin.js files to toggle between for mobile and desktop views. What are the r ...

What is the method for adding data to a table without utilizing an ID field?

Here is the code I have written: This table contains details of the candidates: <table id="candidates-table" class="table table-striped table-bordered"> <thead class="thead-dark"> <tr> <th scope="col">Candidate Picture ...

"Is there a method to make the height of one column in bootstrap equal to the combined heights of two columns

Looking to design a layout using bootstrap where I require one column to appear as two columns stacked vertically. To get a clearer idea, it would be beneficial if you could refer to the visual representation provided below. Additionally, I need it to be r ...

Crafting an interactive form

Creating a form with 2 options (Yes/No) is my current task. When the user selects one of these options, I want a collapsible subform to appear with specific details related to that selection. If the user chooses the other option, a different collapsible su ...

How to successfully incorporate Google fonts into an HTML email for Outlook

Hey everyone – I've come across multiple websites discussing this issue, but I'm still struggling to get it right. I'm trying to incorporate a Google font (specifically, Fira Sans) into an HTML email so that it shows up correctly in Outloo ...

Issue with Framer Motion Modal: Animation presence fails to function

Currently, I am facing an issue with the exit animation of a modal created using framer motion. While the initial animation on opening the modal works perfectly fine, the exit animation fails to trigger and the modal disappears abruptly without any transit ...

Sending a Boolean value from a child component to its parent state in React JS

Within my application, I have implemented a login feature in the navbar component. However, I am encountering an issue with updating a variable in the main component upon successful login. Although I have successfully managed to set up the login functional ...

What is the reason behind my resizer bar not changing color to green?

Whenever I resize the bar between the West and Inner Center areas, it turns green. However, the bar between the Inner Center and Inner South areas does not change color. How can I make it turn green when resizing, including adding the orange highlight for ...

Steps for executing a Python CGI script using an XMLHTTP request

My code includes a button that triggers a javascript function called loadXMLdoc() upon being clicked. This function is designed to create an XMLHttpRequest and send a request to a .cgi script I wrote in Python. Despite my efforts, the .cgi script fails to ...

What is the best method to retrieve child elements from a class list object?

Seems like I have a similar content class <div class="parentclass"> <div class="childClass"> </div> <div class="childClass"> </div> <div class="childClass"> </d ...

Is there a way to insert a JavaScript variable that depends on the React state into another variable through interpolation?

I have a React component that is fetching data from a file containing images, copy, and other necessary information for the application. The challenge I'm facing lies in the syntax - how can I access this data based on the component's state? dat ...

Ways to halt the setInterval function after executing a specific function within it

Currently, I have a condition in place to verify if I am on a specific URL. If this condition is true, the setInterval() function will begin checking for a particular element on the webpage. Once the element is located, a designated function will be exec ...

Error: The 'encoding' property cannot be set on null objects in THREE.js

I have been trying to load a basic grass block from Minecraft, but I keep encountering an error message that says TypeError: Cannot set properties of null (setting 'encoding'). This error originates from line 2893 in GLTFLoader, specifically the ...