Using the "position: absolute" property will not contribute to the

I am facing an issue with aligning two div elements inside a parent div. Currently, they are rendering side by side:

<image><info>

However, on smaller screens, I want them to render one under the other and swap positions, like this:


<info>
<image>

In reality, their order in HTML is


<info>
<image>

Both of these elements have float:right applied to them so that they appear swapped and side by side. When the screen size decreases, I remove the float properties and they stack vertically as intended. I followed Shlomi's solution from here and it works perfectly.

The problem arises when I try to align the div elements to the left horizontally. Due to the float:right, they end up aligning on the right instead.

I attempted to give the container position:relative and the children position:absolute, allowing me to use left:0; and right:0. However, this caused the container to have zero height and resulted in a vertical scrollbar appearing. If I remove the position:absolute, the layout returns to normal but without the desired left alignment.

My current code snippet is as follows:

#container{
    width: 100%;
    height: auto;
    display: block;
    margin-top: 30px ;  
    padding-bottom: 38px;
    clear: both;
    overflow: auto;
    position: relative;
}

#image{
    display: block;
    height: 221px;
    width : auto;
    float: right; 
    margin-right: 20px;
    position: absolute;
    clear: both;
    overflow: auto;
}

#info{
    width:-moz-calc(100% - 331px);width: -webkit-calc(100% - 331px);width: calc(90% - 331px);    
    height: 500px;
    display: block;
    float: right;
    position: absolute;
    clear: both;
    overflow: auto;
}

Answer №1

You could potentially utilize

float: left;

as an alternative solution :)

Take a look at the updated fiddle by Shlomi :

https://jsfiddle.net/sk99xqdd/4/

I'm not certain if this addresses your inquiry ...

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

Ensuring consistent readability in Bootstrap 4 by wrapping text without affecting the height

Referenced from: Twitter Bootstrap Button Text Word Wrap Is there a way to adjust the word wrap of text inside a button in bootstrap 4 without changing the height, or maintaining equal height for all buttons? For example: <div class="container"> ...

React Scroll and Material-UI button active link not functioning correctly

Whenever the link goes to the correct page, I want to add a special background effect or change the font color. Despite trying to use CSS for this purpose, it didn't work as intended. If you want to take a look at my code on codesandbox, follow this ...

How can I vertically align content in Bootstrap 4 without causing horizontal overflow on mobile devices?

Struggling with my registration page on the login form - I've utilized Flex and Vertical Align classes from Bootstrap 4 to center my div vertically. Works great on tablets and larger devices, but encountering an overflow issue on mobile devices: http ...

Unable to trigger click event after slider is modified

One of the tasks at hand is to change the image/div margins in a slider upon click. Change the image margin in the slider Adjust text opacity in the top section of the slider Initially, the code operates as intended when the page first loads for the firs ...

Scrollable container with jQuery draggable functionality

I am currently working on implementing a draggable list that I want to contain within a scrollable div. $( ".draggable" ).draggable(); Here is the fiddle I have created for this: http://jsfiddle.net/YvJhE/660/ However, the issue I am facing is that the ...

Implementing a fixed search bar in Angular for a dropdown selection using mat-select

I'm currently utilizing a mat-select widget from Angular-Material in my application To enhance user experience, I am adding a search bar at the top of the select dropdown for filtering options: <mat-select placeholder="Select a store" ...

All hyperlinks are displayed as a single entity

I have 5 image links displayed side by side, but when I hover over them, they act as one collective link. Can someone please assist me with resolving this issue? After updating my code to include the entire div, it seems that there is something within the ...

What is the best way to define a margin according to the size of the device being used

I am working on an angular/bootstrap web app and need to set a left margin of 40px on md, xl, lg devices and 0px on sm device. I attempted to create a spacer in styles.scss like this: $spacer: 1rem; .ml-6{ margin-left:($spacer*2.5); } Then in my HTML, ...

Ensure that the Div element is able to wrap lines in the same way that the Span element

Is there a method to ensure that a div element wraps the lines similar to how a span does? JSFiddle for testing In this example, I utilized the span tag to create an appearance as if the text was highlighted by a yellow highlighter pen. Everything functi ...

What steps should I take to correct the alignment of this grid using CSS?

I'm currently working on creating a grid layout for my website and I've almost achieved the desired result. However, I'm facing an issue with the size of the "Projects" title within the grid. I want it to stand out and be larger compared to ...

The slideshow feature on W3 Schools does not start automatically when the page loads

After following the W3Schools tutorial to create a slideshow, I found that the animations are working correctly. However, only three dots appear on the screen and I have to manually click on one of them to view the pictures. var slideIndex = 0; sh ...

Alignment of containers on the same level in a horizontal direction

Looking to achieve horizontal alignment of div containers. The container on the left (with a blue border) may have a fixed height. The other two containers (with red borders) should be aligned horizontally to the left blue container regardless of its heigh ...

Is there a way to place two input fields from different forms side by side on the same line?

Here are two forms extracted from an html page: <form method="get" action="search/s" id="number"> <div style="text-align: center;"> <input type="text" id="regNo" name="regNo" size="30" maxLength="50" > or ...

Tips for applying a CSS wrapper to an element, not just text

I am working with a group of span elements within a td that has a set width. My goal is to wrap the span elements onto new lines without breaking up the text inside them. For example, if I have: <td> <span>bind</span> <span&g ...

Bootstrap: White space can be seen on the right side of the mobile screen, with an incomplete nav bar

My website, built with Bootstrap, functions properly on desktop and in landscape mode on mobile. However, it encounters issues in portrait mode on mobile where white space appears on the right side and part of the navigation bar is missing. Below is the c ...

styled-components: the parent's styles take precedence over the child's styles

image export const LogOutButton = styled.button` display: inline-block; .... `; export default styled(ThemedApp)` .... button { .... display: flex; .... } `; Upon inspection, it is evident that the Logout button (with class gBuhXv) ...

Error encountered when compiling LESS files

As a beginner in LESS, I am facing a situation where I have a less file and I am utilizing PHP to pass variables to the LESS file for compilation. The less file contains numerous variables, and each time I pass values via PHP, they may differ. There are in ...

Adjusting the size of HighCharts HighMaps with a custom function

Simple query here (I believe) I have a DIV with the class "container" acting as my Map. The Highcharts plugin I'm using is responsive, but it only resizes when the window does. I'm looking to manually trigger a resize without adjusting my windo ...

What is the process for adjusting the checkbox border color in Material Design 15 and above?

Ever since the latest update to Angular Material 15, I've noticed some changes in how styling is applied to Angular Material components. Previously, in version 14, I used to be able to accomplish styling changes with code like this: ::ng-deep .mat-che ...

How to use jQuery to center an overlay on a webpage

Need help with centering a jquery popup on a webpage? I'm struggling with positioning it in the middle of the page, regardless of site adjustments or resolution changes. Currently, I have it set to absolute positioning with CSS, but the issue is that ...