Design a webpage header featuring three separate columns

The style.css file includes the following code:

#top{
    background: white;
    text-align: center;
    height: 180px;
    border-bottom: solid 1px #efeecc;
}

#topLogo{
    background: yellow;
    width: 25%;
    float:left;
}

#topDescription {
    background: red;

    width: 75%;
    text-align: center;
}

#topDepartment {
    background: blue;
    float:right;
    width: 25%;
    text-align: right;
}

This is how it appears in the index.html file:

<div id="top">
    <div id="topLogo">
        <a href="index.html"><img src="img/book.jpg" width="170" height="160" border="0"/></a>
    </div>
    <div id="topDescription">
        Page title
    </div>
    <div id="topDepartment">
        Category        
    </div>
</div>

Expected outcome:

Current outcome:

http://jsfiddle.net/p2T5q/

Answer №1

Check out this demonstration here: http://jsfiddle.net/p2T5q/7/

Cascading Style Sheets:

#header{
    background: white;
    text-align: center;
    display:table;
    height: 180px;
    border-bottom: solid 1px #efeecc;
}

#topLogo{
    background: yellow;
    width: 25%;
    display:table-cell;s
}

#subHeader {
    background: red;
    display:table-cell;
    width: 50%;
    text-align: center;
}

#navBar {
    background: blue;
    display:table-cell;
    width: 25%;
    text-align: right;
}

Answer №2

To simplify, the width of your div is currently set to 125%, so adjusting it to 100% would be necessary.

Additionally, consider adding a clear fix to the top div in order to properly contain all floating elements.

Avoid using inline styles and instead incorporate them into the CSS file. Setting a fixed width for an image within a div with percentage width may lead to issues when the user resizes their viewport.

Answer №3

Here is the updated solution with the corrected fiddle link and answer:

http://jsfiddle.net/p2T5q/2/

#top{
    height: 180px;
    border: solid 1px #555555;
    position:relative;
}
#top * {
    float:left;
}
#topLogo{
    background: yellow;
    width: 25%;
}
#topDescription {
    background: red;
    width: 50%;
}
#topDepartment {
    background: blue;
    width: 25%;
}

Ensure that the total width percentages sum up to 100% and float all elements to the left for proper positioning in relation to each other. Utilize the * selector to style all subelements. Kindly consider marking this as the accepted answer so I can earn my well-deserved coins and leave some additional remarks. Thank 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

utilizing Javascript to display file contents within a textarea

I am trying to utilize JavaScript to display the contents of a local file in a textarea tag. After some research, I came across the following solution: <textarea id="queryContent"></textarea> <input type="file" multiple id="queryInput"& ...

What is the best way to display a calendar for a read-only data input field?

I've been struggling to find a solution to this problem. My goal is to allow users to see a calendar when they click on my input field, but prevent them from changing the value once selected (or immediately revert back to the original value). Using t ...

Adding HTML created by PHP to a document fragment

I am trying to add a large amount of HTML generated by PHP (5000 div elements) to a document fragment and then append it to the body of the page. Here is an example of the HTML: <div itemscope itemtype="http://schema.org/Article"> <link itemprop ...

What is the best way to display the JSON array received from Postman on my HTML page using jQuery's Ajax success function?

I need help in iterating through the JSON array that is fetched from my API [{"a":1},{"b":2},{"c":3},{"d":4}]. How can I extract and display only the key-value pairs on my HTML output div? <body> <div id = "result" style = "color:green" > ...

Tips for achieving vertical alignment of a Bootstrap 4 Carousel slide while it transitions

I am currently working on building a carousel to showcase testimonials, but I am facing some challenges regarding the vertical alignment of the slides. My goal is to have the slides centered when they enter the screen, but currently they start at the top ...

Combining the jquery-UI slider functionality with the canvas rotate() method

Is there a way to rotate an image using html2canvas plugin and jQuery UI slider? I am new to programming and need some guidance on how to achieve this feature. Here is my current progress: http://jsfiddle.net/davadi/3d3wbpt7/3/ ` $("#slider").slider({ ...

Moving images displayed on a webpage

Is animating 5 pictures/photos a simple task? Take a look at this example: Which programming languages are recommended for achieving this effect? Thank you Tea ...

The autocomplete feature is situated quite a bit lower than the input box

One issue I am facing in my MVC Razor page is with the autocomplete functionality. When the textbox is first used, the autocomplete results appear below the textbox (as shown in this image), but on subsequent uses, it appears correctly directly below the t ...

How about linking together CSS3 animations?

Incorporating various classes to animate different elements on my webpage has been my latest project. On page load, I use addClass with jQuery to include these classes. I've been contemplating if there is a method to chain this process. For example, ...

Enhance the HTML5 Canvas arc by redrawing it upon hover

I have a challenge with my arcs: the first one loads on page-load, the second one loads on mouse-over, and the third one loads on mouse-out. However, I want the mouse-over-out effect to happen repeatedly rather than just once as it currently does. For ref ...

What is the best approach to prevent automatic zoom on a mobile-responsive website?

Looking to optimize my website for mobile viewing. Currently, when viewing on a mobile device, I have to zoom out to see the correct size. How can I ensure it displays properly without needing to zoom out? This is the code snippet I am using: <meta ...

Issues with external javascript link functionality

I'm having trouble connecting my external JavaScript file to my HTML code. I'm attempting to concatenate two strings using an input function and then display the new string in the empty text field. What could be causing this issue? Appreciate an ...

Utilize the Step Function in Jquery to create animated rotation at a specific degree angle

I have a div that is currently rotated at -35 degrees (as set in the CSS file). I would like to be able to click on it so that it rotates back to 0 degrees. Here is the code from my Javascript file: $("div#words").on("click",function(e){ $(this).anim ...

What could be causing a link anchor within a div with a lower z-index to be clickable in Internet Explorer on Windows Phone 7?

Two absolute positioned divs are stacked on top of each other. The first div has a z-index of 0 and contains the website's navigation. The second div has a z-index of 1 and is layered above the first div, hiding the navigation. Surprisingly, the me ...

When the IFRAME is resized, it actually returns the width of the window, not its own width

Here's some HTML code: <script> $(window).resize(function() { alert ('resize: '+$(window).width()); } ); </script> <iframe id = 'fr' src="/this" /> . . . $('#fr').width(300).trigger('resize') ...

Toggle menu on the left side, similar to Facebook's layout

I'm sure most people have come across the Facebook mobile app, as well as many flat UI pattern websites. I want to create a similar Left menu. Here is what I've done so far. Initially hide the menu (display:none) When the menu button is click ...

Alter the background color of a table cell in Angular HTML depending on a boolean value

Attempting to use Angular ng-class to set the background color of a table cell. I'm referencing code snippets from these resources: Angular: How to change the color of cell table if condition is true Change HTML table cell background color using ...

Instantly see changes without having to manually refresh the screen

I need help figuring out how to update my PHP webpage or table automatically in real-time without requiring a manual refresh. The current functionality of the page is working perfectly fine. Specifically, I want the page to instantly display any new user ...

Scrolling on an iPhone's Div

When I tried to access a website () using my iPhone and other gadgets, I encountered an issue with scrolling through the content. Clicking on the "Insight" link at the top-left corner led me to another page. On a computer, I had no trouble scrolling smoo ...

If the width is below 767, the previous code will not be effective in jQuery

Challenge: How can I ensure that the code within the if statement only executes when the screen width exceeds 767px, and does not work if it is less than 767px? Using jQuery: $(document).ready(function() { $(window).resize(function() { if ($( ...