The CSS layout is not positioning elements correctly

Here is a preview of how I want my final design to appear:

I am facing difficulty in properly aligning the two columns using my CSS code. Whenever I apply the float: left; property, the columns end up stacking on top of each other.

    /*------ Code starts here -----*/
    body {
    margin: 0 auto;
    padding: 0;
    font: .75em/1.5em Helvetica, Arial, sans-serif;
    color: #797267;
    width: 960px;
    background: #797267;
    }
    
    /**--- Headers ---*/
    
    header{
    width: 960px;
    height: 210px;
    background-image: url(../images/header-bg.jpg);
    }
    
    h1{
    width: 317px;
    height: 71px;
    padding: 64px 0px 0px 64px;
    margin: 64px 64px 0px 0px;
    
    }
    
    h2{
    color: #423b2e;
    size: 1.5em;
    }
    
    /*--- Navigation ---*/
    
    nav{
    color: #423b2e;
    }
    
    #current{
    color: #bf3102;
    }
    
    ul {
        list-style-type: none;
        padding: 84px 64px 0px 0px;
        float: right;
        clear: left;
        width: 277px;
    } 
    
    li {
        display: inline;
    }
    
    /*--- Banner --*/

    div{
    background-image: url(../images/main-content-bg.jpg);
    width: 960px;
    }
    
    div #banner{
    background-image: url(../images/banner.jpg);
    width: 890px;
    height: 200px;
    margin: auto;
    background-repeat: none;
    }
    
    /*--- Two-Column Layout Content (& Columns) */
    
    
    #column1of2{
    width: 450px;
    padding: 25px;
    }
    
    #column1of2.page-flip {
    background-image: url(../images/page-flip.gif);
    background-repeat: no-repeat;
    background-position: left bottom;
    width: 450px;
    margin: 0px 0px 45px 64px;
    }
    
    #column2of2{
    width: 260px;
    padding: 25px;
    }
    
    #column2of2.page-flip {
    background-image: url(../images/page-flip.gif);
    background-repeat: no-repeat;
    background-position: left bottom;
    width: 260px;
    margin: 0px 0px 45px 44px;
    }
    
    
    /*--- Footer Design Area --*/
    
    footer{
    background-image: url(../images/footer-bg.jpg);
    background-repeat: no-repeat;
    color: #423b2e;
    size: .9em;
    text-align: center;
    width: 960px;
    padding: 92px 0px 0px 0px;
    }
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>BusinessName</title>
    <link rel="stylesheet" href="css/main.css" />
    </head>
    <body>
    <header>
    
    <h1><a href="index.html">Business Name</a></h1>
    
    <nav>
    
    <ul>
    <li><a href="index.html" id="current">Home</a></li>
    <li><a href="about.html">About</a></li>
    <li><a href="services.html">Services</a></li>
    <li><a href="contact.html">Contact</a></li>
    </ul>
    
    </nav>
    
    </header>
    
    <div id="main-content">
    
    <div id="banner">
    
    </div>
    
        <section id="column1of2" class="page-flip">
    
            <h2>Who We Are (Header 2)</h2>
    
             <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod bibendum laoreet.</p>
             
            <p>Nullam ultricies sem eget ornare lobortis. Phasellus leo ante, accumsan at felis nec urna.</p>
            
    <p>Donec aliqueta pulvinar mauris vitae fermentum. Vestibulum placerat dictum tincidunt. Suspendisse potenti.</p>
     
        </section>
        
        <section id="column2of2" class="page-flip">
     
            <h2>How You Can Benefit (Sub-header 2)</h2>
            
            <p><img width="70" height="70" alt="placeholder image" src="images/sample-thumb1.jpg" /> Sed lacinia porta mattis.</p>
    
      <p><img width="70" height="70" alt="placeholder image" src="images/sample-thumb2.jpg" /> Etiam vulputate mi et nunc facilisis, vel iaculis purus tempus.</p>
    
            <p><img width="70" height="70" alt="placeholder image" src="images/sample-thumb3.jpg" /> Vivamus consectetur massa ac blandit fringilla.</p>
    
        </section>
        
    </div>
    
    <footer>
    
    <p>&copy; Business Name. All rights reserved. </p>
    
    </footer>
    </body>
    </html>

Answer №1

It appears there is a misunderstanding. The CSS property float: left; does not seem to be affecting the layout of the columns.

Answer №2

Have you attempted to use the Display:inline property without referencing your code?

Answer №3

