The div is not completely filled with the background color

I've encountered an issue with filling the center content (div) with a background color.

The element with id body-content should be filled with a blue color, but it's not stretching to full height as expected.

Sample HTML code:

<div id="body-content">
    <iframe id="promo-video" width="40%" height="315" src="" frameborder="0" allowfullscreen style="margin-bottom: 20px;"></iframe>
    <script language="javascript" type="text/javascript">
        $(document).ready(function(){
            var y_pos = $('#search-panel').position().top;
            $('#promo-video').css('top',y_pos);
        });
        function sho(a){
            if (a=='1'){
                document.getElementById('criteria-1').style.display = "block";
                document.getElementById('criteria-2').style.display = "none";
                document.getElementById('criteria-3').style.display = "none";
            }
            else if (a=='2'){
                document.getElementById('criteria-1').style.display = "none";
                document.getElementById('criteria-2').style.display = "block";
                document.getElementById('criteria-3').style.display = "none";
            }
            else if (a=='3'){
                document.getElementById('criteria-1').style.display = "none";
                document.getElementById('criteria-2').style.display = "none";
                document.getElementById('criteria-3').style.display = "block";
            }
        }
    </script>
    <div id="search-boxes">
        <div id="search-panel">
            <form id="search-form" name="search-form" onsubmit="return false;">
                <fieldset style="margin-bottom:8px;">
                    <legend><i>Find By</i></legend>
                    <input type="radio" name="sp" onclick="sho(1);" checked/>A 
                    <input type="radio" name="sp" onclick="sho(2);"/>B
                    <input type="radio" name="sp" onclick="sho(3);"/>C
                </fieldset>
                <p>
                        <select name="spe" id="criteria-1">
                            <option value="g">G</option>
                            <option value="c">C</option>
                            <option value="ge">Ge</option>
                        </select>
                        <input type="text" style="width:97%;vertical-align:center;display:none;height:24px;padding-left:8px;" placeholder="Or find a.." id="criteria-2"/>
                        <input type="text" style="width:97%;vertical-align:center;display:none;height:24px;padding-left:8px;" placeholder="Or find b.." id="criteria-3"/>
                </p>        
                        <select name="city" style="width:49%;">
                            <option value="any-city">In City</option>
                            <option value="mumbai">Mumbai</option>
                            <option value="nyc">New York</option>
                        </select>
                        <select name="locality" style="width:49%;">
                            <option value="anywhere">Near Area</option>
                            <option value="vasant-vihar">Vasant Vihar</option>
                            <option value="andheri">Andheri</option>
                        </select>
                        <br><br>
                    <input type="submit" class="button_g" name="submit-search" value="Search for A">
                </form>
            </div>
        </div>
    </div><!-- End of Search boxes -->

</div><!-- End of body content -->

CSS styles:

#search-boxes{
    margin: 40px;
    display: inline-block;
    float: right;
    margin-right: 8%;
    clear: both;
    width: 450px;
}

#search-panel{
    border: 6px solid #c6e7f8;
}
#search-panel{
    text-align: center;
    padding: 30px;
    padding-top: 20px;
    padding-bottom: 20px;
    width: 400px;
    background-color: #ffffff;
    font-family: "Segoe UI Semibold", sans-serif;
}

#search-boxes select{
    width: 100%;
    height: 30px;
}

#promo-video{
    position: absolute;
    margin-left: 8%;
    border: 6px solid #d9d9d9;
}

#body-content{
    background-color: #e9f6fc;
/*  background: linear-gradient(to bottom, #e9f6fc 50%, white);
    background: -webkit-linear-gradient( to bottom, #e9f6fc 50%, white);
    background: -moz-linear-gradient( to bottom, #e9f6fc 50%, white);
    background: -o-linear-gradient( to bottom, #e9f6fc 50%, white);
*/  margin-top: 0px;
    margin-bottom: 0px;
    margin-left: 0px;
    margin-right: 0px;
    padding: 40px;
    vertical-align: middle;
}

I attempted to solve the problem by using the clear property for floating items, but it didn't work. What could I be missing?

Another challenge arose with the linear gradient, where I intended for the blue color to extend only up to 50% height, yet it fills up to 90% when the blue color spans the entire body-content.

Answer №1

Give this a shot:

#main-content {overflow: hidden;}

This code will make the main-content div encompass its floated elements. While there are alternative ways to contain floats, this approach is usually the most straightforward.

Keep in mind that since your iframe is styled with position: absolute;, the only way to clear it is by setting a height on the container, which may not be ideal. It's recommended to float the iframe as well for better results.

Answer №2

Initially, the code provided did not produce a layout resembling the screenshot described (with the frame covering the search boxes and the blue background extending further down). However, modifying the position:absolute; in the #promo-video style to float: left;, and adding an additional float: left to #search-boxes, resulted in a similar appearance.

To address this issue, simply insert

<div style="clear:both;"></div>
right after the closing tag for search-boxes.

In summary, utilizing floats is key to achieving the desired layout.

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

The magical unveiling of words through the art of animation

After spending considerable time learning how to code, I find myself seeking assistance in creating a specific animation. For the past two days, I've been struggling to bring my vision to life (see attached image). Unfortunately, my current knowledge ...

