Designing websites using elements that float to the right in a responsive manner

Responsive design often uses percentage width and absolute positioning to adjust to different screen sizes on various devices. What if we explore the use of the float right CSS style, which is not as commonly used but offers high cross-browser compatibility?

Demo: http://jsfiddle.net/3A89Q/48/

.wrapper { width: 70%; margin: 0 auto; }
div, span { display: block; float: left; position: relative; }
.wrapper > div { width: 60px; }
.b1 { background-color: blue; height: 132px; }
.b2 { background-color: red; height: 88px; }
.b3 { background-color: green; height: 44px; }
.test { background-color: black; max-width: 160px; min-width: 100px; float: right; border: 2px solid black; }
.test div { width: 16px; height: 16px; background-color: yellow; margin: 2px; }


<section class="wrapper">
    <div class="b1"></div>
    <div class="b2"></div>
    <div class="b3"></div>
    <span class="test">
        <div></div>
        <div></div>
        <div></div>
    </span>
</section>

My innovative approach involves resizing a right floating element to a minimum width without relying on percentages. This resizing occurs only when neighboring elements limit the available space for the element as the window width decreases. The element will expand to a maximum width if there are no restrictions on its available space. Essentially, the element has a range of flexibility in size with specified minimum and maximum widths. (To visualize this width range, try shrinking the results window in the linked jsfiddle demo.)

Currently, if the right floating element collides with a left floating element, it drops below while maintaining its maximum width.

My desired outcome is for the right floating element to shrink to its minimum size before dropping down beneath its neighbor. Once at the minimum size, it would expand to fill the remaining space up to its maximum width after moving below the neighbor. It should continue this adaptive process while floating right.

My query is whether these desired outcomes can be achieved solely using CSS/CSS3. If not, is there a JavaScript/jQuery plugin that can accomplish this functionality? I have provided a link to a jsfiddle demo above for reference and assistance.

Thank you for your support.

Answer №1

Ever considered employing CSS media queries to target various screen sizes?

Take a look at this useful resource.

One approach using jQuery involves utilizing a resize event handler to adjust the CSS as needed whenever the browser window is resized. Alternatively, you can dynamically calculate widths and heights on document ready.

Check out this Stack Overflow solution Using jQuery To Get Size of Viewport

Here's another helpful link for reference.

http://api.jquery.com/resize/

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

Determining the best CSS based on the user's preferred color scheme using media queries

Is it possible to separate my CSS into two files, one for dark mode and one for light mode, and conditionally load them using only HTML without the need for JavaScript? I haven't been able to find any examples on https://developer.mozilla.org. Could ...

Troubleshooting Compatibility Issues: JavaScript Function Works in Chrome but not in Internet

After collaborating with fellow coders to develop info boxes using HTML, CSS, and JavaScript, I have come across an issue with the hover functionality not working properly in Internet Explorer. Interestingly, everything functions flawlessly on Google Chrom ...

Navigate to the middle of the visible area

Is there a way to automatically center a div when it is clicked, so that it scrolls to the middle of the browser viewport? I have seen examples using anchor points but I want to find a different solution. Any ideas on how to accomplish this without using ...

Elements separated by empty space on a Complex Grid, appearing distant despite the available space

Struggling with creating a complex layout using minimal relative and absolute positioning. Here's the issue I'm facing: All my elements are aligned side by side with only one problem: the border image needs to bleed into the row below. How can t ...

Can you explain the purpose of jQuery's event.detail property?

When handling the click event on a button, I noticed that when the button is clicked, e.detail = 0. However, if I press enter inside a textbox and somehow trigger the button click event (asp.net), e.detail = 1. I searched through the jQuery documentation, ...

implementing a fixed header in HTML

I am facing a challenge where I have a header with dynamic height and fixed position. My goal is to position the container div right below the header. However, since the header height varies, using a fixed value for margin-top is not feasible. Any sugges ...

Eliminating the default inline style automatically

My goal is to hide a table row until a radio button is clicked. I attempted using display:none;, but it did not work. Upon inspecting the code in my developer tools, I noticed that the specific table row has a style attribute style="display: table-row; whi ...

How can you ensure that the execution of your code only moves forward after the successful completion of asynchronous requests in jQuery Ajax

I'm facing a challenge in optimizing the speed and functionality of my Ajax requests. Here's a snippet of the code I've been working on: function fetchData(dataArray){//dataArray is an array containing roughly 10 elements var resultArr[]; ...

What makes fastify-plugin better than simply calling a regular function?

I recently came across a detailed explanation of how fastify-plugin operates and its functionality. Despite understanding the concept, I am left with a lingering question; what sets it apart from a standard function call without using the .register() metho ...

Different ways to update the AutoComplete Style attribute

MuiInput-formControl { margin-top: 16px; Is there a way to reset the marginTop property to zero? I attempted the following method, but it was not successful. MuiFormControlLabel: { marginTop: 0, }, <Autocomplete disabl ...

Is it possible to show more than five buttons in an Amazon Lex-v2 response display?

Here is the sessionState object I am working with: { "sessionAttributes": {}, "dialogAction": { "type": "ElicitSlot", "slotToElicit": "flowName" }, "intent": { "name": &q ...

The hit detection algorithm seems to be malfunctioning, and the reason behind it is unclear. (Using Javascript/Processing

I am a beginner in game programming and programming in general. In the past, I have created a clone of "Flappy Bird" and some other games using the hit detection algorithm from the Mozilla Developer Network here. Currently, I am facing an issue while tryi ...

What would be the best way to structure this workflow as a JavaScript data format?

I have a complex workflow that I need to represent as a JavaScript data structure. This workflow involves a series of questions and answers where the response to one question determines the next one asked. Here is a basic example of what this workflow migh ...

Enhancing Game Security through PHP and jQuery

I am currently developing a game using PHP and jQuery, but I am facing some security issues. The game involves typing combinations correctly, and when the player does so, jQuery sends an ajax request to PHP which then adds 10 points to their session. Below ...

The bullets in the HTML unordered list are partially hidden from view

My unordered list is experiencing issues with displaying bullets correctly. In Firefox and Internet Explorer, the bullets are only partially shown, while in Chrome they are not visible at all. Adding margin-left: 5px to the <li> element resolves this ...

Checking for the existence of a row in Node.js using Sqlite3

Wondering if it's possible to verify the existence of a row using node.js and the sqlite module. I currently have this function in place, but it always returns false due to the asynchronous nature of the module. function checkIfRowExists(username, pa ...

Why is my console showing a SyntaxError with JSON.parse and an unexpected character?

I am facing an issue. When I attempt to call a PHP page for some data with specific requested parameters using AJAX asynchronous call, I encounter the following error: SyntaxError: JSON.parse: unexpected character var jsonData = $.ajax({ u ...

The issue I'm facing with Angular 8 is that while the this.router.navigate() method successfully changes the URL

As someone who is relatively new to Angular, I am currently in the process of setting up the front end of a project using Angular 8. The ultimate goal is to utilize REST API's to display data. At this point, I have developed 2 custom components. Logi ...

Perform encryption and decryption of a JSON file on separate webpages

Situation : Is there a way to encode JSON data in the getuser.php page and then decode it in index.php? In my getuser.php file, I use echo (json_encode($data)); which produces the following example output: { "id": 2, "username": "Teeto", "sur ...

Extracting the name of the file from the image's web address

I have created a simple Chrome extension for personal use and sharing with friends. I am dealing with URLs that have various formats, such as: i.imgur.com/abcd123.png or imgur.com/a2b3c78 or even i.imgur.com/herp321.png?1 All I need from these URLs are t ...