I believe this solution will meet your needs as I don't have access to your images, so I have set the background color for demonstration purposes.

body {
    margin: 0 auto;
    padding: 0;
    font: .75em/1.5em Helvetica, Arial, sans-serif;
    color: #797267;
    width: 960px;
    background: #797267;
}

/**--- Headers ---*/

header  {
    width: 960px;
    height: 210px;
    background-image: url(../images/header-bg.jpg);
    background-color:red;
}

h1  {
    width: 317px;
    height: 71px;
    padding: 64px 0px 0px 64px;
    margin: 64px 64px 0px 0px;

}

h2  {
    color: #423b2e;
    size: 1.5em;
}

/*--- Navigation ---*/

nav {
    color: #423b2e;
}

#current    {
    color: #bf3102;
}



ul {
    list-style-type: none;
    padding: 84px 64px 0px 0px;
    float: right;
    clear: left;
    width: 277px;
} 

li {
    display: inline;
}

/*--- Banner --*/

div {
    background-image: url(../images/main-content-bg.jpg);
    width: 960px;
    background-color:black;
}

div #banner {
    background-image: url(../images/banner.jpg);
    width: 890px;
    height: 200px;
    margin: auto;
    background-repeat: none;
    background-color:green;
}

/*--- Two-Columns Content --*/


#column1of2 {
    width: 450px;
    padding: 25px;
    float:left;
    background-color:yellow;
}

#column1of2.page-flip {
    background-image: url(../images/page-flip.gif);
    background-repeat: no-repeat;
    background-position: left bottom;
    width: 450px;
    margin: 0px 0px 45px 64px;
}

#column2of2 {
    width: 260px;
    padding: 25px;
    background-color:blue;
    float:left;
}

#column2of2.page-flip {
    background-image: url(../images/page-flip.gif);
    background-repeat: no-repeat;
    background-position: left bottom;
    width: 260px;
    margin: 0px 0px 45px 44px;
}


/*--- Footer --*/

footer  {
    background-image: url(../images/footer-bg.jpg);
    background-repeat: no-repeat;
    color: #423b2e;
    size: .9em;
    text-align: center;
    width: 960px;
    padding: 92px 0px 0px 0px;
    background-color:green;
   clear:both;
  
}
<header>

            <h1><a href="index.html">BusinessName</a></h1>

            <nav>

                <ul>
                    <li><a href="index.html" id="current">Home</a></li> 
                    <li><a href="about.html">About</a></li>
                    <li><a href="services.html">Services</a></li>
                    <li><a href="contact.html">Contact</a></li>
                </ul>

            </nav>

        </header>

        <div id="main-content">     

            <div id="banner">

            </div>

            <section id="column1of2" class="page-flip">

                <h2>Who We Are (h2)</h2>

                 <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

                <p>Aenean pretium tellus  sit amet enim. Donec laoreet urna ut pede. Nulla eget magna at felis feugiat imperdiet.</p>

                <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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

            </section>

            <section id="column2of2" class="page-flip">

                <h2>How We Can Help (h2)</h2>

                <p><img width="70" height="70" alt="placeholder image" src="images/sample-thumb1.jpg" /> Sunc auctor, est a scelerisque vehicula, tortor nulla imperdiet elit, eu tincidunt ligula. </p>

                <p><img width="70" height="70" alt="placeholder image" src="images/sample-thumb2.jpg" /> Sunc auctor, est a scelerisque vehicula, tortor nulla imperdiet elit, eu tincidunt ligula. </p>

                <p><img width="70" height="70" alt="placeholder image" src="images/sample-thumb3.jpg" /> Sunc auctor, est a scelerisque vehicula, tortor nulla imperdiet elit, eu tincidunt ligula. </p>

            </section>

        </div>

        <footer>

            <p>&copy; BusinessName. All rights reserved. </p>

        </footer>  

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

Displaying content on the <div> element

Looking for recommendations for a jQuery plugin or JavaScript solution that allows me to load a full "view" into a <div> when a user clicks on a link. The challenge I'm facing is that I have 8 pages, with the Homepage consisting of 3 divisions: ...

Center the p tag vertically

To ensure the text inside the p tag aligns vertically in the middle, I've set a specific height for the tag. While this works perfectly for single-line text, it shifts to the top of the p tag when there are two lines of text. It's important to k ...

Ways to achieve a gradient effect on top of an image

Hey, I'm trying to implement a gradient on images in my project. Here's what I have so far: import Image from 'next/image' import Box from 'mui/material/Box' import PlayIcon from './PlayIcon.tsx' <Box ...

