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

Create custom buttons in Material-UI to replace default buttons in a React modal window

How can I prevent overlay on material-ui's RaisedButton? When I open a modal window, the buttons still remain visible. Which property should be added to the buttons to disable the overlay? Any assistance from those familiar with material-ui would b ...

What could be causing the issues I am encountering while using IE8?

My website looks great on all browsers except for Internet Explorer. I am currently using Internet Explorer 8 to test it. I've tried using a conditional stylesheet (ie.css) to fix some issues, but there are a few problems that have me stumped. I am op ...

Guide on implementing a scroll feature for a div element with a fixed width that contains a dynamically generated table with td elements of fixed width in HTML

Struggling with HTML formatting. I'm facing an issue where I have a table nested inside a div. The div has a fixed width of 200px and the td elements are added dynamically. Despite setting each td to be 100px wide, when five td elements are added, to ...

Having trouble with element.scrollTo not functioning properly on mobile devices?

I have been working on creating a vertical scrolling carousel, and so far everything seems to be functioning well. I can scroll horizontally using buttons and swipe gestures successfully on the simulator. However, when I view the website on a real mobile d ...

Is there a way to achieve a marker-style strike through on text?

I'm attempting to create a strikethrough effect for a marker, just like the one shown in the image below. https://i.sstatic.net/2FQkD.png In my efforts to achieve this effect, I have tried wrapping the text within two span elements. The inner span ...

The contents table remains fixed in the top right corner as you scroll

I have developed an Angular app with a table-of-contents component that only displays two items. The code for the script is as follows: ts import { Component, OnInit } from '@angular/core'; import { pdfDefaultOptions } from 'ngx-extended-p ...

Which is better for creating hover effects: CSS3 or JavaScript?

When hovering over a link, I want to highlight a specific picture and blur the rest. Here's my HTML code: <body> <div id="back"> <div id="one"></div> <div id="two"></div> </div> ...

Ways to change the border color of Bootstrap cards

While working on my webpage, I utilized bootstrap cards to maintain a clean and organized layout. By default, bootstrap cards are white in color. Unlike the navbar, where you can easily set color options like navbar-dark, changing the color of the cards re ...

Create a DIV element that completely fills the vertical space available

My webpage is currently looking quite empty, with only one DIV element present: <div style="height: 20%; min-height: 10px; max-height: 100px; width: 100%; background-color: blue;"></div> I' ...

Sorting through mongoose information on the front end using EJS depending on a dropdown pick

Beginner embarking on my inaugural project here. I have developed 2 Mongoose schematics and models for managing categories and products. The products are nested within the corresponding categories model. Using Node and Express, I successfully sent all ca ...

Ways to resolve the issue of the search icon adapting to the selected value of the dropdown menu

Take a look at this. <!DOCTYPE html> <html lang="en"> <head> <!--REQUIRED META TAGS--> <meta charset="utf-8"/> <meta name="viewport" content="width=device-widt ...

Make sure to keep the <div> element nested within the image

I'm working on creating a photo album that displays images in full screen and allows users to navigate using arrows. Check out my progress here: https://jsfiddle.net/q49wzey6/ Here's the HTML code I'm using: <div class="main"> &l ...

Activate a button with jQuery when a key is pressed

Currently, I have two buttons set up with jQuery: $('#prev').click(function() { // code for previous button }); $('#next').click(function() { // code for next button }); My goal now is to implement a .keypress() handler on the ...

Exploring the depths of Cordova's capabilities: implementing a striking 3D front-to-back screen flip effect

Recently, I came across an interesting app that had a unique feature. By clicking on a button, the entire screen would flip from front to back with a 3D effect on iPhone. It was quite impressive to see in action. The developer mentioned that he achieved t ...

I am struggling to make my Bootstrap 5 Navbar transparent. Can anyone help me figure this out?

I've been struggling with my Bootstrap Navbar, which appears as white no matter what I do. I've tried numerous solutions from Stack Overflow to make it transparent without any luck. Even after setting the background to transparent and ensuring t ...

Is there a way to switch the cursor to a pointer when hovering over a bar on a ChartJS bar graph?

Here's the chart I created: createChart = function (name, contributions, idArray) { globalIdArray = idArray; var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, { type: "bar", data: { lab ...

Changing the background color of the dropdown button in Vue Bootstrap: A step-by-step guide

I've been struggling to modify the background color of a dropdown button, but no method seems to work. I've attempted changing it by using ID, removing its class and applying a new one, and even using !important to override the styles, but the ba ...

A Guide to Making a Floating Widget That Can Move Beyond the Boundaries of a Website in React

Currently, I am in the process of developing a project that requires the implementation of a floating widget capable of overlaying content not just within the confines of the website, but outside as well. This widget needs to have the ability to remain on ...

Create animations for SVG paths and polygons that move along specified paths

I am trying to animate both a path and a polygon in an SVG arrow along the same path. Currently, I have successfully animated the path using CSS, but I am struggling to figure out how to move the polygon along the path at the same pace. <svg id="La ...

Using blending modes with gradient colors in an SVG design

I'm struggling to get my logo to change colors upon scrolling into a button with similar gradient colors, but I just can't seem to make it work. Can anyone lend me a hand? Thank you! Take a look at my Logo. I've attempted to add some styles ...