Is there a way for me to align this to the corner of the top left side?

Let's dive into an example for better understanding:

Check out this jsFiddle link

Here is the HTML code snippet:

<div id="a">AAAAAAA</div>
<div id="b">BBBBBBB</div>
<div id="c">CCCCCCC</div>
<div id="d">DDDDDDD</div>

This is followed by the relevant CSS:

div { display:block; position:relative; float:left; }
#a { width:25%; height:100px; background-color:#ff00ff; }
#b { width:25%; height:100px; background-color:#ffff00;}
#c { width:25%; height:100px; background-color:#FF0000;}
#d { width:25%; height:400px; background-color:#CCCCCC;}
#e { width:150px; height:50px; background-color:#00FF00;}

The objective is to have the green box positioned just below the purple box.


In a practical scenario, I utilize a script that generates similar square boxes:

Click here for real-world example

The challenge lies in arranging the last two boxes, which are meant to adjust themselves within the remaining space without any gaps as it is already perfectly calculated.

Key constraints include:

  • The order of the boxes cannot be altered
  • The HTML structure must remain unchanged
  • Avoiding the use of absolute positioning (top/right/bottom/left) is necessary

Is achieving this goal possible?

Your insights and assistance are greatly appreciated!

Answer №2

To align your #c ID to the right, include float: right;.

Check out the jsFiddle DEMO for reference.

Here's the HTML:

<div id="x">XXXXXXX</div>
<div id="y">YYYYYYY</div>
<div id="z">ZZZZZZZ</div>
<div id="w">WWWWWWW</div>

The corresponding CSS:

div { display:block; position:relative; float:left; }
#x { width:25%; height:100px; background-color:#ff00ff; }
#y { width:25%; height:100px; background-color:#ffff00;}
#z { width:50%; height:200px; background-color:#FF0000; float: right;}
#w { width:50%; height:100px; background-color:#00FF00;}

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

Image not showing correctly after closing the bootstrap modal

I am currently working on creating a gallery with hover effects for each image, similar to the one found here. My goal is to have a Bootstrap modal open when I click on a link within the hovered image, displaying additional content. Everything seems to be ...

What is the best way to incorporate buttons that trigger PHP scripts within a MySQL database?

I have a MySQL database filled with various records that I've displayed in an HTML table on a webpage. I want to add two buttons next to each record, both of which trigger PHP scripts. For example, let's say the table lists the names of three pe ...

Applying a transparent layer to all slider images, with the exception of the one that is

I am utilizing an IosSlider that is functioning properly, but I am looking to enhance it by adding opacity to all images except for the selected image. This adjustment will make the selected image stand out more and enable users to focus on one image at a ...

Tips for displaying a gallery of 5 images in a 2-row slider using bxslider

I've been attempting to create a unique image slider using bxslider. My goal is to have a 2-row slider with 5 images displayed in each row. However, I'm encountering difficulties when I try to integrate the HTML, CSS, and JavaScript code. Despit ...

Combine various input data and store it in a variable

I am looking for a way to add multiple input text values together and store the sum in a variable. Currently, I can add the values and display it in an id, but I want to assign it to a variable instead. The condition for this variable is described below af ...

Maintain hover effect of main menu on sub-menu in CSS3 flip dropdown menu

Check out the fiddle I created for my query https://jsfiddle.net/e7te8hf1/ <section id="action-bar"> <div id="logo"> <a href="#"><img src="img/logo.png"></a> </div><!-- end logo --> <nav class="navbar navigat ...

Troubleshooting on Safari for iOS

As I work on my portfolio website using only HTML 5 without any JavaScript, I encountered an issue with the about page not functioning properly on iPhones. There seems to be a problem with scrolling as some elements are fixed and do not move along with t ...

Incorporate a Selectable Class when selecting a cell in a table

I have a single HTML table. <table id="tbl_1"> <tr> <td>ABCD</td> <td>ABCD</td> </tr> <tr> <td>ABCD</td> <td>ABCD</td> </tr> < ...

Clicking on an iframe activates the loading of the displayed page

I'm attempting to create a functionality where clicking on an iframe will load the page it is displaying. I experimented with placing it within an tag, but that didn't produce the desired result. The effect I'm aiming for is similar to zoom ...

I'm looking for a Visual Studio add-in that can identify and flag any unused CSS classes or IDs within the entire solution

Exactly as the headline suggests. If not, what are some reliable online services you've tried for decluttering oversized stylesheets? ...

Animating with CSS3 triggered by JavaScript

Can you help me with an issue I'm having? When attempting to rotate the blue square using a function, it only works once. After that, the page needs to be reloaded in order for the rotation function to work again. Additionally, after rotating 120 degr ...

Displaying a vertical arrangement of collapsed menu items with a centered navbar and logo positioned at the center of it (using bootstrap)

I'm currently working on a website that features a centered navbar with a logo also centered inside it. The tech I'm using is Bootstrap and LESS. Issue When the navbar collapses on mobile/tablet view, the menu items are displayed horizontall ...

The skrollr.js navigation bar is stuck and won't move

On my website, I have implemented skrollr.js to create a parallax effect. While it works perfectly on desktop, the mobile responsive menu does not scroll due to the skrollr script. ...

Guide to locating a child element using CSS from a given web element

<div id='example' /><div> When looking at the provided example, the goal is to locate a div under the following conditions: WebElement divelement = driver.FindElement(By.css("#example")); My objective is to locate the div tag wit ...

Troubleshooting a problem with HTML table styling

Could someone please help me identify the issue with this code snippet? I am aiming to style the table with a border, background color, and align it to the top. I appreciate any assistance. Thank you. <td style="border: solid 2px #111111;" bgcolor="#d ...

What are the reasons behind the ineffectiveness of !important in CSS?

I am looking to increase the font-size of all text on my website to 200%, you can find some test code in this Fiddle link. If it is a PX issue, why does the code work when I add the style to "<h2>"? <div> <h2 class="test" style="font-size: ...

Tips on incorporating dynamically appended table rows from javascript post button click in asp.net

After dynamically adding rows based on the selected number, I am facing issues with retrieving data from these rows when trying to submit it to the database. Upon Button Click, only the header row predefined in the HTML file is returned. Is there a way to ...

Explicitly employ undefined constants deliberately

So I am working on a project called WingStyle: https://github.com/IngwiePhoenix/WingStyle. It is still in the development phase, and I'm looking for ways to improve its functionality. One thing I want to address is the use of quotes. For example, whe ...

Can you provide instructions on creating a small border at the center of an h1 heading?

What is the best way to create a small border in the center of an h1 text element? ...

Div's HTML Classes are not triggering the Click Event

I'm attempting to create a custom function that will display notifications in the top right corner of my website, similar to how OS X notifications appear. Instead of relying on an external library, I am using jQuery as a resource. To house my notifi ...