Variances in the order of HTML elements within an article's layout

Check out this example of HTML and CSS

<!DOCTYPE html>
<html>
<head>
    <title>Floats Example</title>
    <style type="text/css">
        .left {
            float:left;
            width:100px;
        }
        .right {
            float:right;
            width:400px;
        }
        body {
            width:500px;
        }
        div {
            outline:solid red 1px;
            padding-bottom:20px;
        }
        .blue {
            outline-color:blue
        }
        .green {
            outline-color:green;
            height:20px;
        }
    </style>
</head>

<body>
    <div class="left green"></div>
    <div class="right"></div>
    <div class="right"></div>
    <div class="right"></div>
    <div class="right"></div>
    <div class="left blue"></div>
</body>
</html>

The green box represents an image with varying heights. The red boxes symbolize blocks that form the article. The blue box contains related information.

I am seeking a solution to position the blue box directly after the green box, eliminating the space caused by the red boxes, while still maintaining the placement of the blue box at the end in the HTML structure.

Answer №1

Alright, give this a shot. I made some tweaks to your code.
**Check out the updated HTML below -**

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>

  <div class='container'>
    <div class='leftNav'>
       <div class="green"></div>
      <div class="blue"></div>
    </div>

     <div class='rightNav'>
       <div class="right"></div>
       <div class="right"></div>
       <div class="right"></div>
       <div class="right"></div>
       <div class="right"></div>
       <div class="right"></div>
     </div>

  </div><!-- main container closing tag  -->
</div>
</body>
</html>

**And here's the updated CSS -**
.container {
  width: 450px;
  height: 300px;
  background: #f2f2f2;
  position: relative;
}
.leftNav {
  width: 120px;
  height: auto;
  float: left;
}
.rightNav {
  width: 320px;
  height: auto;
  float: right;
}
.green {
  border: solid thin green;
  width: 120px;
  height: auto;
  padding-bottom: 135px;
  background: green;
}
.blue {
  border: solid thin blue;
  width: 120px;
  height: auto;
  padding-bottom: 75px;
  background: blue;
}
.right {
  width: 320px;
  height: 45px;
  background: gray;
  margin:3px 0;
}

Give it a test run by clicking on this demo link: http://jsbin.com/uhazad/1

Answer №2

give this a shot

http://jsfiddle.net/ztUt4/8/

<div class="left green">
</div>
<div class="rights">

<div class="right">
</div>

<div class="right">
</div>

<div class="right">
</div>
    </div>

<div class="left blue">
</div>

Answer №3

Apply the use of absolute positioning to keep the blue divider at the very end of its parent element:

Check out the Demo

CSS:

body {
    width:500px;
}
.main {
    overflow: hidden;
    position: relative;
}
.left {
    float:left;
    width:100px;
}
.right {
    float:right;
    width:400px;
}
.red {
    border:solid red 1px;
}
.green {
    border:solid green 1px;
    height:20px;
}
.blue {
    border:solid blue 1px;    
    position: absolute;
    width:inherit;
    height: 100%;
}

HTML:

<div class="main">
    <div class="left">
        <div class="green">green</div>
        <div class="blue">blue</div>
    </div>
    <div class="right">
        <div class="red">1</div>  
        <div class="red">2</div>
        <div class="red">3</div>
        <div class="red">4</div>
        <div class="red">5</div>
        <div class="red">6</div>
    </div>
</div>

Answer №4

Take a look at this alternative solution where I grouped all 4 right divs within one main div.

DEMO

HTML

<div class="left green"></div>
<div class="rights">
    <div class="right"></div>
    <div class="right"></div>
    <div class="right"></div>
    <div class="right"></div>
</div>
<div class="left blue"></div>

CSS

.left {
    float:left;
    width:100px;
}
.rights {
    float:right;
    width:400px;
    margin-top:0px
}
body {
    width:500px;
}
div {
    outline:solid red 1px;
    padding-bottom: 20px;
}
.blue {
    outline-color:blue;
    height:10px;
}
.green {
    outline-color:green;
    height:30px;
}

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

Having trouble saving textarea content to a file with php?

I'm having trouble saving the content of a textarea to a file. I used the POST method to send the form to another page, but when I try to include the textarea content with the file on that page, it's not working and I'm unsure of what the is ...

Troubleshooting a Windows Phone HTML5 app encountering an Ajax error

Currently, I am working on developing a Windows Phone application specifically focusing on creating a "Windows Phone HTML 5 app". However, I have encountered an issue while using ajax with Jquery (version 1.9.1). The snippet of my code is as follows: ...

Generating a highchart visualizing a pie chart using data from a local JSON file (OBJECT)

