Optimal menu layout based on window dimensions

I'm encountering an issue with my menu layout: I have a container div set at 960px, which has a background image (image 2). I need to position another element to the left of image 2 that fits the space available on the left, and on the right side, there should be a div that fits the remaining space.

So, for example, if the resolution is 1024px, the left element should be 32px wide, the center should always be 960px, and the right element should be 32px. If the resolution is 2048px, the left element would be 544px, center: 960px, and right: 544px.

<div id="container-menu">
    <div id="left-bg">// This div needs to fit the space on the left //</div>
    <div id="center-bg">// Place menu and logo content here //</div>
    <div id="right-bg">// This div needs to fit the space on the right//</div>
</div>

Refer to the image below:

UPDATE:

Image 1 and Image 3 have a width of 1px and use repeat-x for the background

Image 2 has a width of 960px

All images are transparent PNG files.

Thank you!

Answer №1

To achieve this, utilize the CSS3 property called Flex.

Here is an example:

HTML

<div class="parent">
 <div class="left">1</div>
 <div class="middle">2</div>
 <div class="right">3</div>
</div>​

CSS

.parent {
    display: -moz-box;
    -moz-box-orient: horizontal;
    display:-webkit-box;
    -webkit-box-orient: horizontal;
    width: 100%;
}

.parent div{
    -moz-box-flex: 1;
    -webkit-box-flex: 1;
    height:40px;
}
.parent .middle{
    width:460px;
    background:yellow;
}
.left{background:red;}
.right{background:blue;}

Feel free to check out this demo link: http://jsfiddle.net/pMh97/1/

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

Join and authenticate

Currently, I am facing a rather peculiar issue. I have created a simple login form that seems to be functional halfway. Users can input their name and other details, but upon clicking the Submit button, I encounter an error stating "Undefined index: nameX" ...

Position the Crossmark to align with text using CSS styling

How can I properly align a crossmark and a checkmark with the text behind them? The checkmark looks aligned well, but the crossmark appears to be slightly off to the top-right. I'm hesitant to adjust margins and paddings as it may cause issues when th ...

Displaying an error message in the designated errors div is necessary when the regular expression does not produce a match

Is there a way to display an error message in the errors div when the jQuery match function returns false? <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link href="form.css"> ...

Adjust the parent div's background color when a radio button is selected

Is it possible to dynamically change the background color of a div that contains a radio button when the button is checked? Here is an example of the HTML code: <div class="custom-container"> <input id=“example” type="radio" name="opt ...

What are some effective ways to restrict users from downloading the HTML template from a demo site?

I'm looking to start selling HTML templates online, but I'm realizing that creating a demo page may lead users to simply download the template without purchasing it. How do other sellers prevent this from happening? What strategies can ...

Aligning text or icon to center in React

Need assistance with positioning an icon in the center of two boxes. Any guidance would be greatly appreciated. Thank you! ...

Using jQuery to create animated effects for hidden input fields

The struggle to smoothly animate and fade in a hidden text field can be witnessed in this example. The goal is to seamlessly move all elements around the text field and button while fading in/out the hidden element. However, it appears that towards the en ...

Utilizing routing in Sencha for seamless back button functionality

I'm new to using Sencha and I need help with implementing support for the back button in Android using Sencha Touch2 Routing. I read through the Sencha documentation, which mentioned scenarios like "#products/123". However, in my case, only the views ...

"Using jQuery to trigger a click event on a specific column within

Welcome to my HTML table. <table id="status_table" class="table table-bordered"> <tr> <th>Serial Number</th> <th>Product Number</th> <th>Description< ...

What is the correct syntax for implementing scrollTop and transform CSS effects in jQuery?

I find myself in a bit of a quandary, as this question may seem rather simple but it's causing me some confusion. I'm trying to navigate the CSS transform syntax within a jQuery script that calculates window height. Here is the code in question: ...

Steps for enabling/disabling dynamically added checkboxes dynamically

Using a map, I am generating dynamic checkboxes as shown below: {{range $key, $val := .package.Group_Name_Map}} <div class="row"> <div class="col-xs-12 col-sm-3 col-md-3"> <label><strong>{{$val}}</strong></la ...

Issues with Django and Bootstrap Dropdown Lists Functionality

I've been working on my Django web application and I'm facing an issue with getting the dropdown list to actually drop down when clicked. <div class="panel panel-default"> <div class="panel-body"> <div class="dropdo ...

How can I show a dynamic popover with specific content when a "Copy" action is triggered?

I am attempting to copy a value to the clipboard: /** * If the browser does not support direct clipboard manipulation, use an alternate method * This is used in the copyTextToClipboard function. * * Function found at: https://stackoverflow.com/a/3 ...

Steps for implementing a select all feature with jQuery

I'm currently working on a jQuery function that is acting as a select-all option. Everything is functioning correctly except that when I deselect any of the child elements from select all, the option remains enabled. My goal is to enable or disable th ...

Error encountered while validating jQuery word cloud

Can anyone please assist me with validating a jQuery word cloud in HTML5? I'm encountering issues with all of the rel values showing this error message: "Bad value 1 for attribute rel on element a: Not an absolute IRI. The string 1 is not a registere ...

A single click causes the entire row of cards to extend seamlessly

The cards on this tab were generated using a loop and the data is sourced from a database. When I click on the "Show More" button, the entire visible column expands along with it. The expansion does not reveal the content immediately; instead, the content ...

Creating event listeners for slides transitioning forwards and backwards in Swiper JS: How can it be done?

Is there a way to create separate functions for when the slider moves forward and when it moves back? The documentation only mentions an event (slideChange) that triggers whenever the slide changes in any direction. If you have any suggestions or methods ...

How to create a smooth and continuous scrolling effect in the Twitter Bootstrap Carousel?

I've implemented a carousel with 8 images using Twitter Bootstrap 3. Currently, the carousel displays 4 images at a time before jumping to the next set of 4. Is there a way to modify it so that the carousel scrolls continuously and slowly through all ...

Acquiring Backlinks from an HTML Document

Looking to streamline a workplace process, I have a webpage with around 20-30 links that all begin with specific words: Dim Browser, strOut Set Browser = CreateObject("InternetExplorer.Application") With Browser .Visible = False .Navigate "http://anee ...

Customizing Bootstrap Navigation: Creating Space Between Menu Items

I've configured my Bootstrap navigation with a dropdown toggle for "Coverage". I'm looking to decrease the spacing between each list item (li) under this dropdown. What CSS setting should I use to achieve this? Interestingly, when I apply float: ...