Working condition may vary depending on the size of the item

I have integrated the Masonry jQuery plugin into my design, but it is not functioning properly. The CSS class mentioned in the documentation only includes: width: 25% For my purposes, I modified it to: width: 24% float: left margin-right: 5px This modi ...

My images seem to lose control and go completely wild when I try to turn them into hyperlinks

Seeking advice on why my social icons are behaving strangely. This is a new issue for me and I suspect that some other CSS is causing the problem, but I can't seem to locate it. I want to ensure that the formatting of these images remains consistent ...

Creating an email body using css and html from a file on Android - how can it be done?

After searching extensively, I have come across a plethora of solutions on how to load HTML into the body of an email intent. However, I am struggling to find a way to load a file that contains CSS and HTML content. I have a specific program in which I dis ...

CSS struggles after implementing conditional checks in return statement for an unordered list

I'm encountering a CSS issue with the header section. When I include the following code snippet in my code to display a tab based on a condition, the entire header list doesn't appear in a single horizontal line: <div> {isAdmin(user) ? ...

To style the input box, apply the CSS properties "filter: alpha(opacity=70);" and "background-image: url(image.png);"

Individual functionality for both the form and css has been achieved, but when trying to implement them together, they do not work as intended. This integration is specifically for a windows sidebar gadget. Here is the structure of the form: <form nam ...

Is it possible to add padding to an HTML element without affecting its overall dimensions?

Is it possible to apply padding to a div without increasing its size? <div id="someDiv"> someContent </div> #someDiv{ padding: 1em; } One potential solution is to add another nested div within #someDiv and apply margin to that, rathe ...

Animate.css does not function properly when loaded locally

I'm currently using a Flask server to host an HTML file for testing purposes. Within the head of this HTML file, I have linked to a locally stored animate.min.css file (<link rel="stylesheet" type="text/css" href="{{ url_fo ...

Ways to adjust text color after clicking on an element

Just a heads up, I didn't write all of the web-page code so I'm not exactly sure what pdiv is. But I want to see if I can fix this small issue [making text color change when clicked on to show which section you're reading]. This particular ...

Switch up the CSS variable within an embedded iframe

I'm in a predicament with a specific issue. I am currently utilizing Angular to incorporate an Iframe. Let's imagine the angular app as A and the Iframe as B. B is being loaded within A. Within B, I have utilized CSS variables to define colors. I ...

Side-to-Side Bootstrap Display Panel

I have been attempting to customize a Bootstrap panel to create a horizontal version, but I am struggling to align the panel heading vertically with the content in the panel body. I believe it may be related to clearing the divs. Front-end development is ...

Insert content into a designated DIV

Progress bars are essential for tracking certain metrics. Take a look at the progress bars below: <div id="lifeBar-holder"> <div id="lifeBar"></div> </div> <div id="discretionBar-holder"> <div id="discretionBar"&g ...

Make the div disappear after a specified time

Does anyone know of a code snippet that can make a couple of div elements fade out after a specific time period? Currently, I have the following example: <div id="CoverPop-cover" class="splash"> <div id="CoverPop-content" class="splash-center"> ...

Center-align the table element

I've been struggling to center align this table element, specifically the one containing the square, but nothing seems to be working. Can anyone lend a hand in fixing this issue? <table> <tbody> <tr> <td>TURKEY - SU ...

Concealing scroll bars while still maintaining the ability to scroll by using overflow:scroll

Similar Question: How to hide the scrollbar while still allowing scrolling with mouse and keyboard I have created a sidebar for a web application that needs to enable users to scroll through it without displaying a scrollbar. The content is 500px high ...

How to target a class with a specific number in CSS selectors

My mobile hybrid application is built with Sencha Touch 2 and requires some customization based on the iOS version it's running on. In my Sass stylesheet, I originally had the following selector: .x-ios-7 { /* add iOS7 customizations here */ } How ...

Looking for assistance with my website's navigation bar and logo

Looking for assistance in moving my navigation buttons to each side of the logo. As a beginner in web design and CSS, I've been struggling with this task. Essentially, I want the "home" and "about" buttons on the left side of the logo, 16px apart from ...

Choose an input that is not grouped with the rest

I am facing an issue where I need to group these three inputs together as one continuous form. However, there seems to be a problem with the select input not aligning correctly with the rest of the form. Is there something that I might be doing wrong? & ...