The alignment of the third column div is off and not displaying properly

I am having some trouble with aligning the divs on my page in a column layout. Despite setting the first two divs to float left, the third one does not align properly. I want the third div to be floated right and aligned with the first two.

You can see an example of the issue in this JSFiddle.

The specific requirement is for the .commitment_box div to be floated right in alignment with the other boxes.

CSS:

.major_data {
    margin: 110px auto;
    width: 40%;
}
.major_data .profile_box p:first-child {
    border-bottom: 0px;
    text-align: center;
    font-size: 20px;
    margin-top: 0px;
    background-color: #eee;
    font-weight: bold;
}
.major_data .profile_box p:nth-child(2) {
    text-align: justify;
    padding-left: 5px;
    padding-right: 5px;
    margin-top: -20px;
}
.major_data .profile_box p {
    border: 1px solid #bbb;
}
.commitment_box { /*the div i want to be floated right in alignment with those about boxes */
    margin-top: -58.2%;
    text-align: center;
    height: 40px;
    overflow: hidden;
    background-color: lightblue;
    color: white;
    font-size: 20px;
    width: 25%;
    margin-right: 2%;
    float:left;
}
.commitment_box .commitment p {
    display: inline-block;
    margin-top: 1.5%;
}
.commitment_box .commitment p:first-child {
    font-weight: bold;
    margin-right: 20px;  
}

HTML:

<div class="commitment_box">
    <!--/*the div i want to be floated right in alignment with those about boxes */-->
    <div class="commitment">
        <p>Alex:</p>
        <p>He's great at his work.</p>
    </div>
    <div class="commitment">
        <p>Alex 1:</p>
        <p>He excels in his role.</p>
    </div>
    <div class="commitment">
        <p>Alex 2:</p>
        <p>He consistently delivers top results.</p>
    </div>
    <div class="commitment">
        <p>Alex 3:</p>
        <p>He demonstrates exceptional skills.</p>
    </div>
    <div class="commitment">
        <p>Alex 4:</p>
        <p>He's a valuable team member.</p>
    </div>
</div>

Answer №1

Avoid using float in your code as it is not considered a good coding style.

Instead, try making large sections into inline-block elements and setting their width to, for example, 30%.

Check out this simplified jsFiddle showcasing the important style changes.

Answer №2

To ensure proper alignment, remember to add a float:left property to the .major_data container as well, and maintain consistent top margins for both boxes.

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

Automatically populate fields when the selection changes

Currently, I am facing an issue with a mysql table named clients that I utilize to populate the options of a select in one of the rows. The goal is to automatically fill out 2 input fields with client information when a specific option is selected. To acc ...

Enhancing Time Precision in CakePHP: Introducing Quarter-Accurate Time Input

I'm currently implementing time inputs using the following code snippet: $form->input("time") However, the select boxes generated have minute-accuracy, which is unnecessary for my project. Is there a way to restrict the options in the select lis ...

How can you make each <li> in an HTML list have a unique color?

Looking for a way to assign different colors to each <li> element in HTML? <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <ul> Here's how you want them displayed: Item 1 should be red Ite ...

Creating a blog "post" model in Ruby on Rails with CSS that can behave in two distinct ways

I am in the process of creating a blog using Ruby on Rails. The posts on my blog are generated from the Posts model, and I want them to exhibit two different behaviors. Currently, I have configured it so that a new post is automatically created every day. ...

How can recursive data be displayed in a template?

I am working with a model in Django that has a ForeignKey pointing to itself, and I need to display all the data from the database using lists and sublists: Below is my model definition: class Place(models.Model) name = models.CharField(max_length=1 ...

Click on the print icon in the modal window

I have been working on a receipt generator for a client. The client can add payment receipts using the "Add" button, and upon submission, they have the option to convert it to PDF or print it. However, there seems to be an issue with printing as the text f ...

Tips for transforming a date into a time ago representation

Can someone help me with converting a date field into a "timeago" format using jquery.timeago.js? $("time.timeago").timeago(); var userSpan = document.createElement("span"); userSpan.setAttribute("class", "text-muted"); userSpan.appendChild(document.crea ...

Vuetify's data table now displays the previous and next page buttons on the left side if the items-per-page option is hidden

I need help hiding the items-per-page choices in a table without affecting the next/previous functionality. To achieve this, I've set the following props: :footer-props="{ 'items-per-page-options':[10], &apo ...

Utilizing objects from a JSON file within an HTML document

I'm currently in the process of creating a comprehensive to-do list, and I want to establish a JSON file that will link all the items on the list together. Despite my efforts, I find myself uncertain about the exact steps I need to take and the speci ...

Using a timer to make Ajax calls twice on a single webpage

Can multiple ajax calls be made simultaneously on the same page to different receiving div tags? I am struggling to find a solution to this issue. I have a total of 3 pages: a home page, and two PHP pages named status and alert which echo the results. Wi ...

What is the best way to customize the size of a file upload Buefy component to have both a specific

I am looking to set up a file drop area with the Buefy component, but I want the size of the drop area to be 100% of both the width and height. The basic page is provided below, however, I am unsure about where to add the necessary width and height styles. ...

The Bootstrap navigation menu fails to extend the parent div when toggled

When I toggle the button to show the menu on small screens, the menu overflows the parent div with id=contents instead of pushing it down. How can this issue be fixed? Here is the code: <body> <nav id="header" class="navbar navbar-default"& ...

Tips for resolving the issue of windows resizing due to off-screen elementsplacement:

During the development of a project, I wanted to incorporate an effect into my webpage. To achieve this, I positioned elements off the screen. However, upon running the code, the window resized with scrollbars, causing inconvenience for mobile users Below ...

How to responsively position and scale a background image for a full-width div

Here is the situation: I have an SVG with dimensions of 1920*1920 pixels () This is what I require: I intend to use it as a background-image for a div that spans the full width of the screen. The background image for the div must be responsive. An essent ...

The placement of a material-ui component at the beginning of the render method can impact the styling of the following components in the hierarchy

After creating some styled components, I noticed that they were not rendering correctly for me. However, when I transferred the code to a codesandbox environment (which had a material-ui button in the template), the components rendered perfectly fine. It w ...

What is the best way to eliminate all borders from a select box?

Is there a way to completely remove all borders from the selectbox using either CSS or JQuery? The code snippet is as follows: <select id="doctor_ch"> <option value="1" selected>One</option> <option value="2">Two</option& ...

Storing multiple values of dynamically added elements in a single variable and accessing them within a function

Is it possible to store multiple values into a single variable and then access them in a setTimeout function? $(document).ready(function (){ div ({'div':'#noo','auto':'true','pos':'top',' ...

"Trouble encountered while trying to display Angular in an HTML document

In my Angular project, there is a feature where a list of orders is displayed in one view. Each order is represented by its title only. When the user clicks on the title, they should be redirected to a new view showing the complete content of that particul ...

Placing a CSS image with absolute positioning on top of a responsive image

Is there a way to keep the balloon image position fixed in relation to the grid image when resizing it? The balloons Balloon1 and B2 are technically within grid 5 and 7, but if you resize the grid left or right, the balloons will go off-center. Do I requ ...

What is the best way to make the div inside the table cells expand to fill the available space?

I'm having trouble making the inner divs within table cell divs expand and fit their parent div without overlapping the next cell below it. Check out the sandbox for reference I've outlined the areas in grey where I want the cells to be filled. ...