3-Column Layout with Left-Floated Columns Displaying Incorrect Order

Currently, I am in the process of converting a 3-column website to be responsive by using percentages and em's instead of negative pixel margins. This will ensure that the site functions well on various devices.

I am facing a similar issue as discussed in this post: HTML float right element order

Following the advice given in this article by @bookcassey, I have placed all columns in a container that is floated right, with child elements inside floated left. However, I am still struggling to get the columns in the correct order (#NavColumn #ContentColumn #ExtraColumn).

The HTML code looks like this:

<!DOCTYPE html>

<html>

<head>

<title>3 Col Page</title>

<meta name='description' content='Sample 3 Column Page'>

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" type="text/css" href="style.css" />

<link rel="stylesheet" type="text/css" media="screen and (max-width: 800px)" href="./support-files/landscapemobile.css" />

<link rel="stylesheet" type="text/css" media="screen and (max-width: 480px)" href="mobile.css" />

</head>
<body>

<div id="PageWrapper">
    <div id="Header">
    <div class="Liner">

    Header Links Etc

    </div> <!-- End Header Liner -->
    </div> <!-- End Header -->

    <!-- Begin Center Column Content -->
    <div class="OuterBG threecol"> <!-- disregard. There are no rules for this. This was part of a tut-->
    <div class="MidBG"> <!-- disregard. There are no rules for this. This was part of a tut-->
    <div class="InnerBG">
    <div id="ContentColumn"> <!-- col1 in tut -->
    <div class="Liner">

<h1>Page Headline</h1>

Page Content, Images Lorem Upsim etc...

</div> <!-- End Content Column -->
</div> <!-- End Liner -->

<div id='NavColumn'>
<div class='Liner'>
<div class='Navigation'>
Site 
Navigation
Links
</div><!-- end Navigation -->        
</div><!-- end Navigation Liner -->
</div><!-- end NavColumn -->

<div id='ExtraColumn'>
<div class='Liner'>
Extra
Column 
Content
</div><!-- END Extra Column Liner-->
</div><!-- END ExtraColumn -->


</div><!-- END colleft -->
</div><!-- END colmid -->
</div><!-- END colmask and threecol -->
<div id='Footer'>
Footer Content, Address etc...
</div>
</div><!-- END PageWrapper -->

</body>
</html> 

Here is the CSS code:

#PageWrapper{ 
    margin:1em auto;
    max-width:60em; /*960px / Default Font Size of 16px = em result*/
    border:0.3125em groove #DDDDDD;
    background-image:url(../image-files/background.gif);
    background-repeat:repeat-y;
}

.InnerBG{float:right;/*border:3px solid red;*/width:100%;}

#Header{position:relative;}

#Header .Liner{padding:0;}

#Header a.header-home-link{max-width:60em;display:block;}

#Header img{display:block;}

#ShareThis{width:100%;margin:1em auto 2em;}

#NavColumn, #ContentColumn, #ExtraColumn {float:left;}

#ContentColumn{max-width:62.50%;/*border:2px solid green;*/width:100%;}

#NavColumn{max-width:18.645833333%;text-align:center;font-size:90%;color:#000;width:100%;}

#ExtraColumn{max-width:18.645833333%;text-align:center;font-size:90%;color:#000;width:100%;}

It has been an extensive process trying to figure out the ideal CSS rules to display the columns correctly. If anyone has suggestions on how to resolve the column display issues witnessed here: , I would greatly appreciate the help. Thank you in advance for any assistance provided.

Answer №1

I was able to accomplish most of the tasks you were looking for, with the exception of the "Share This" column which was missing. I placed the first two columns inside the MidBG div and floated it to the left. Then, I floated the first column to the right so that it appeared before the second column, and the third column ended up on the right side.
I also had to remove several instances of width:100%, as they were causing some issues.

To see the changes, check out my jsfiddle.

I hope this aligns with your requirements, as it's based on what you requested...

Answer №2

Your current code structure is a bit messy and cluttered, with unnecessary elements scattered throughout. It might be best to consider starting fresh for clarity.

To help you kickstart your project, I've created a simple three-column layout that is responsive as per your request.

When developing your website, remember the principles behind this layout to keep things organized and functional.

<body>
<div id="container">
<div class="column1">
</div>
<div class="column2">
</div>
<div class="column3">
</div>
</div<!--end container-->
</body>

CSS

#container{
width:100%;
}

.column1{
background-color:blue;
width:33.33%;
height:200px;
float:left;
}
.column2{
background-color:red;
width:33.33%;
height:200px;
float:left;
position:relative;
}
.column3{
background-color:green;
width:33.33%;
height:200px;
float:right;
position:relative;
}

@media screen and (max-width:320px){
.column1, .column2, .column3{
    float:none;
    position:static;
    margin:0 auto;
    width:100%;
}
}

Feel free to view it in action http://jsfiddle.net/hJ9BS/ Resize the 'Result' window to see its responsiveness 😉

Answer №3

I'm not sure why there are so many wrappers in your code, but rearranging your containers can help you achieve the desired layout. Start with NavColumn, then ContentColumn, and finally ExtraColumn.

<div id="PageWrapper">
    <div id="Header">
        <div class="Liner">Header Links Etc</div>
    </div>
    <div class="OuterBG threecol">
        <div class="MidBG">
            <div class="InnerBG">                    
                <div id="NavColumn">
                    <div class="Liner">
                        <div class="Navigation">Site Navigation Links</div>
                    </div>
                </div>
                <div id="ContentColumn">
                    <div class="Liner">
                         <h1>Page Headline</h1>Page Content, Images Lorem Upsim etc...</div>
                    </div>
                <div id="ExtraColumn">
                    <div class="Liner">Extra Column Content</div>
                </div>
            </div>
        </div>
    </div>
    <div id="Footer">Footer Content, Address etc...</div>
