Tips for positioning the side bar below the content without using the float property

As I delve into responsive design, I encountered a particular issue.

Displayed below are images that demonstrate the layout scenario:

  1. Image A showcases the layout on a large screen
  2. Image B illustrates how I envision it to look on narrower screens, achieved by removing the float:right;
  3. Image C depicts the outcome after eliminating float:right from the sidebar.

Here is an example of the code snippet being utilized:

  <doctype html>
  <html>
  <head>
  <title>Test</title>
  <style>
 #container{width:100%; height:700px; background:blue; -moz-box-sizing:border-box; padding:10px;}
 #box{width:60%; height:70px; background:black;}
 #content{width:70%; height:600px; float:left; background:green; margin-top:10px;}
 #aside{width:30%; height:800px; float:none; clear:right; background:yellow;}
 </style>
 </head>
 <body>
 <div id="container">
<div id="box">
</div>

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

<div id="aside">
</div>


 </div>
 </body>
 </html>

Check it out here: http://jsfiddle.net/cBh6z/

Answer №1

Learn about how to use CSS media queries

#container{
    width:100%; 
    height:700px; 
    background:blue; 
    box-sizing:border-box; 
    padding:10px;
}
#box{
    width:60%; 
    height:70px; 
    background:black;
}
#content{
    width:70%; 
    height:600px; 
    background:green; 
    margin-top:10px;
    float:left;
}
#aside{
    width:30%; 
    height:800px; 
    background:yellow;
    float:right;
}
@media (max-width: 400px) {
   #content,#aside{
    display:block;
    float:none;
   }
   #aside{
     margin-top:20px;  
   }
}

Check out the JSFIDDLE DEMO here!

Answer №2

Here is the solution for you

Check out this JSFIDDLE DEMO

 #container {width:100%; min-height:700px; background:blue; -moz-box-sizing:border-box; padding:10px;}
 #box {width:60%; height:70px; background:black;}
 #content {width:70%; height:600px; float:left; background:green; margin-top:10px;}
 #aside {width:30%; height:800px; float:none; clear:both; background:yellow;}

Make sure to use clear:both; instead of just clear:right;

Answer №3

This solution avoids using floats:

