Position the div to float on the right side and then have it drop below on smaller screens

I'm currently working on implementing a design effect similar to the one shown below:

on my website (), but I'm struggling with getting the HTML and CSS just right. When I move the map to float up on the right side, it doesn't drop below the text when the width is reduced. I've tried different approaches but haven't found the perfect solution yet. Any suggestions would be greatly appreciated. Thank you!

EDIT - Apologies for the lack of information in my initial post. I am using a responsive layout (WP Twenty Thirteen theme). If I set the text div to float: left and the map iframe to float: right, the text div takes up the entire width, causing the map to drop down. I want the text div to resize along with the window without setting a specific width. (I prefer not to have to adjust the map's dimensions as well by using percentage widths.)

Placing the iframe first in the HTML code keeps the map at the top without specifying a width (similar to the first three frames in the illustration), but then it doesn't drop below the text. To achieve the desired effect in the last frame of the GIF, I had to move the iframe back below the text.

Is there a way to achieve what I want without defining a width for the text div? If not, I might have to settle for the map resizing accordingly. However, I'd prefer to avoid that solution if possible.

Answer №1

Implement @media queries in your code like so:

.sidebar { float: right; }
@media (max-width: 600px) {
   .sidebar { float: none; }
}

This CSS will adjust the styling of the .sidebar class based on screen size. When the screen is 600px or smaller, it will remove the float property, and for larger screens, it will keep the float set to right. You can customize the breakpoint value as needed.

Answer №2

JSFIDDLE

To style the left block, apply the following CSS:

float:left;
width:50%;

The current width is set to 100% automatically, so you need to separate the content as 50% on each side.

Next, for the container block, clear the float by adding:

 display:inline-block;

Answer №3

Instead of requesting the answer outright, seek guidance on how to approach the problem using your existing code.

Your goal is to design a responsive layout. This can be accomplished by incorporating media queries within your CSS. Here's an example:

@media (max-width: 990px) {
    .sidebar {
        float: left;
    }
}

There are three main methods to achieving your desired outcome:

  • Build your layout from scratch
  • Utilize a grid system
    • Responsive Grid System
    • Check out the Best Responsive CSS Grid Systems for Your Web Designs
    • Explore the 34 Responsive Grid System
    • Discover more about the Responsive Grid System
    • Learn about the Golden Grid System
    • ...
  • Consider using a web tool
    • Check out Responsive Web CSS

You have the freedom to choose which approach suits you best. However, sharing a fiddle or some code snippets would enable us to provide more tailored assistance. ;)

Answer №4

It appears that the content area div in question lacks a specific identifier, causing it to adopt the styles of its neighboring divs. Assigning it a name and specifying a fixed width with a float-left property should resolve this issue and correctly position the map on the right side automatically.

Answer №5

To position both elements side by side, use the float property with a value of left. Specify percentage widths for better control over element widths, such as width: 50%;

Here's a simple example:

Check out this demo - Demo Link!

Update - Updated demo with more text - Updated Demo Link!

HTML

<div id="text"></div>
<iframe></iframe>

CSS

#text {
    width: 50%;
    height: 200px;
    background: #CCC;
    float: left;
    min-width: 200px;
}
iframe {
    width: 200px;
    height: 200px;
    background: #333;
    border: none;
}

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

Unable to modify the focus outline for .custom-control-input within Bootstrap 4

