The background color feature of a div is malfunctioning

I have encountered a strange issue with one of my Div elements. When I add text inside the div, the background color sticks to the text. However, if there is no text present, the background color disappears.

Image with Text:

https://i.stack.imgur.com/oYKj2.jpg

Image without Text:

https://i.stack.imgur.com/Uei3J.jpg

Below is the HTML code snippet:

body {
  margin: 0;
  padding: 0;
  font-family: bebas;
}
header {
  max-width: 960px;
  height: 80px;
  margin: 0 auto;
  line-height: 80px;
}
#leftRuler {
  width: 15%;
  height: 80px;
  float: left;
  background: #f3af9d;
}
#bannerContent {
  width: 70%;
  height: 80px;
  float: left;
  background: #e8603c;
  line-height: 80px;
}
#rightRuler {
  width: 15%;
  right: 80px;
  background: #f3af9d;
  float: left;
}
#logo {
  height: 80px;
  float: left;
  font-size: 40px;
  display: block;
  color: #e8603c;
}
#menu {
  float: right;
}
#menu ul {
  padding: 0px;
  margin: 0px;
  float: right;
}
#menu ul li {
  display: inline-block;
}
#menu ul li a {
  text-decoration: none;
  font-size: 16px;
  color: #b9b9b9;
  margin-left: 20px;
}
#menu ul li a:hover {
  border-bottom: 2px solid e8603c;
}
#menu ul li .current {
  border-bottom: 2px solid e8603c;
  color: e8603c;
}
<header>

  <div id="headerContent">
    <div id="logo">
      JETRO
    </div>
    <nav id="menu">
      <ul>
        <li><a href="index.html">Home</a>
        </li>
        <li><a href="#">About Us</a>
        </li>
        <li><a href="#" class="current">Blog</a>
        </li>
        <li><a href="#">Portfolio</a>
        </li>
        <li><a href="#">Contact Us</a>
        </li>
      </ul>
    </nav>
  </div>

</header>

<section id="banner">
  <div id="leftRuler">

  </div>
  <div id="bannerContent">
    Blog
  </div>
  <div id="rightRuler">

  </div>

</section>

Answer №1

If there is no content, the "#rightRuler" div will not have a height and therefore will not be displayed.

To fix this issue, either set a height for the div or add at least one &npsp; character in it.

Answer №2

Kindly provide specific details on the desired output.

Based on my understanding, you also need a background color for the right div, correct?

To achieve this, simply adjust your CSS as shown below:

#rightRuler {
    width: 15%;
    right: 80px;
    background: #f3af9d;
    float: left;
}

Updated CSS code:

#rightRuler {
    width: 15%;
    height: 80px;
    background: #f3af9d;
    float: left;
}

Instead of 'right', specify 'height' in the CSS.

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

Creating square elements using only HTML and CSS

This is just a longer text to demonstrate multiple lines being centered. ...

Updating HTML label values using jQuery in a loop based on their index position

I am having an issue with my ajax call where I want to loop through each label in a class and set their value to the response returned from the server. However, the current code sets all labels to the same value instead of setting individual values based o ...

Having Difficulty Positioning Tooltip Beside Input/Label Field

I have created a tooltip using HTML and CSS that appears when hovering over an image. However, I am encountering alignment issues when placing the image next to a textbox/input as it is not inline with the input box, likely due to some absolute positioning ...

Unsuccessful passing of the popstate event in jQuery bind

Currently, I am working on a small demo using the History API, but I seem to be facing some challenges: $(window).bind('popstate', function(event) { console.log('pop: ' + event.state); }); When I click on the 'P ...

Is it possible to convert (HTML and CSS3 generated content for paged media) into a PDF format?

Would it be possible to convert a HTML document styled with CSS3 Generated Content for Paged Media into a PDF format? If such an application does not exist, what alternatives can I consider as the foundation for developing a converter? Thank you ...