JSBIN DEMO

 body{margin:0;min-width:500px;}
 #wrapper{color:white;width:100%; height:700px; background:blue;padding:10px}
 #box{width:60%; height:70px; background:black;margin-bottom:10px}
 #content{width:60%; height:300px;background:lightgreen;margin-bottom:10px}
 #aside{position:absolute;right:0;top:0;width:30%; height:400px;background:green;margin:10px  10px 0 0}
 @media(max-width: 500px){#aside{position:static}}

Answer №4

if you take out the float:right style from the aside, try adding clear:left.

p.s. if there are no elements floated to the right, then you don't require clear:right

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 add texture graphics to the box element in an A-Frame simple environment

Currently, I am experimenting with the demonstration of a Basic Scene in A-Frame. However, when I reach the section about Applying Image Texture and Using Asset Management System, I encounter an issue where the suggested texture does not display as expect ...

Differentiate between chrome and chromium with the help of Javascript programming

Can we differentiate between Google Chrome and the open-source Chromium browser using JavaScript? It appears that the navigator.userAgent property is the same in both browsers. ...

Tips for achieving a static background image while allowing scrolling on a webpage in asp.net

I am struggling to implement this on my website. The background image needs to be fixed while the content of the webpage should scroll in asp.net <head runat="server"> <title></title> <style type="text/css"> body { backgr ...

jQuery failing to recognize multiple selection form elements

<select class="js-example-basic-multiple categories form-control" name="categories[]" style="width: 100%" multiple="multiple"> <option value=""></option> <option value="fresher">fresher</option> <option value=" ...

What is the procedure to alter the color of XYChart in JavaFx?

How can I change the color of a bar chart? Does anyone have any tips on: How to adjust the color of line charts? How to assign a CSS class to series? public class CustomBarChart extends Application { @Override public void start(Stage stage) throws Ex ...

Conceal a particular object from view by selecting it from the menu

I want to hide a specific element when the burger button is clicked. (See CaptureElementNoDisplay.PNG for the element to hide) When I click the burger button again to close the menu, I want the hidden item to be displayed once more. I've successfull ...

A step-by-step guide on customizing the background color of a Dialog in Angular Material (Version 16)

I've been attempting to modify the background color of my Angular Material Dialog by utilizing the panelClass property in the MatDialogConfig. Unfortunately, I'm encountering a partial success. I am aiming to set the background color as red (jus ...

Why does my HTML page keep triggering a redirect loop when embedded?

Trying to create an HTML document that auto-refreshes every 5 seconds while embedding a web page poses a challenge. Various attempts with embed tags, object tags, and iframe tags led to automatic redirection to the embedded page upon each refresh. The curr ...

Css beforehand, unique subject matter

Trying to use a jQuery plugin that has CSS code like this: .icon-eye:before { content: '\56'; } On the plugin's site, it displays as an eye icon. However, when I install the plugin on my local PC, I see 'V' instead of the ey ...

Using sandboxed iframes in HTML for secure `src` loading on Internet Explorer 11 and Microsoft Edge

Is there a way in IE11/Edge with HTML5 to populate a sandboxed iframe (<iframe sandbox></iframe>) with HTML without using a src url? I am searching for a solution similar to srcdoc that is compatible with all other modern browsers. Attempting ...

The drop-down menu is misaligned from its designated position underneath the title

Trying to incorporate a dropdown menu into my website, I am structuring the HTML as follows: <ul class="topnav"> <li> SECTION TITLE <ul class="subnav"> <li>One</li> <li>Two</li> ...

Enhanced JQuery Functionality with Additional Parameters

My current class setup is as follows: <div class="photo" parameter1="custom" parameter2="custom"></div> There are a total of 4 parameters in use. I am looking for a solution to pass these parameters within my photo div for JQuery coding, whi ...

authentication routing procedure

My web portal for event bookings initially allows users to choose tickets without logging in. However, when it comes time to make a payment, the user must sign in. I have set up a redirect to the sign-in page and then back to the main page of the portal wh ...

Tips for implementing resizable Material-UI Dialogs

I'm working on a project that involves creating a dialog box that can be resized and dragged. While I found steps in the Material-UI Dialog documentation on how to make it draggable, I'm still looking for information on how to make it resizable. ...

Adjust the color of the upcoming line I am sketching without ending the path

I am working on a paint program and encountered an issue. My goal is to create buttons of various colors that can change the color of the next stroke drawn by the user. While searching for a solution, I came across a similar question (HTML5 Canvas change ...

Design the appearance of page buttons distinct from select buttons

I am currently working on styling my paging buttons differently from the select buttons. However, the selector I am using for the select buttons is also being applied to the paging buttons: .gridView tr td a{} /* The gridView class has been assigned to th ...

Is it possible to modify the button icon on hover by utilizing chakra-ui and vanilla-extract?

My stack includes nextjs13, chakra-ui, and vanilla-extract Seeking guidance on how to update both icon and text within a button upon hover, utilizing chakra-ui and vanilla-extract. The current setup of my button is as follows: <Button > <svg wi ...

What is the best way to ensure that all of my images are the same size?

I've been working on making my pictures of varying resolutions the same size here, but no matter what I try, it just doesn't seem to work. Here is what I'm getting: . When I change the state to 1, 2, 3, or 4, I want it to look like this: her ...

Is there a way to showcase the uploaded file contents on the current page without the need to refresh?

Is there a way to display the contents of an uploaded file on the same HTML page without opening a new tab or refreshing it? I have the following HTML and PHP codes for reading an uploaded file in a separate page, but I want to integrate it into the same H ...

AngularJS date and time picker featuring user-defined input validation

Is there an AngularJS component available that offers both a date/time picker and the ability to input dates using the keyboard? ...