Uncertainty surrounding the effectiveness of the display: block CSS property - my demonstration is not yielding the expected results

I encountered an issue while using display: block.

To better understand the problem I'm facing, please check out this example link:

Take a look at the HTML code below:

<div id="container">


    <div id="titleBox">
        <p id="myTitle">Promoting Investment in Agriculture</p>
    </div>

    <div id="columns">
        <div id="first">
            <p>BLA BLA BLA</p>
            <p>BLA BLA BLA</p>
            <p>BLA BLA BLA</p>
        </div>

        <div id="second">
            <p>BLA BLA BLA</p>
            <p>BLA BLA BLA</p>
            <p>BLA BLA BLA</p>
        </div>
    </div>

    <div id="reportBox">
        <p>REPORT</p>

        <div id="flagsContainer">

            <div id="reportEng"></div>
            <div id="reportFrn"></div>
            <div id="reportSpn"></div>
       </div>

</div>
</div>

And here's the corresponding CSS code:

#titleBox{
    margin: 0 auto;
    width: 350px;
    background-color: #6da662;
    height: 40px;
    position:relative;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.28);
    -moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.28);
    -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.28);
}

#myTitle{
    /* centers an element within its container */
    margin: 0 auto;
    overflow: hidden;
    color: #fff;
    font-size: 16.5px;
    font-weight: bold;
    text-align: center;
    vertical-align: middle;
    line-height: 40px;
}

#columns{
    display: block;
}

#reportBox{
    margin: 0 auto;
    margin-top: 25px;
    width: 350px;
    height: 150px;
    background-color: #EFEFEF;
    border: 1px solid #DFDFDF;
    font-family: Verdana;
    display: block;
}


#reportBox p{
    text-align: center;
    font-size: 12px;
    font-weight: bold;
    color: #004673;
    padding-top: 5%;

}

#flagsContainer{
    width: 222px;
    height: 200px;
    min-height: 200px;
    margin: 0 auto;
}
#reportEng{
    float: left;
    width: 64px;
    background-image: url(United-Kingdom2.png); 
    background-repeat: no-repeat;
    margin-right: 10px;
    height: 60%;



    text-align: center;
}

#reportFrn{
    float: left;
    background-image: url(France2.png); 
    background-repeat: no-repeat;
    width: 64px;
    height: 60%;
    text-align: center;
    margin-right: 10px;
}

#reportSpn{
    float: left;
    background-image: url(Spain2.png); 
    background-repeat: no-repeat;
    height: 60%;
    width: 64px;
    text-align: center;
}




#first{
    background-image: linear-gradient(to bottom, #35F2EC 0%, #16B7D6 50%, #016D94 100%);
    width: 200px;
    min-height: 300px;
    border-radius: 10px;
    float: left;
    margin-bottom: 20px;
    box-shadow: 6px 7px 15px rgba(0, 0, 0, 0.37);
}

#second{
    background-color: #8FBC8F;
    width: 200px;
    min-height: 300px;
    border-radius: 10px;
    float: right;
    margin-bottom: 20px;
    box-shadow: 6px 7px 15px rgba(0, 0, 0, 0.37);
}

Below the #titleBox div, there is a container div called #columns containing two floated columns #first and #second.

My goal is to have the #reportBox div centered UNDER the #columns div instead of between the two columns.

Despite setting display:block on the #columns div and the #reportBox div, I haven't achieved the desired outcome. Any suggestions on how to display the #reportBox under the #columns div?

Thank you,

Andrea

Answer №1

Experiment

Add the following CSS property to #reportBox:
clear: both;

The rationale behind this suggestion is that floated elements float in relation to subsequent elements. By applying clear: both to the element, you are indicating that you want the following element to appear after all floating elements. This recommendation is not related to the display: block; property. By default, divs have a display: block; setting (unless overridden by a float).

Answer №2

Expanding on the previous comment, there is an issue with the #columns element lacking a defined height. When you apply the float property to both #first and #second, which are independent divs, it creates empty space for #reportBox.

There are two solutions in this scenario:

#reportBox {
    clear: both;
}

This option will clear both floating elements on the left and right side.

or

#columns {
    min-height: 300px;
}

By setting a minimum height for the container of #first and #second, it will push #reportBox downwards since it's not within the same container.

I hope this explanation clarifies things for you.

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

what is the best way to showcase a nested ordered list with varying list-style-types using ckeditor 4?

Dealing with a legacy application that features CKEDITOR 4 integration has presented me with a challenge involving the display of a nested ordered list. The issue arose when a user added an ordered list using the bullet list plugin. I encourage you to tak ...

Managing mouse click events in jQuery