</div>

http://jsfiddle.net/rWtDa/

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

Deactivate user input in Knockout Kendo TimePicker

Is it possible to prevent user input in the Kendo UI TimePicker while using knockout-kendo binding? In a previous project without knockout-kendo, I was able to achieve this by using the following code (see jsfiddle example): $('#timepicker').at ...

Slider that is always being updated cannot be moved by dragging

Currently, I am utilizing React wrapped with cljs+reagent to develop a small application. One key feature I require is a slider that updates roughly every second and can be adjusted by the user. At present, my implementation looks like this: [:div.scrubb ...

Randomize elements with the click of a button

Every time the page refreshes, the words shuffle around. For instance, "May I# know# your name?" shuffles to "know May I your name". To display the correct sentence with "#" as "May I know your name?", click the SHUFFLE button to trigger the shuffling. HT ...

Is it feasible to execute exe files within a ReactJS environment?

Hey there! I've created a Game Launcher using ReactJS for my Unity game and was wondering if it's feasible to start the game (an exe file) simply by clicking on the play button. Can anyone please advise me on this? ...

Is it not recommended to trigger the 'focusout' event before the anchor element triggers the 'click' event?

In a unique scenario, I've encountered an issue where an anchor triggers the 'click' event before the input field, causing it to lose focus and fire the 'focusout' event. Specifically, when writing something in the input field and ...

Adjusting Text Size Depending on Width

I recently used an online converter to transform a PDF into HTML. Check out the result here: http://www.example.com/pdf-to-html-converted-file The conversion did a decent job, but I'm wondering if it's feasible to have the content scale to 100% ...

Why does the parent URL become the origin for an AJAX request coming from an iframe?

I am facing an issue with a website where I need to load an iframe from a different subdomain. The main website is hosted on portal.domain.com, and the iframe is on iframe.domain.com. To make requests to iframe.domain.com from portal.domain.com, I decided ...

Stable header that jumps to the top when scrolled

I have implemented the JavaScript code below to set the header to a fixed position when it reaches the top of the page so that it remains visible while the user scrolls. Everything appears to be functional, but the header movement is abrupt and not smooth. ...

The height of a div element does not automatically default to 100% in Next.js

I'm encountering an issue with styling pages in next.js. My goal is to create full-height pages. Although I've successfully set the height attribute in the body and html tags to achieve full height (verified in dev tools), I'm struggling to ...

Challenges with aligning Fontawesome stacks

I utilized the code example from Fontawesome's website to create a pair of stacked social media buttons and enclosed it in a div element to float them to the right side of the page. <div class="social-icons"> <span class="fa-stack fa-lg"> ...

Side Text for Floating Action Button

I've been working on incorporating labels to the left of my FAB, following the Material Design principles. Despite my efforts, I'm facing difficulties in getting the labels to display properly. I would greatly appreciate any advice or tips on how ...

Automated static file versioning in Google App Engine/Python

Recently, I've been experimenting with Google's page speed service, and it has inspired me to implement automatic versioning of static files in my GAE/P application. This way, I can fully utilize longer caching times. Developing a script to perf ...

What is the best way to include a div element with a dynamic animation on a webpage?

I'm attempting to create a laser beam that can shoot enemies on the screen, much like in classic games such as Space Invaders or Galaga. However, I am encountering difficulties getting the laser to move when I click the button. Below is the code I hav ...

Implementing image change on dropdown selection using jQuery click event

I'm new to Jquery and JavaScript. I have a dropdown in my Keen template that displays 2 flags. I want to be able to click on the dropdown and select the corresponding flag. Most of the examples I found online use the select and options tags, but my co ...

Dynamically create a button using jQuery and JSON based on specific conditions (either true or false)

Is there a way to generate buttons with specified parameters only if a condition is true? Currently, the buttons are generated without checking conditions. Any help with the correct syntax would be appreciated. Sample JSON code: { "Caption": "Module ...

Javascript Dilemma: Unable to Access 'object.style.left' and 'object.style.top' Values - What's the Issue?

Why am I unable to access and modify the object.style.left & object.style.top values? I am currently attempting to dynamically reposition a button on a webpage. In order to set new values for the style.left & style.top, I can utilize JavaScript l ...

Using AJAX and jQuery, the result is retrieved and inserted into a <div> element

Having trouble populating a DIV with the result of a simple GET request using AJAX and jQuery. What could be causing the issue? <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script> <scrip ...

Tips on handling a nested HTML hyperlink in Selenium using Python with IE11

Can anyone assist me in resolving the issue of clicking on a hyperlink within an HTML page that contains nested HTML elements up to 4 levels deep? I have attempted various methods using XPATH, but they do not seem to work during runtime. I am utilizing Sel ...

Is it possible for the binding model of Mat-Checkbox to be optional or null?

Greetings everyone! I am a newcomer to the world of Angular, where I have successfully created a dynamic list of checkboxes. However, I have encountered a challenge when trying to bind selected values from an API to these checkboxes. <div *ngFor="let b ...

Bootstrap columns causing a collision

My website has a problem when viewed on mobile at 320 x 480 resolution. Two columns filled with text collide and mash up the text together. I initially tried without using columns, just "container-clearfix," but that did not resolve the issue. Check out t ...