The CSS code isn't functioning properly on both desktop and mobile views

Here is what I desire to achieve: https://i.sstatic.net/8H4fv.png

The CSS code I have is:

And the HTML code looks like this:

<body>
 <div class="contanier">

    <div id="rightcol">Right Section</div>
<div id="content">Content Section</div>

    </div>
</body>

I am referencing this site for guidance:

desktop and mobile view

However, with my current setup, the display is not as expected. The desktop view appears fine, but on mobile, the content does not stack below. What seems to be causing this issue? What adjustments do I need to make?

This code snippet lacks spacing.

In another version of the code, the "rightcol" element remains at the same level instead of moving down.

Implementing the suggestion provided has resulted in space between "container" and "right section," as shown here:
https://i.sstatic.net/nCr1T.png

Answer №1

Make sure your divs are styled as inline-block on desktop, and as block on mobile devices

Check out this demo

        * {
  margin: 0;
  padding: 0;
}

body {
  width: 100%;
  font-family: 'Cabin', sans-serif;
}
.contanier {
  margin:auto;
  height: 1500px;
  display: block;
  width: 70%;
   -webkit-flex: 3 1 60%;
           flex: 3 1 60%;
   -webkit-order: 2;
           order: 2;
}
#rightcol {
  background: #f00;
    position:relative;
    display:inline-block;
  width: 20%;
  margin-left:auto;
  margin-right:auto;
  height: 500px;
   -webkit-flex: 1 6 20%;
           flex: 1 6 20%;
   -webkit-order: 3;
           order: 3;
}
#content {
  background: #fff;
  position:relative;
    display:inline-block;
 margin-left:auto;
  margin-right:auto;
  width: 59%;
  height: 500px;

   -webkit-flex: 1 6 20%;
           flex: 1 6 20%;
   -webkit-order: 3;
           order: 3;
}
@media screen and (max-width: 700px) {
    #rightcol, #content{display:block!important; width:100%;}
    
   .contanier {
    -webkit-flex-flow: column;
            flex-direction: column;
   }

   #rightcol, #content {
    /* Return them to document order */
    -webkit-order: 0;
            order: 0;
   }

  #rightcol{
    min-height: 50px;
    max-height: 50px;
   }
}
<body>
  <div class="contanier">

    <div id="content">Content Section</div>

    <div id="rightcol">Right Section</div>
    

  </div>
</body>

Answer №2

#rightcol {
     display: inline-block; /* use instead of float */
}

reference:

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

The dropdown menu in the navigation bar is getting hidden behind the content

My simple navbar is currently functioning, but it's overlapping with other content. Both the navbar and main content elements use relative and absolute positions to function. I have tried adjusting position:absolute without success. The menu keeps ...

The class is failing to be applied to the parent div that holds an id starting with the letter x

I have been attempting to assign a class to the parent container when the child element has the 'hidden' class. If not, then a different class should be added. function tagMissions() { if ($('span[id^="mission_participant_new"]').h ...

Having trouble getting my jQuery fade in effect to work

I am having an issue with the fade in / fade out effect using jQuery. The Menu is rendering perfectly and functioning properly, but there is no delay or fade when hovering over the menu items. I'm not receiving any errors, but the expected behavior is ...

Tips for positioning a highcharts pie chart and legend in the middle of a page

I'm struggling to center my highchart data in a node/react single page application. Currently, it appears off-center like this: https://i.stack.imgur.com/ccR6N.png The chart is floating to the left and I would like to have everything centered within ...

Forwarding the geographic coordinates directly to the system's database

I have a unique script that retrieves the precise latitude and longitude position. It then automatically sends this data to a database without the need for user input. <script> function getPosition(position) { var latitude = position.coor ...

Tips on dynamically passing values according to media queries

Within my product section, there is a total of approximately 300 products. To implement pagination, I have utilized the ngx-pagination plugin. The products need to be displayed based on media query specifications. For example, if the viewport size falls wi ...

Positioning html images to overlap each other without losing the ability to click

Currently, I am facing a challenge with positioning two images over each other. The back image should be at the bottom, while the center image needs to be on top of it. Additionally, there is a requirement for placing a random link (in this case google.com ...

Showing a hidden div after an unsuccessful AJAX call

Encountering an issue with displaying a div notification using the code snippet below: $.ajax({ url: url, cache: false, async: false, success: function (data) { response = jQuery.parseJSON(data); }, error: functi ...

Add drop caps to every individual word within a hyperlink

Is there a way to recreate the menu effect similar to using CSS fonts and drop caps for each word? I'm aware of the CSS code: p.introduction:first-letter { font-size : 300%; } that enlarges the first character of the first word, but I want this ef ...

Utilize JavaScript conditions to dynamically apply styles within your web application

I am facing a challenge with managing two separate <style> tags that each contain a large number of styles and media queries. The issue is that one set of styles is intended for desktop users, while the other is meant for mobile users. When both se ...

The update of the attribute in jQuery on a checkbox is not causing the change event to trigger

I am working on a feature where there are multiple checkboxes along with a status box that indicates if at least one of the checkboxes is checked. Additionally, I have included a Check All/None checkbox that can toggle all the checkboxes. However, althoug ...

Does activating a hyperlink on an anchor element count as a cross-origin request?

Understanding CORS: Cross-origin resource sharing (CORS) is a method that enables limited resources on a webpage to be requested from a different domain than the one where the initial resource originated. Let's say I have a simple HTML page with a li ...

What is the proper way to specify the type for a <video> element reference in React when utilizing Typescript?

I have been experimenting with controlling the play/pause state of a video in React.js using ref's. My code functions correctly but I am encountering tslint errors that I am currently trying to diagnose: function App() { const playVideo = (event:a ...

How can I change the Safari blue outline to black?

I have an input field and I have applied the following CSS to it: input:active, input:focus { outline: 1px auto rgb(16, 16, 16) !important; outline-offset:0px; } However, when I tested it using , the input field still had a blue outline: I was hoping ...

Tips for resolving a sluggish webpage with database content

I am facing an issue with one specific page on my website that contains links to the database. The loading speed of this page is extremely slow and I'm looking for ways to speed it up. I have noticed that even when there are no visitors on the server ...

Stop the anchor tag from activating Chrome's status bar

I've been working on a web application with an elastic layout where the footer acts as a toolbar and information display. The footer is always visible at the bottom of the page, without any need for scrolling. We specifically chose this location for t ...

Is there a possible method to obtain a smartphone number from a website?

Seeking a solution to retrieve the phone number of a device using HTML 5, JavaScript, or similar technology. Recently, I successfully obtained the coordinates of the device by incorporating the following JavaScript code: <!DOCTYPE html> <html> ...

Display extensive text content in HTML for mobile devices

As I work on developing a web app, specific requirements must be met: Pages that can dynamically load large amounts of text (around 30-100 printed pages) in HTML using $.ajax based on complex functions The complete text must be loaded upfront and cannot ...

Trouble with CSS Vertical Alignment: Solutions to Fix it

Link to a JSFiddle for reference: http://jsfiddle.net/STmwz/4/ Initially, there is only the top div displayed. Upon clicking the edit button, the JavaScript code replaces the top div with the bottom div. However, during this transition, there is a slight ...

Guide to changing the background colors of multiple elements when hovered over by the mouse?

I want to customize my website's search bar by changing the background color when it is hovered over. Currently, the search bar has two main elements: the text box and the submit button. I have successfully programmed the text box element to change to ...