Here on SO, I successfully implemented the mouse down handler. Now, my goal is to separate these functions into their own file named test.js. Within test.js, the code looks like this: function handleMouseDown(e) { console.log('handleMouseDown&ap ...

Finding a nested HTML element within a frame using Selenium without the presence of an iframe

Currently, I am delving into the world of Selenium using python to automate form filling on a particular website. However, my efforts have hit a roadblock as I am struggling to identify any elements within a frame and encountering a dreaded NoSuchElementEx ...

Can you explain the distinction between using ":" and "::" both before and after a word?

Can someone clarify whether I should use ":" or "::" before and after in this context? I'm curious if there's any distinction between the two. ...

Eliminate the horizontal overflow caused by the HTML video tag

I'm currently facing an issue with using a video as the background for a div on my website. The problem arises when I view it on a smaller resolution, causing overflow on the right side. I've been attempting to solve this without success... You ...

Achieve a seamless alignment of text/icons at the bottom of a row in BootStrap 4

Looking at this screenshot showing red and blue lines from a Firefox add-on called Pesticide: https://i.sstatic.net/h3Dmy.png Here is the code from the screenshot: <div class="row my-auto"> <p class="h6"> < ...

Getting the full referrer URL can be achieved by using various methods depending

I am currently working with ASP.Net. My goal is to retrieve the complete referrer URL when visitors arrive at my website from: https://www.google.co.il/webhp?sourceid=chrome-instant&rlz=1C1CHEU_iwIL457IL457&ion=1&espv=2&ie=UTF-8#q=%D7%90 ...

Creating a Drop-down Menu Item using React Material UI

I am experiencing an issue with displaying a MenuItem in my Dialog2 within my React app. Despite setting the zIndex: 1900 to a higher value than the two dialogs, the MenuItem remains hidden behind the dialogs instead of appearing at the front. Please revi ...

Generating a fictional list of items in a sequential order

I am managing a website that focuses on displaying the line of succession to the British crown. The main content of the site is structured as an ordered list using the <ol> tag. However, there is a unique challenge. Individuals occasionally drop out ...

Issue with Jquery focus on dropdown not working

I am facing an issue with setting up the dropdown feature for my list. It's similar to ul li:hover ul li. What I'm trying to achieve is something like ul li:focus ul li in jQuery because I don't think it can be done using CSS. The desired ou ...

How can we trigger the Skill bar effect upon scrolling to the section?

I have created a stunning Skill Bar that is functioning perfectly. However, I am looking to enhance the experience by having the skill bar effect trigger only when I scroll to that specific section. For example, as I navigate from the introduction section ...

I'm attempting to create a text toggle button for displaying more or less content

I am currently working on implementing a show more/show less button feature. However, the current version is not very effective as I only used slicing to hide content when the state is false and display it all when true. Now, my goal is to only show the ...

In CSS, when text within a tab div lacks spaces, it triggers a horizontal scrolling effect

My special css style for the div: .message-body { background: #5181a2; padding: 8px 5px; text-align: justify; } I aim to display this particular text inside the div similar to how 'hello hello' appears on the line above. ...

Automatically scraping Facebook API data with PHP

I'm completely new to php and I am looking for a way to automatically scrape metadata. I came across a solution, but I am unsure how to implement it in php. POST /?id={object-instance-id or object-url}&scrape=true Can anyone provide a sample php ...

Position a div element after another using the :after pseudo-element

My goal is simple to explain, but I have exhausted all my efforts trying to achieve it. I am hoping for the ★ symbol to appear immediately after the number 06 using jQuery. Any assistance would be greatly appreciated. The numbers are generated by a s ...

The marquee's position is reset the first time text is loaded dynamically from an API

In my angular project, I'm implementing a marquee feature to display data fetched from an API. However, I've noticed a strange issue where after a page reload, the marquee starts from right to left but once it reaches the end of the div, it reset ...

Enhance your Bootstrap navigation menu with eye-catching hover effects

Hey everyone, I'm a beginner in web development and I'm attempting to incorporate a hover effect into my navigation menu. I want it to look like the first example in this link: https://codepen.io/Calloumi/pen/vndlH I've tried to replicate t ...

What are some strategies for preloading a webpage to improve loading times?

My webpage contains multiple images, but the browser loads them one by one when a user visits the page. I would like to display a "loading" gif in the center of the page first and only show the entire webpage once all the images have been downloaded. Is ...

A guide on retrieving <div> element in a WordPress function PHP file

How can I wrap a div around the output from this code snippet? add_filter( 'the_content', function( $content ) { if (is_singular('cda')) { return get_the_term_list( get_the_ID(), 'cda_cat', 'Product:' ).$con ...

Change to a dark theme using React hooks in typescript

Hello, I am new to React and English is not my first language, so please excuse any mistakes. I have been trying to enable a dark mode feature on my website. Most examples I have found involve toggling between dark and light modes where you need to specify ...