After spending countless hours attempting to change the focus outline color of the custom bootstrap controls, I have hit a roadblock. Changing the background is a breeze with: .custom-control-input:checked~.custom-control-indicator { background-color: re ...

What is the method for extracting JavaScript code as data from a script tag?

I have a file external (let's say bar.js) function qux() {} Then in my webpage, I include it using the script tag: <script type="text/javascript" src="bar.js"></script> I am looking for a way to retrieve the JavaScript code from within ...

What is the best way to align a search box within a Bootstrap navbar?

Seeking assistance to center the search box within my Bootstrap navbar without disrupting alignment. I am aiming for a similar look as seen on linkedin.com. Any suggestions on how to achieve this? Here is a JSFiddle link to my navbar: https://jsfiddle.ne ...

Is there a way to set the size of my unique carousel design?

Having some trouble with my modal image carousel; the dimensions keep shifting for different image sizes. Image 1 Image 2 ...

What causes the width of input fields to increase as more inputs are added in flexbox?

I'm working on a form that consists of multiple sections, each with varying numbers of input fields. I've noticed that when I apply display: flex to the parent div and set the input fields to 100% width, the widths are calculated differently depe ...

Ways to position a single item in the middle of a multi-column layout

I need help with aligning dynamic images in a 2-column layout. What's the best way to center a single image or collapse the columns when there's only one image? Currently, the single image is always placed in the left column. Is there a CSS-only ...

Keeping the scroll in place on a Bootstrap4 modal while scrolling through content that is already at the top

On my Bootstrap 4 modal, I have encountered an issue with scrollable content. When I am at the top of the content and try to scroll downwards, nothing happens because I am already at the top. However, if I continue to hold the touch without releasing it, t ...

Text within cells is not wrapping onto a new line in an HTML table

Let me show you how it currently looks: https://i.sstatic.net/OeHRg.png The maximum width of the cell is working properly, but the text is not wrapping to a new line as expected. Instead, it overflows out of the cell. Here is the CSS applied to the tabl ...

`Implementing a dynamic list with image and button using Bootstrap 5`

I've been exploring ways to create a container with 4 images aligned next to each other, accompanied by a button beneath each image. My goal is for the layout to be responsive, meaning that as the screen size adjusts, the elements inside should also a ...

What is the best way to maintain scrollbars on mobile devices?

I'm currently building a cross-platform application using Angular 4 that needs to work seamlessly on both mobile and desktop devices. Is there a special trick to prevent the scrollbars from disappearing when viewing this page on a mobile browser? I&ap ...

Dynamic drop-down navigation with rearranging menu

I am attempting to design a drop-down navigation bar with 2 rows. Initially, only 1 row is visible. Upon clicking the visible row, both rows should appear. Subsequently, when one of the 2 rows is clicked, only that specific row should be displayed. Below a ...

What is the best way to arrange these badges in a row?

I'm struggling to horizontally align these badges next to each other, as inline-block isn't working and they keep stacking vertically instead of side by side. How can I achieve the alignment shown in the image below? This is the desired appeara ...

The issue of CSS3 Grid-gap not functioning properly on iPhone devices

I've been working on creating a CSS template and everything seems to be functioning correctly, except for the grid gap which doesn't seem to work properly on my iPhone. Here's the code I have so far: <div class="grid"> <h1 ...

Can we utilize conditions to both select and deselect items using JavaScript and PHP together?

I have a selection list with checkboxes that is dynamically generated based on certain conditions in the code snippet below. if ($data_inteiro_01 <= $data_inteiro_02) { if ($parcela[$i] === 0) { $display = 'disabled'; } } els ...

container dimensions for images

Is there a way to make an image adjust its size according to the container? For example, if the container is 100x100 pixels and the image within it is 90x80 pixels, can we make sure that the smaller property of the image (height in this case) adjusts to f ...

Display only distinct items in a v-for loop in Vue.js

I am attempting to show icons based on specific v-for and v-if conditions. However, the icons are appearing multiple times when I only want them to display once. I attempted using v-if = 'index === 0', but this did not resolve the issue. <di ...

Displaying PHP errors in input fields

I have noticed that this particular code is functioning correctly. However, I am wondering why I receive an error when I remove the foreach loop ($rows as $row). Is there a method to display the data without utilizing it? <?php require("coneccion.php ...

Managing websites on Android when the keyboard is displayed

I am currently facing an issue with my webpage on Android (Galaxy SIII). The problem occurs when visitors try to enter their email in the form at the bottom of the page. The keyboard becomes visible, causing the design to look messy. When using Chrome, the ...

Expansive dropdown menu stretching across the entire width, yet the content within restricted to a width of

I have recently made some updates to our website's dropdown menu, expanding the results displayed. However, I would like the dropdown contents to fit within the width of our page. https://i.sstatic.net/aR0Qm.jpg https://i.sstatic.net/e61Ig.jpg I ha ...

Blog entries alternating between a pair of distinct hues

I want to create a design where each post container has a different color from the one next to it. Essentially, I would like the containers to alternate between two distinct colors. The left side shows how it currently appears, while the right side depict ...