Safari 10.1.1 is encountering an issue with accessing the window.innerWidth property

I'm currently working with a script that dynamically changes the font size based on the viewport size. It seems to be functioning properly in most browsers, except for Safari (I've only tested on version 10.1.1). https://i.sstatic.net/UX3az.jpg ...

Tips for assigning a background image value in Vue by utilizing a URL produced by an API

I'm facing a challenge in setting the background image of my #app element in Vue to the response obtained from Unsplash's API. Although I can fetch the image URL, I'm struggling to apply that information to the background style element. My ...

Center-aligned vertical Bootstrap 4 card collection

I am attempting to vertically align (center) the card deck below: <div class="container-fluid"> <div class="card-deck d-flex justify-content-center"> <div class="col-xl-2"> <div class="card d-flex> ...

Whenever I attempt to use window.print(), the styling gets completely messed up. I've experimented with both @media screen and @media print, but unfortunately, I

I am working on creating an invoice, the design looks perfect in the browser, but when I try to window.print() the style gets corrupted. I attempted to include @media screen and @media print, but I am still facing the same issue. The invoice form is incorp ...

Storing a value from an external JavaScript variable into an HTML variable involves a few key steps

Is there a way to transfer the jQuery variable value to an HTML variable? Take a look at my code, This is the JavaScript function that resides in an external script function createImage(settings) { var kk = createCanvas(settings)[0].toDataURL(' ...

There is an issue with XMLHttpRequest loading http://*********. The requested resource does not have the necessary 'Access-Control-Allow-Origin' header

Just getting started with node, javascript, and other related technologies. I encountered an Access-control-allow-origin error while attempting to execute a GET request using XMLHttpRequest. Despite searching extensively for a solution, nothing seems to be ...

I am struggling to make my button hover effects to function properly despite trying out numerous suggestions to fix it

As a newcomer, this is my first real assignment. I've managed to tackle other challenges successfully, but this one seems a bit more complex and I'm struggling to pinpoint where I'm going wrong. Despite googling various solutions, none of th ...

Tips for choosing elements based on a specific attribute (such as fill color) in D3.js using the SelectAll method

I have various sets of circles on a map - 10 red circles, 10 blue circles, and 10 green circles. Is there a way to use d3 selectAll or select to specifically choose only the red circles? Are there any alternative methods for achieving this? The color of ...

Identify all unticked checkboxes using jQuery

Looking for help with checkboxes: <input type="checkbox" name="answer" id="id_1' value="1" /> <input type="checkbox" name="answer" id="id_2' value="2" /> ... <in ...

Showing the Ajax response on an HTML webpage

After reviewing numerous similar questions, I still couldn't find the solution I was looking for. I apologize in advance if this is a duplicate inquiry. My goal is to display the Ajax response on the page once the window has loaded. Code HTML < ...

Executing PHP code on button click in HTMLThe process of running a PHP script when

I am currently working on a project that involves detecting facial expressions using Python. However, I need to pass an image to this code through PHP. The PHP code provided below saves the image in a directory. How can I trigger this code using an HTML ...

"Vanishing act: The mystery of the disappearing Bootstrap dropdown

I am currently using Bootstrap 3 in conjunction with Ruby on Rails through the Rails Tutorial Sample App. Within my application, users have the ability to like, or "savor," microposts, referred to as "pops." My goal is to display Gravatar icons of users wh ...

Unable to create a polygon on the Google Maps API using GPS coordinates inputted from a text field

I am currently developing an interactive map using the Google Maps API. The map includes a floating panel with two input fields where I can enter GPS coordinates. My goal is to create markers and connect them to form a polygon. While I can easily draw lin ...

Attempting to alter the appearance of my validation control by implementing a custom style sheet theme

After naming a style sheet theme Basic and applying it to my web.config file, I created a Validator class in the css file. Utilizing the cssClass attribute with the Validator type, I successfully adjusted the font-weight property but struggled to change th ...

Display toggle malfunctioning when switching tabs

I am currently working on implementing a search function with tabbed features. Everything seems to be displaying correctly without any errors. However, the issue arises when I try to click on any tab in order to show or hide specific content from other tab ...

My struggle continues as I attempt to vertically center Bootstrap icons next to text

Having trouble centering bootstrap star icons alongside review text in my website design. Even after embedding the svgs within my code and utilizing Bootstrap 4 classes, here's the current appearance: Review star icons and text layout: https://i.sst ...

What could be causing the width issue with my vertical Bootstrap 4 menu items?

I am facing an issue with creating a menu. While I have managed to implement the old bootstrap, the new flexbox feature is proving to be confusing for me. Specifically, I want to have a dark vertical side menu that is 80px wide, with the rest of the screen ...

The Bootstrap modal simply fades away without ever making an appearance

My bootstrap modal is not displaying on desktop, only showing a faded screen. It works fine on mobile and tablet devices. Any ideas why this might be happening? Here is the code: <button type="button" class="btn btn-primary" data-to ...

Android browsers display the input box with a shorter height when the input type is set to number

Currently, I am working on creating a form that includes a numeric input field which should display the numeric keyboard on mobile devices. For this purpose, I have used an input element with type=number. The input renders correctly on desktops, appearing ...