This is the JSON data from my JSON file {"diskspace":100,"diskspace.free":50,"time":8,"time.played":2,"controllers":25,"controllers.used":3, "controllers.new":10, "controllers.broken":12} I want to represent this JSON data in various forms of pie cha ...

Discover the ins and outs of the "DOM" within a string, treating it as HTML in AngularJS

Looking to extract data from a legal HTML string based on tags and attributes, but want to avoid using jQuery in favor of Angular. Are there built-in functions in Angular for this task? ...

Issue with data type not refreshing in mySQL Workbench

I'm facing an issue with changing the datatype of my "first_name" column. I want it to be VARCHAR(45), but it's stuck at INT(11) as shown in the table diagram and connection provided below. https://i.sstatic.net/0CbkD.png https://i.sstatic.net/8 ...

The iframe is not adjusting its size in relation to the parent window

For more information, click here: http://jsfiddle.net/5HYve/ <div style="position: fixed; top:0; right:0; width:300px; height: 100%; text-align:justify; overflow:hidden;" class="chat-container"> <iframe id="chat_1" style="width:300px;height:1 ...

Preventing PHP Form Resubmission and Addressing Unusual Problems

Let's keep this brief. This is the code I've been working on: <?php if ($_POST['title'] != 'Title' && $_POST['date'] != 'Date') { $fileName = 'blog.txt'; $fp = fopen('blog.txt', &ap ...

Clicking on the href=#div will cause the page to smoothly scroll down

Whenever I click on the links in my navigation bar, the page automatically scrolls down. How can I resolve this issue? I have a navigation bar containing a list of links. Below is the HTML code: <ul> <li><a href="page.html#1">menu item ...

What is the best way to display an alert box through AJAX technology?

My code snippet is as follows: <script> function updateQty(quantity) { $.ajax({ alert(quantity); }) } </script> Here is the corresponding HTML markup: <form name="quantityForm"> <select name="quantity" id="quantity" onChan ...

The hover drop-down menu in CSS is not appearing in the correct position

Having trouble with my navigation bar - the dropdown menu isn't showing up below the category when I hover over it. It keeps ending up in the left-hand corner and I can't access it! I've searched everywhere for a solution, but can't fin ...

Switch classes according to scrolling levels

My webpage consists of multiple sections, each occupying the full height and width of the screen and containing an image. As visitors scroll through the page, the image in the current section comes into view while the image in the previous section disappe ...

"Select2 dropdown fails to function properly upon returning to the page using the browser's

I've encountered an issue while working on a search page with Select2 dropdowns. Everything functions smoothly upon the initial page load, however, problems arise when a user performs a search, hits the browser back button, and then revisits the page. ...

Creating unique CSS class and ID names dynamically in PHP

I have two divs with randomly generated IDs and I would like to use those IDs in my CSS instead of using inline styles. Is there a way to achieve this without creating a separate PHP file with a CSS header? For example, I want the padding for the ID $id_ ...

CSS - setting the background-image property is not displaying the image

.main_banner { background-image: url("../images/main_banner.png"); width: 100%; height: auto; } <!DOCTYPE html> <html> <heading> <title> ********** </title> <link rel="sty ...

Potential Performance Issue with Material UI's withStyles Function

I've been given the task of optimizing the loading speed of a page in our react redux web app. When the page load action is triggered, there seems to be a slight freeze lasting about half a second. After checking the profiler, everything seems fine ...

execute the changePage() function in jQuery using the data stored in localStorage

In my jQuery mobile page, I have a simple setup: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.2"> <link rel="stylesheet" href="js/jquery.mobile-1.2.0.css" /> < ...

Determine whether a specific key exists in the formdata object

Can I check if a key in the formdata object already has a value assigned to it? I am looking for a way to determine if a key has been previously assigned a value. I attempted something like this but did not get the desired outcome data = new FormData(); ...

Delivering styled coldfusion outcomes utilising css and jquery

After using jquery to retrieve some data, I've noticed that the results are displayed correctly but the CSS is not being applied. Is there a way to style the results with CSS? function doSearch() { //Making an AJAX call to the server $.ajax({ / ...

Tips for displaying multiple results from a MySQL query in a single .ejs file using Node.js and Express

Currently diving into Node.js and working on a web application, I am faced with the challenge of rendering twice in the same .ejs file. Consider the scenario presented in the following .ejs file: <table> <% rows.forEach(function(ind){ %> /* m ...

CSS - a collection of hyperlinks to browse. the pseudo-element a:visited::before is not behaving as anticipated

Here's what I'm looking to achieve: http://codepen.io/anon/pen/KaLarE I want to make a list of links, each with a checkbox in front. Then, I want to be able to check the boxes for visited links. I attempted this approach, but unfortunately, it ...