Shifting a div's position to a different div upon resizing - a simple guide

Current Situation :

  • I currently have two div. One is for the title and the other is for the form section.
  • However, when I resize the screen on mobile devices, the layout does not look correct.

Objective :

  • My goal is to adjust the left margin of the div containing the title and the form section when resizing the screen. Essentially, aligning the left margins of both divs.

Any suggestions on how to resolve this issue?

Answer №1

Ensuring accuracy, it appears that the intention is to position the title above the form when viewed on a mobile device. This can be achieved effortlessly through media queries. Refer below for guidance: W3Schools | Media Queries

<div id="div1"></div>
<div id="div2"></div>

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

     .div 2 {
        display: block;    
     }
}

.div1 {
   display: inline-block;
   width: 40%;
}

.div 2 {
   display: inline-block;
   width: 40%;
}

Media queries offer versatility as they allow for dynamic application of styles such as changing the display property of the divs to 'block' (occupying the full width of their container) rather than aligning them side by side and taking up only 40% of the container. If necessary, please submit a markup for further evaluation.

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

HTML5 elements expand to fit the dimensions of the window

While creating an HTML5 page, I observed that div elements without specified widths within sections like "header" and "footer" only occupy the width of the window. For instance: <header> <div id="header-background" style="background: #ddd"> ...

Enhancing an element with a modifier in CSS using BEM conventions without the need for @extend

Trying to grasp the best method for writing BEM modifier rules within parent classes. I've utilized SASS's @extend but question if this is the right approach. For example: If there is a class called .form structured like this: <div className= ...

The Bootstrap 4 Accordion feature ensures a smooth scrolling experience without jumping to the

Are you in need of assistance? If so, I have developed a Javascript code that enables an accordion card to scroll to the top when clicked on to expand. Provided below is an example of a Bootstrap 4 accordion along with the associated Javascript snippet: ...

Manipulate image position with touchmove event using CSS3 transformations on an iPad

Looking to adjust the position of an image on my iPad3, but running into some difficulties. The movement isn't as smooth as desired and seems to lag behind the gestures being made. This is what I have so far (a 3MB base64 image) <img src="data:i ...

Display or conceal <ul>'s using JavaScript when the mouse enters or leaves

I'm encountering an issue with a basic JavaScript function. The goal is to toggle the dropdown menu on my website when the mouse hovers over or leaves the menu. The problem arises because my script is triggered by the ul tags within my menu, and I ha ...

How to Make a Div Tag Fade Effect with JavaScript in an External File

*** New Team Member Notice *** I'm currently working on an assignment and trying to implement a simple fade effect on a box. While it seems like this should be straightforward, I'm encountering some obstacles. Currently, the button causes the bo ...

Display two lists of models categorized by time

I have two lists of model types that are initialized in the controller and values are inserted into them. These list objects are then assigned to ViewData so that I can iterate through them using a foreach loop. However, the issue is that the models of the ...

Clear validation messages upon closing Bootstrap modal in Laravel 9

I am currently working on a Bootstrap modal that contains form inputs. I have implemented jQuery validation to validate the form upon submission. However, I encountered an issue where the validation messages persist even after closing and reopening the mod ...

Chrome not displaying Bootstrap dropdowns correctly

Lately, I've been exploring Bootstrap and experimenting with its dropdown menus. Typically, I use Chrome for my work but encountered a strange issue with how Chrome is handling my dropdown menus. This forced me to temporarily switch to Edge. Here&apos ...

Is there a way to incorporate a transition delay for the text-align feature?

Is there a way to change the text-align property of an input field only after its width transition is complete? I've tried using a transition delay, but it didn't work. How can I achieve this effect? div { height: 3rem; width: 100%; backgr ...

Implementing Enter key functionality to add items to a Todo list using pure DOM manipulation

var listLis=document.getElementById('list'); const addbutton=document.querySelector('.fa-plus') const inputBar=document.querySelector('.show') function showInput(e){ inputBar.classList.toggle('show') } addbutt ...

Tips for arranging left and right elements in a row of three items?

Adding a second Header (from react-native-element 3.4.2) to a React Native 0.70 app involves placing it under the first Header, with its centerComponent pointing to a search bar that spans only one line. Below is the code snippet: import { Header } from &a ...

The reasons behind the unsightly gaps in my table

Here is the HTML code snippet: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <script type='text/javascript' src='js/jquery-1.10.2.min.js'></ ...

Creating line breaks in Bootstrap input group formatting

My issue involves rows with checkboxes and labels, some of which are longer than others. When the browser is resized or viewed on a mobile device, the columns containing longer labels collapse to a second row while shorter labels stay beside their checkbox ...

What exactly does this jquery library aim to achieve?

Recently, I discovered a new library for CSS3 animations. As someone who is still learning JavaScript, I am unsure of the benefits it offers. It appears to replicate what jQuery can already achieve but by utilizing CSS3. So, what advantage does using a to ...

Can a border not be added to a <tr> in an HTML table using CSS for any specific reason?

I am facing an issue with the borders of a table row (tr) when applying CSS styling. The tr has a class called "underRow" which is supposed to add a border at the bottom. In my CSS, I have defined the following for the ".underRow" class: .underRow { ...

Implementing multiline ellipsis without relying on -webkit-line-clamp

Content is dynamically loaded in this p tag. I am looking to implement text ellipsis after a specific line (for example, show text ellipsis on the 4th line if the content exceeds). p { width: 400px; height: 300px; text-align: justify; } <! ...

I'm noticing that when I refresh the page, my inputs seem to disappear from the page, yet I can see that they are saved in the console's local

If anyone can help me with this issue I'm facing, I would greatly appreciate it. My aim is to retain values in the text box along with local storage even after refreshing the page. Here is an example of the code I am working with: Link to my web appl ...

Horizontal navigation bar encroaching on slideshow graphics

I'm encountering difficulties aligning the horizontal menu below the image slider. When I have just an image without the slider, the menu aligns properly (vertically), but as soon as I introduce the code for the slider, the menu moves to the top and d ...

What are the recommended steps for successfully integrating a Bootstrap 4 Split Navigation?

Wanting to improve the coding for a BS-4 split navigation. Ideally, looking to have only one instance of each link but struggling to figure out how to achieve it. Check out the code here <nav class="navbar navbar-expand-md navbar-light" style="backgro ...