Troubleshooting Problems with Positioning and Floating in HTML and CSS

I'm facing some challenges with clearing floats (or it could be something else?). My goal is to have the #newsbar div free from the previous floats so that its width can extend 100% across the page/browser.

I believe I've tried everything within my capacity, and this issue is really starting to frustrate me. This is how it currently appears:

Current display:

If anyone could review my HTML and CSS, I would greatly appreciate it. Thank you!

HTML & CSS Code:

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Rob's BBC</title>
       <meta charset="UTF-8" />
       <meta name="viewport" content="width=device-width; initial-scale=1" />
<style type="text/css">

    body {
       margin: 0;
       font-family: Arial, Helvetica, sans-serif;
    }

    #topbar  {
       background-color:#7A0000;
       width: 100%;
       height: 45px;
       color: #FFFFFF;
    }

    .fixedwidth  {
       width: 1050px;
       margin: 0 auto;
       /* background-color: green; */
    }

    /* BBC Logo */
    #logodiv  {
      padding-top: 8px;
      float: left;
      border-right: 1px solid #990000;
      padding-right: 15px;
    }

    /* Sign In Text */
    #signindiv  {
      font-weight: bold;
      font-size: 0.9em;
      float: left;
      padding: 5px 50px 8px 8px;
      border-right: 1px solid #990000;
    }

    /* Sign In Image */
    #signindiv img  {
      position: relative;
      float: left;
      margin: 6px 0 0 2px;
    }

    #signindiv p {
      float: left;
      margin: 10px 0 0 4px;
    }

    #topmenudiv  {
      float: left;
    }

    #topmenudiv ul  {
      float: left;
      margin: 0;
      padding: 0;
    }

    #topmenudiv li  {
      list-style-type: none;
      font-weight: bold;
      font-size: 0.9em;
      border-right: 1px solid #990000;
      height: 100%;
      padding: 15px 20px 10px 20px;
      text-align: center;
      float: left;
    }

    #searchdiv  {
      float: left;
      padding: 7px 0 0 10px;
    }

    #searchdiv input  {
      height: 25px;
      border: none;
      font-size: 0.9em;
      padding-left: 5px;
      padding-right: 22px;
      background-image:url('images/magnifyglass.png');
      background-repeat: no-repeat;
      background-position: right center;
    }

    .break  {
      clear: both;
    }

    #newsbar  {
       background-color:#990000;
       width: 100%;
       height: 45px;
       color: #FFFFFF;
    }
    </style>
    </head>
    <body>


    <div id="container">
        <div id="topbar">
            <div class="fixedwidth">
               <div id="logodiv">
                  <img src="images/bbclogo.png" alt="bbclogo" height="28" />
            </div> <!-- logodiv -->
            <div id="signindiv">
                <img src="images/signinlogo.png" alt="signinlogo" />
                <p>Sign In</p>
            </div> <!-- signindiv -->
            <div id="topmenudiv">
                <ul>
                   <li>News</li>
                   <li>Sports</li>
                   <li>Weather</li>
                   <li>iPlayer</li>
                   <li>TV</li>
                   <li>Radio</li>
                   <li>More...</li>
                </ul>
              </div> <!-- topmenudiv -->

            <div id="searchdiv">

              <input type="text" placeholder="search" /> 

            </div> <!-- searchdiv -->

            <div class="break"></div>

            <div id="newsbar">

              <div class="fixedwidth">

              </div>  

            </div> <!-- newsbar -->


            </div> <!-- fixedwidth -->
        </div> <!-- topbar -->

    </div> <!-- container -->


    </body>
    </html> 

JsFiddle: http://jsfiddle.net/1f030av9/

Answer №1

Great news - no more floating issue! All you need to do is move the <div> outside of its parent (which is another <div> with the class name "fixedwidth"). I also adjusted the padding to ensure that the search bar stays on one line.

Updated CSS:

#searchdiv  {
  float: left;
  padding: 7px 0 0 0px;
}

I removed the line padding-right: 22px; from #searchdiv input.

You can view the changes in this updated fiddle.

Answer №2

The width of your <div class="fixedwidth"> is fixed at 1050px, and the <div class="newsbar"> is nested within the class="fixedwidth". Even though you've defined 'newsbar' as 100%, its dimensions cannot surpass those of the parent div class="fixedwidth"

Answer №3

Check out your fiddle

The solution is working perfectly for me

The width is set to stretch to 100%

Although I made some minor adjustments that are not related to your specific problem

#newsbar  {
   background-color:#990000;
   width: 100%;
   height: 45px;
   color: #FFFFFF;
    clear:both;
}

#searchdiv  {
   float: left;
   padding: 7px 0 0 0px;
 }

Also removed the padding-right from #searchdiv input

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

Add unique content to a div upon page reload

Whenever the page is refreshed, I would like to add a random anchor from an array into a specific div. Here's my current code: <div id="exit-offer" class="exit-offer-dialog"> <div class="offer-content" id="banner-load"> <bu ...

What is the best way to implement a sidebar closing animation?

