Issue with CSS floating and wrapping

I'm having some trouble explaining this concept clearly, but I'm attempting to achieve a layout where elements wrap around a block.

Here is an illustration of what I mean:

The issue lies with the code provided below. It aligns correctly when there are only 2 blocks, but as soon as additional blocks are added, they drop below the welcome block (as shown in the image).

The desired design includes 2 blocks alongside the welcome box, followed by 3 blocks beneath it. Therefore, the 3rd block should be positioned under the welcome block, while subsequent blocks will continue in a normal flow (with 3 blocks per line).

CSS

#welcome-block {
float: left;
width: 300px;
background: #fff;
}

#bingo-offers {
float: left;
margin: 0;
padding: 0;
overflow: hidden;
}
    .bingo-offer {
    float: left;
    width: 300px;
    background: #fff;
    margin: 5px;
    }
        .bingo-offer ul {
        margin: 0;
        padding: 0;
        }

HTML

<div>
        <div id="welcome-block">
            <h2>Welcome to Zesty Bingo</h2>
            <p>Zesty Bingo is the home of FREE Bingo!</p>
            <p>We have a huge selection of Bingo games to choose. Simple find a game, and click play. It’s as simple
            as that.</p>

            <p>Ensure you click the read more link on each game to find out more details and customer reviews on all
            of our hosted games.</p>

            <p>Good Luck and we wish you wealth and happiness from all the Zesty Bingo team.</p>
        </div>

        <ul id="bingo-offers">
            <li class="bingo-offer">
                <ul>
                    <li><img src="../img/winkbingo-146.png" alt=""></li>
                    <li><h3>Wink Bingo</h3></li>
                    <li>Free Cash: <span>£20</span></li>
                    <li>Join one of the biggest Bingo sites on the Internet and enjoy a whopping £20 bonus when you deposit £5!</li>
                    <li><a href="#">Play Now</a></li>
                    <li><a href="#">read more</a></li>
                </ul>
            </li>

            <!-- Additional list items here -->

        </ul>
    </div>

Answer №1

Modify the following:

<ul id="bingo-offers">

<li class="bingo-offer">

to be like this:

<div id="bingo-offers">

<div class="bingo-offer">

UPDATE: Avoid using <div id="bingo-offers"> altogether, simply remove those tags. Place the <div class="bingo-offer">s right after the <div id="welcome-block">.

Check out JSFiddle for more details

Answer №2

The reason for the issue could be related to the <ul id="bingo-offers"> element being used in your code.

Although the <ul> itself is floated left, it also has a width:100%; property applied to it.

To potentially improve the situation, consider removing the <ul id="bingo-offers"> element and changing the <li> tags to <div> instead.

You can test out these changes here: jsfiddle

Answer №3

adjusting width

#bingo-offers {
float: left;
margin: 0;
padding: 0;
overflow: hidden;
width:XXX;
}

Answer №4

#header-section {
float: left;
width: 400px;
background-color: #f7f7f7;
margin-right: 20px;
}

#gallery-items {
margin: 0;
padding: 0;
overflow: hidden;
}

#gallery-items > li.gallery-item{
    float:left;
    width: 400px;
    background-color: #f7f7f7;
    margin: 10px;
}

Implement the CSS provided above to style your website. For a visual representation, check out the link below.

http://example.com/view.php?name=Living%20Room%20Design

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

"Customize the appearance of your theme by adjusting the background and text colors when making a

Is there a way to dynamically change the style of a webpage based on user selection using CSS in AngularJS? I've searched online, but haven't found a solution that works for me. I have a CSS file with different styles and I want to apply these ...

What is the best way to get rid of an underline from a hyperlink

