What is the best method for achieving precise alignment of all my div elements?

My issue is that my three columns are not aligning properly with the rest of my content. While my header, footer, and featured sections all line up correctly, this is because they are contained within a single div rather than multiple ones. demo: http://jsfiddle.net/Zevoxa/3LDUd/

<body>
    <div id="header">
        <h1>LOGO</h1>
        <div id="nav">
            <ul>
                <li><a href="">Home</a></li>
                <li><a href="">Products</a></li>
                <li><a href="">Services</a></li>
                <li><a href="">About</a></li>
                <li><a href="">Contact</a></li>
            </ul>
        </div>
    </div>
    <div id="content">
        <div id="feature"><div style="text-align:center">
            <p>Feature<p>
        </div>
        <div class="article column1">
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        </div>
        <div class="article column2">
            <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
        </div>
        <div class="article column3">
            <p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio.</p>
        </div>
    </div></div>
    <div id="footer"><div style="text-align:center">
        <p>&copy; Copyright 2013</p>
    </div></div>
</body>
</html>

Answer №1

Visit this link for a solution

Ensure the width is set to a percentage rather than in pixels.

.column1, .column2, .column3 {
        background-color: #efefef;
        width: 30%;
        float: left;
        margin: 10px;
        display: inline-block;
 }

Answer №2

The articles now have a width of 33% with a 10px margin around the paragraph tags inside them. Additionally, I've included a clearer div for better organization. To view the changes, click on this link:

http://jsfiddle.net/dzHgX/

.column1, .column2, .column3 {
    background-color: #efefef;
    width: 33%;
    float: left;
    display: inline-block;
}
.column1 p, .column2 p, .column3 p {
    margin: 10px;
}

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

Canvas js displaying blank image instead of loading

I'm working on a website that includes a canvas with an image, but for some reason the image is not displaying and I can't seem to identify the issue in the code. var canvas = document.getElementById("canvas1"); var ctx = canvas.getContext("2d ...

Challenges faced with FormData during AJAX image uploads

I'm having trouble uploading an image via AJAX from a form. The console keeps showing me that the data is empty and I'm not sure how to get FormData to work correctly. Here's the error message: form.php?f3_file=:362 Uncaught ReferenceError ...

As the week progresses, the cells corresponding to each weekday will automatically highlight, from Monday through Sunday. If today is Tuesday, the Tuesday cell will be highlighted accordingly. Please refer

Take a look at the image provided in the link below. I need the library hours to be automatically highlighted each day. https://i.sstatic.net/LvqhR.png ...

Text that adjusts beautifully with Bootstrap 4's responsive design

When utilizing bootstrap 4, I aim to implement various font styles for different breakpoints. While media queries can achieve this functionality, Bootstrap's website presents an example as follows: html { font-size: 1rem; } @include media-breakpoi ...

Issue with Bootstrap 4 navbar collapse: it collapses correctly but unable to expand

I am currently learning how to use Bootstrap and I am experimenting with the navbar collapse feature. Although I have successfully collapsed the navbar, I am facing an issue where it does not expand when clicked on. I have exhausted all possible solutions ...

Reactive form utilizing Angular template

While working on our application, I observed a significant amount of duplicate code present in the HTML structure of our forms. Most input elements follow the same pattern, prompting me to consider creating a generic input component to streamline and tidy ...

Is there a way to create interconnections in all the HTML code I produce, without needing to use

Here is the code I am currently using. Strangely, everything below MSN.com turns into a link. I have double-checked my CSS and suspect that the issue lies there. However, I wanted to first explore if there might be an underlying problem in the HTML side of ...

Sending form data from View to Controller in ASP.NET's MVC framework

I have recently started exploring JavaScript and I am attempting to extract form data and convert it into a JSON object. Afterward, I want to initiate an AJAX call to retrieve the form results and display them within a ajax.done() function. Currently, I on ...

Removing Borders from Dropdown Tabs in Bootstrap Navbar: A Step-by-Step Guide

I am facing an issue while using Bootstrap 4, as I am unable to remove the border that appears when selecting the drop-down tab. Here is a glimpse of the problem You can view the Inspector View here Check out the relevant code snippet ...

Select from multiple levels in a dropdown menu HTML

I have encountered an issue while developing a website. I am trying to create a hierarchical list with multiple levels, but it seems that such feature does not exist (unless you know otherwise). As a workaround, I have implemented a system using invisible ...

Is there a way to prevent jQuery's .after() from modifying the HTML I'm trying to insert?

Trying to divide a lengthy unordered list into smaller segments using the following code: $('.cList').each(function() { var thisList = $(this).find('li') var thisLen = thisList.length for(var x=0;x<thisLen;x++) { ...

What is causing col-xs-0 to occupy the entire width of the row?

Here is the structure of my Bootstrap container: <main > <div class="row co-lg-12 col-md-12 col-xs-12"> <div class="col-lg-1 col-md-1 col-xs-1" style="background-color:red; height: 100vh;"></div> <div class="col-lg-4 col-m ...

Preserve the iframe src value in the dropdown menu even after the page is refreshed

I am trying to figure out how to prevent the iframe src from changing when I refresh the page, unless the user manually changes it using the dropdown menu with JavaScript. Can someone help me with this? <div class="row"> <div class="span9"> ...

What is the quickest way to redirect a URL in WordPress?

Is it possible to redirect a URL instantly in WordPress using this script code? JavaScript Code: jQuery(document).ready(function() { var x = window.location.href; if (x == 'http://example.com/') { window.location.hr ...

Steps for transferring an `<li>` element from one `<ul>` to another

<ul id="List"> <li class="li">1</li> <li class="li">2</li> </ul> <ul id="List2"></ul> const items = document.querySelectorAll(".li"); for(var i = 0; i < ...

Tips for adjusting the height of an iframe to ensure that all content is responsive and contained within a div set to 40% height

I am having issues with setting the height of an iframe that displays a PowerBI dashboard. My specific requirements are: The content within the iframe should be contained within a div that has a height of 40% and sets all its contents to a height of 100% ...

Legend alignment issue in Firefox disrupting Flexbox functionality

My fieldset has a legend containing text and a button. I am attempting to use flexbox to right-align the button within the legend. This setup works correctly in Chrome, but encounters issues in Firefox. I have managed to replicate the problem with a simpl ...

The delete function in aspx.cs never seems to be triggered from the .aspx file

I am encountering an issue with deleting items from a list, as my delete function in the .aspx.cs file is not being called. Below is my JavaScript code: function doTheDelete(doIDeleteExpenses) { if (selectedExpensesList.length > 0) { ...

The iPhone has a unique feature that allows users to scroll through images horizontally,

Is it possible to create an HTML div container with some CSS tricks that can display a horizontal scrollbar similar to the one seen on iTunes preview screenshots, specifically for Safari on iPhone? For example: I am looking to use this feature to showcas ...

Tips for automatically displaying the first option as selected in an HTML Select dropdown

I have an HTML select element where I want the option chosen by the user to not be displayed in the box. Instead, I would like the box to always show the first option, regardless of what the user selects from the dropdown menu. Below is my CSS code for sty ...