Is it possible to incorporate this design in a way that is responsive?

Can you share your insights on the best approach to implement this design in a responsive manner? I have a mockup ready for reference, featuring a lovely blue square.

Here's the "mobile" version of the design. When the width is reduced to a point where the blue square can no longer fit without shrinking, it should move below the three other content blocks.

In this scenario, it seems the straightforward solution would be to have the blue block drop below the block immediately to its left. However, the client has specified that this is not the desired layout. How would you tackle this challenge?

Answer №1

If you want to style the blue block, consider using a combination of float: right for high-res screens and display: table-footer-group for low-res screens. This way, you can avoid the need to move the blue block or use a hidden clone.

Check out this example: http://codepen.io/anon/pen/Kwdrdy


Here's the basic markup:

<main>
  <aside><div>1</div></aside>
  <section>2</section>
  <section>3</section>
  <section>4</section>
</main>

CSS:

section, aside { 
  margin: 10px 0;
  width: 100%;
  border: 1px #ccc solid 
}

main {
  display: table;
  width: 100%;
}

aside {
  display: table-footer-group;
}

aside div { background: #c2c1dc; width: 30%; margin: 0 auto;  }

@media all and (min-width: 600px) {
   main { display: block; }
   aside { float: right; width: 30%; margin: 0; }
   aside div { width: 100%; }
   aside + section { width: 68%; }
}

Screenshot on viewport < 600px

Screenshot on viewport > 600px


Note : display: table-* is well supported on all browsers, including IE8+

Answer №2

Here is a helpful starting point for you, using the order property to arrange elements:

Check out the Demo

HTML:

<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>

CSS

 div {
    background:lightblue;
    height:100px;
    width:100%;
    box-sizing:border-box;
    padding:10px;
    box-sizing:border-box;
    margin:10px;
    overflow:hidden;
}
div:nth-child(2) {
    width:calc(100% - 130px);
}
div:nth-child(1) {
    background:lightgrey;
    float:right;
    width:100px;
    margin:0 10px 0 0;
}
@media screen and (max-width: 500px) {
    body {
        display:flex;
        flex-flow: column;
        text-align:center;
    }
    div, div:nth-of-type(1) {
        margin-left: auto;
        margin-right: auto;
    }
    div:nth-of-type(1) {
        order:4;
        float:none;
    }
    div:nth-of-type(2) {
        order:1;
    }
    div:nth-of-type(3) {
        order:2;
    }
    div:nth-of-type(4) {
        order:3;
    }
}

Answer №3

Have you ever tried transforming an old position switch like the one showcased in this Fiddle? It transitions from absolute to relative using a media query.

<div class="content">
    <div class="block block1">1</div>
    <div class="block">2</div>
    <div class="block">3</div>
    <div class="block block3">4</div>
</div>

Here is the accompanying CSS:

.content {
    margin: 0 auto;
    max-width: 800px;
    position: relative;
}
.block {
    box-sizing: border-box;
    border: 1px solid red;
    height: 50px;
    line-height: 50px;
    text-align: center;
}
.block1 {
    width: 75%;
}
.block3 {
    width: 25%;
    position: absolute;
    right: 0;
    top: 0;
}
@media all and (max-width: 350px) {
    .block1 {
        width: auto;
    }
    .block3 {
        width: auto;
        position: relative;
}

Answer №4

If you want to explore the flexbox layout mode, it can be a great option.

(using the HTML elements from @fabrizio)

main {
  display: flex;
  flex-flow: row wrap;
  justify-content: space-around;
}
aside {
  width: 100px;
  order: 4;
  background: lightblue
}
section {
  width: 100%;
}
section:first-child {
  flex: 1 0px
}
@media screen and (min-width: 700px) {
  aside {
    order: 0
  }
}

/*next rule is for demo only*/
main > * {
  padding: 10px;
  min-height: 100px;
  border: 1px solid #ddd;
  margin: 10px;
}
<main>
  <section>content of section 1</section>
  <aside>content of aside 2</aside>
  <section>content of section 3</section>
  <section>content of section 4</section>
</main>

For a live demo of this layout, check out http://codepen.io/gpetrioli/pen/ZYbmYo

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

Create a canvas and include input boxes in an HTML document

I'm attempting to create a canvas line diagonally above two textboxes that are also positioned diagonally (similar to Samsung's pattern passcode) when a button is clicked, but I am facing difficulties in achieving this. I have attempted to solve ...

Angular JS does not display the bold tag for specific words

I'm currently working on an Angular JS application and receiving text from the server that needs to be displayed on my website. The text received from the server is: "My name is <b> John </b>" with b tags. Unfortunately, when I display ...

The text sliding feature gradually moves further away from the left side with each iteration

I am in the process of transferring an existing slider from one website to another. Instead of creating a text slider from scratch, I decided to modify the code I found for the new site. However, the slider is not functioning correctly on the new site. Th ...

Whenever I hover over a dropdown menu item, it suddenly stops functioning and I am forced to click in

I am facing an issue with my responsive dropdown menu that has 4 buttons, one of which opens a submenu (portfolio). The problem occurs when I accidentally click the 'portfolio' button, although it should only be triggered by a hover function. Thi ...

Enhance User Experience by Implementing Event Listeners for Changing Link Visibility Using mouseover and getElementsBy

I am new to JavaScript and struggling to find a solution. Despite searching online for fixes, none of the solutions I've found seem to work for me. I have spent hours troubleshooting the issue but I must be missing something crucial. Can someone plea ...

Downloading multiple files concurrently in Flask

I am currently working on implementing a feature in Flask that allows users to download files from the client side. This feature should support downloading multiple files or just a single file. However, I am facing a challenge in providing the option to d ...

Retrieve several values with a limit of 1 in SQL

Consider the following table structure: ID | ident | product 1 | cucu1 | 99867 | 2 | kkju7 | 88987 | 3 | sjdu4 | 66754 | 4 | kjhu6 | 76654 | 5 | cucu1 | 98876 | Running the query: SELECT ident,COUNT(*) FROM sales WHERE status=? AND team=? AND DATE(da ...

Header with absolute positioning doesn't play nice when nudged in Chrome

Take a look at the HTML page on this JSFiddle link: http://jsfiddle.net/rb8rs70w/2/ The page features a "sticky" header created using CSS with the property position: absolute. ... <body class="body-menu-push"> <header role="banner"> ...

php code to show data in a single column of a table

I am working with a database record that includes an id and name, and I need to display it in a table where records are distributed in the pattern 1-2-1-2-4 across columns. Below is my current code that is generating the incorrect output: <table borde ...

What is the term used for a tag that automatically closes itself?

Within tag-based languages such as HTML or XML, there are tags that automatically close themselves without the need for a separate closing tag: <tag/> As opposed to the traditional method of closing tags like this: <tag></tag> Do thes ...

Ways to transfer several files while transferring just one file

When you save a complete webpage, a .htm file is created along with a folder containing all the icons and scripts for the page. If you relocate the .htm file, the accompanying folder also moves to the same location. Similarly, if you move the folder, the ...

Task: Choose MySQL option and Retrieve JSON data

I have a question regarding implementing a function in a separate module file and calling it within a route to retrieve query data: function getSobre() { return new Promise((resolve, reject) => { db.query(`SELECT * FROM sobre ORDER BY cod ...

Issues with HTML5 video playback have been reported in both Chrome and Firefox browsers

I'm having trouble getting the following HTML5 Video code to work. Can someone help me spot what I might be missing? <video width="267" poster="Poster.gif" height="209"> <source src="6Minutes_1.mp4" type="video/mp4"></source> <so ...

Can we guarantee that all buttons in a button group are identical?

How can I make sure that two radio buttons in a button group have the same width? <div class="d-flex btn-group" role="group" aria-label="Basic radio toggle button group"> <input type="radio" class=" ...

I'm looking to adjust the padding on the left and right sides of the v-select menu checkbox in Vuetify 3. How

While trying to reduce the left padding of the v-select menu checkbox using the F12 debugger, I encountered an issue where the menu suddenly disappears when clicked. This makes it difficult to see the active menu. Attached is a screenshot of the select me ...

What is the best way to ensure that the input search bar, microphone icon, and two small boxes adapt to different screen

Upon submitting my exercise for The Odin Project, I was under the impression that everything looked perfectly aligned and centered on my MacBook Pro 15-inch screen. However, when I viewed the completed webpage on a larger computer screen at work, I noticed ...

What are the proper steps to ensure images are displayed correctly on mobile devices?

https://i.sstatic.net/M68Ob.jpg https://i.sstatic.net/fPKXr.jpg Our background image is 1920x1080p and looks great on desktop browsers, but it's not displaying properly on mobile devices in either portrait or landscape mode. Is there a way to resolv ...

Symbol for infinity does not appear correctly within the span element

I am currently facing an issue where HTML entities are not displaying within a span element. Specifically, I am attempting to show &infin; if there is no destroy date for my object. Interestingly, when the entity is moved outside of the span, it appear ...

Issues arise when Angular animations fail to function properly due to the addition of styles through the [ng

Exploring Angular animations and seeking advice. Currently, I am utilizing ngStyle to show or hide text on hover. The goal is to smoothly animate the text as it appears on the screen. Are there alternative methods to achieve the same hover effect without r ...

Issue with interactive rows in a table ( Rails Version 4 )

I am encountering an issue with a table that is linked to a customer show page _table.html.erb <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th width="50"><%= sort_link ...