I am facing a peculiar issue where, with each image or word that appears ..... below I have already applied internal and external CSS styles like the following: a:hover { text-decoration: none; } a:link { text-decoration: none; } a:visited { ...

Increasing the height of child elements beyond the boundaries of their parent container

Is there a way to make three divs with fixed heights expand outside a full-width parent div, but only in terms of height, not width? Imagine the scenario depicted in the image below: What approach would be most effective in achieving this design? Check ...

Enable jquery offsetParent() function

$(document).ready(function(){ $("button").click(function(){ if ($("p").offsetParent().css("background-color") === "red") { $("p").offsetParent().css("background-color", "yellow"); } else { $("p").offsetParent().c ...

Tips for enabling multiple v-list-group components to remain open simultaneously (bypassing the default Vue behavior)

Currently, I am facing an issue with Vue's default behavior where only one v-list-group can be open at a time. I am using Vuetify 2.6 and have attempted to use the multiple prop without success. Additionally, individually assigning the :value prop to ...

Tips on creating a resizable box that can move from left to bottom and also from right to top

Hey there, I'm currently working on developing my own catalog and I'm in the process of creating a selection tool to allow users to zoom in on a specific part of an image. If you're interested, you can check out the project here. However, I ...

Automatic responsive navigation bar in mobile view

As a novice in web programming, I'm facing an issue where the navigation bar shifts to the bottom when the mobile screen size changes. Many solutions online use the hamburger style, which I find less appealing. Here is how the mobile view looks befor ...

Transitioning the implicit width

Using implicit width, which involves adding padding to an element containing text to give the parent container a specific but unstated width, can be quite elegant. However, it poses challenges when it comes to transitions. Is there a way to achieve a trans ...

Issues with displaying video content and controlling the Bootstrap 5 video carousel

I have encountered an issue while coding a website for a friend's company. He requested a video carousel to be added to his existing site, so I incorporated links and scripts for Bootstrap in order to create a gallery for his products and a carousel t ...

How can I adjust iframe content to fit properly on a mobile device screen?

I am facing a challenge where I need to embed an iframe into an external website over which I have no control. The only thing I can specify is the size of the iframe on my own website. My goal is to ensure that the content within the iframe adjusts to fit ...

The res.download() function in Express is failing to deliver the accurate URL to the client

When trying to utilize the res.download() method for downloading specific files from a server, there is an issue where triggering the res.download does not redirect the client to the correct URL. The files intended for download are located in a directory s ...

Having trouble adding flexslider before a div element with jQuery

Hey there! I recently got flexslider from woothemes.com. The page structure I'm working with looks something like this: <div class="parentdiv anotherdiv"> <div class="child-div1">some buttons here</div> <div class="child-div2"& ...

Challenges with looping in Jquery animations

I've been working on an animation function that I want to run in a loop. So far, I've managed to get it to work for one iteration, but I'm struggling to figure out how to repeat the loop a specific number of times. Below is the code for my a ...

What is the best way to switch between different styles for each paragraph using CSS?

I attempted to use the :nth-of-type selector, but I am uncertain if it is feasible or if it accomplishes what I desire. My goal is to create an alternating style: two paragraphs aligned on the left, followed by two on the right, and so forth, regardless of ...

Disappearing Into the Background Excluding Specific Divs

I have a dilemma with fading in and out a background image using jQuery fadeIn and fadeOut. The issue arises because my wrapper div contains elements such as sidebar and navigation that are positioned absolutely within the wrapper div, causing them to also ...

Switching the navigation drop down from hover to click: A step-by-step guide

I'm currently designing a responsive navigation bar with a dropdown feature that expands on hover. However, I've encountered an issue as this hover effect is not ideal for mobile devices. Therefore, I am looking to modify my navigation bar so tha ...

Conditionals in ng-class Syntax

I'm attempting to apply a class conditionally to an element, but I'm struggling with the correct syntax. I've experimented with the code below, but it's not functioning as expected: ng-class="{foo: bar === "true"}" The value of bar i ...

As one container is being moved, they both shift down simultaneously

I have set up a container named main that contains another container called banner, like this: <div id="main"> <div id="banner"></div> </div> Main has a gradient background and I want the banner to be positioned in the middle of t ...

Are there any portable stylus options available?

Hey there! I'm dealing with a situation where the computers at my school are locked down and I can't install software. Does anyone know if there's a way to compile my Stylus code without having to install Node first? Or perhaps, is there a p ...

The attempt to change the header's background color has proven to be unsuccessful

Hello this is my first question on stackoverflow so please forgive my lack of experience. I am attempting to modify the background color of an entire HTML document using the background-color property on the element. Despite changing some parts of the docu ...