Utilizing both react and tailwindcss, I successfully crafted a sidebar menu that elegantly appears from left to right when the user clicks on the hamburger icon. However, my attempts to create a reverse animation as the sidebar disappears from right to lef ...

Having trouble obtaining data from the database and showing it on the webpage

I am encountering an issue with displaying content from a database named resources and a table within it also named resources. The code snippet causing trouble is as follows: mysql_connect('localhost', 'username', 'password', ...

What is the method of generating an HTML tag solely using CSS?

Looking to style HTML tags without altering them in any way? Consider this example: <div id="Code_G" class="editor-group"> editor-group<br /> <div id="Code_L" class="editor-label "> editor-label </div> < ...

What could be causing my CSS relative positioning to malfunction?

I am struggling to adjust the positioning of my divs using relative and absolute properties. Any advice on how to resolve this issue would be greatly appreciated. Thank you. Example Code: <div id="game"><img src="gta-game.jpg" height="100" width ...

I am interested in displaying or hiding a table depending on a specific condition in MVC 4

Looking at this MVC 4 Razor code snippet: <h4>You have @Model.Count() items up for sale currently. @Html.ActionLink("Add a new listing by clicking here", "Create")</h4> <br /> <table style="visibility: hidden"> .... I am seeking ...

Storing Selenium WebElement in memory for extended periods to retrieve its details: A guide in C#

I am using Selenium and C# to monitor a website for any new items that may appear. The website contains a list of <div class="myClass"> elements displayed in a table format with multiple sub-divs. Periodically, I scan all the displayed divs to check ...

Twitter Bootstrap 3.3.5 navigation menu with a drop-down feature aligned to the right

I've been attempting to position the drop-down menu all the way to the right, following the search input field and submit button. I've tried using pull-right and navbar-right classes without success. Is there a method to accomplish this? <na ...

Adjust the width of a box-shadow using percentage values in CSS

As we work on developing our tool according to the provided design, we are facing a challenge in drawing a line within a table row using box-shadow. The requirement is to have the line cover only 30% of the row width, rather than spanning across the entire ...

Is there a way to recycle an image and ensure that the web browser only needs to download it once?

Is there a way to effectively reuse the same image multiple times on my website without inefficiently downloading it each time? ...

Efficiently shrink column width in Material-UI's <TableRow/> using ReactJS and Material-UI

At the moment, I am utilizing ReactJS along with Material-UI. One issue I am encountering is that when using Material-UI's <Table>, the columns' width are automatically set based on content which results in all columns having equal width. H ...

Tips for locking the button in the navigation bar while scrolling

I noticed that when I have 6 fields in my navbar, with 5 of them being links and one as a dropdown, the scrolling of the page causes all fields to remain fixed except for the dropdown field.Check out this image description for reference https://i.stack.im ...

Font Awesome icons occasionally display as squares, but typically they render correctly

I've noticed a strange issue on my website where the font awesome icons sometimes display as squares instead of their intended design. After searching through forums, it seems that my situation is different from others experiencing similar problems. I ...

Guide to saving a Python docx file on the client side with the help of Ajax

I am currently using Python 3.6 with Django, and my code snippet is shown below: from docx import Document document = Document() document.add_heading('My docx', 0) document.save('myFile.docx') return HttpResponse(document, content_typ ...

Does anyone else have trouble with the Smtp settings and connection on Servage.net? It's driving me crazy, I can't figure it out!

Whenever I attempt to connect to send a servage SMTP, it gives me this error message: SMTP connect() failed. I have tried using the following settings: include('res/mailer/class.phpmailer.php'); $mail->SMTPDebug = 2; include('res/mai ...

"Comparison: Utilizing HTML5 Video Player with IE8 Embed Fallback versus Implementing Fixed

This dilemma has me at my wit's end. In an HTML5 Video element, I've included an mp4, ogg, and an embedded mp4 fallback. However, on the embed fallback in IE8, all my attempts to position the fixed element (#fixed) above it with z-indexing have f ...

Choose the data attributes you want to include and attach them to input elements using plain JavaScript

Creating a User Information form with a select element containing four options, each with data attributes. Under the select are input types to populate the data attributes when selected. Looking for help in achieving this using plain JS and onchange event. ...

What is the best way to calculate the width for each of the three elements in a row so that they all have 300px

Creating my own framework using flexbox has been an interesting journey. One of the major challenges I faced with flexbox is when dealing with an odd number of elements in a row, such as 3, 5, or 7. To tackle this issue, I decided to use JavaScript/jQuery. ...

What is the best way to align an element based on the position of another element?

I have integrated a calendar icon above a fullcalendar, and when I click on the icon, a react-datepicker pops up. Here is my CSS : .react-datepicker { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 0.8rem; background-color: ...

My custom Wordpress template experiences a hiccup with the jQuery slideshow, as it unexpectedly

Looking for help with a slideshow issue. Initially, it loads and transitions smoothly into one picture, but then stops working. I decided to use Chrome to troubleshoot the problem, and it informed me that it doesn't recognize the slideSwitch function ...