What is the best way to connect individual buttons to a dynamic div that displays different content depending on the button clicked?

Hey there! I'm diving into the world of JavaScript and HTML, and I need some guidance on creating a menu that can toggle visibility of specific content in div(s) depending on which button (picture1-12) is clicked. My idea is to have one div that can d ...

Make the mp3 file automatically download/save as by forcing the link

My website has links to mp3 files using normal <a href="file.mp3"> tags. However, many users with Apple Quicktime installed experience the mp3 files opening instead of saving when clicking on the links. Is there a way to force the browser to save t ...

Guide to executing the "brew" command on a Windows operating system

Encountering the error message "'brew' is not recognized as an internal or external command" in the Windows command prompt. https://i.sstatic.net/suFT2.png Attempting to set up the codeigniter-reactjs-example project from github, where the init ...

AngularJS table with resizable columns for seamless data browsing

Most examples of expandable tables using ng-repeat feature a separate content for the expanded row, like an independent table inside the detail row. I have implemented many expandable tables using these methods, similar to the following: <tr ng-repeat ...

There is a collision of boxes occurring within the CSS

Help Needed: Overlapping Boxes in Responsive Design I am facing a problem with my CSS where the boxes on my website are overlapping when I shrink the browser window. The issue occurs as I resize the window, causing the boxes to overlap more and more. I ...

What could be preventing the background image from displaying properly?

I had the idea to create a game where players have to flip cards to reveal what's on the back, but I'm struggling to get the background image to display properly. As a newcomer to Vue, I'm not sure if I made a mistake somewhere. My intuition ...

Tips for displaying Japanese characters followed by numbers in a single line on a web browser using CSS

Combining Japanese characters with numbers without spacing can present formatting challenges. For example, with a string like "新しいフォルダ000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ...

Elements generated from bootstrap's divs are not produced in a single line

I'm attempting to have a div append multiple other divs with the class "card" from Bootstrap, but instead of being created in a horizontal line, they are stacked on top of each other. I have tried to modify the "card" class by adding display: inline- ...

Is there a problem with the alignment of

<s:form id="inputThresholdForm" name="inputThresholdForm" theme="simple"> <table border="0" class="display-table" cellspacing="2" cellpadding="2" height="100%" width="100%"> <tr> <td colspan= ...

Repeated Hover Effects on CSS Menu Icons

the webpage I need help with is (issue with general menu drop down) Hello I recently decided to enhance my menu by incorporating icons. I had successfully implemented a drop-down menu using only HTML and CSS, but when I attempted to add icons next to ea ...

Tips for aligning two canvases with different heights at the top in HTML5

My problem involves two canvases housed within a single <div>. Despite their different heights, they are currently aligned at the bottom. +-------+ + + +-------+ + + + + + + +-------+ +-------+ Is the ...

"Submitting an HTML form and displaying the response without redirecting to a

I created a basic portlet for Liferay that includes a form for inputting parameters to send to an external webservice. However, when I submit the form, I am redirected to the URL of the webservice. Is there a method to prevent this redirection and instead ...

Interacting with various cookies created from user-provided input (specifically from textboxes) simultaneously

I'm facing a challenging problem and I'm in need of some assistance. The task at hand is to create three text boxes for users to input values for cookies named: name, city, and hobby. Then, using a single button with an onclick event, a function ...

Images that have been resized on Android appear blurry when viewed on the second page

Customizing the Toolbar: #main_bar { background: url(../images/logo.jpg) 99% 50% no-repeat; background-size: auto 80%; } The original size of logo.jpg is 220x266px The toolbar has a fixed height of 46px Therefore, the background image appears t ...

Adjust the pagination page size based on the value in the Angular scope dynamically

My goal is to provide the user with the ability to adjust the number of rows displayed in a table. This feature is crucial for our web app, as it needs to be accessible on various devices and should allow users to customize their viewing experience to redu ...