Utilize the full width available to create a flexible div element without any fixed sizes

I have come across similar questions, but none of them quite addressed my specific situation. My dilemma involves a tabbed navigation that can vary in size depending on the number of tabs added to it. Adjacent to the navigation, there is a second area housing a phone number display that I want to expand and fill the remaining space from right to left.

The width of both objects is unknown. My attempts to solve this issue included floating the navigation to the left, but it resulted in the blue background expanding behind the navigation, obscuring the view of background between the tabs. Using tables also proved unsuccessful as they either allocated width only to the blue area or collapsed the table's size to fit both elements without utilizing the full 960px width.

My preference would be to find a CSS solution for this layout challenge, although I am open to exploring JavaScript or jQuery alternatives if necessary.

Answer №1

If your navigation tabs are floated, simply include overflow: hidden; in the styling of the navy blue div (the one intended to occupy the remaining width).

Check out this brief demonstration: demo link here.

Answer №2

Wouldn't using width: 100% solve the problem?

Answer №3

Check out the working code on jsfiddle here

<div class="base">
    <div class="menu">
        <ul>
            <li>Hello</li>
            <li>Hello</li>
        </ul>
    </div>
    <div class="extra">
        Hello represents nothing but a greeting
    </div>
    <br clear="all"/>
</div>

CSS:

.base{
   width:100%;
   background:#c00;
   color:#fff;
   padding-top:15px;    
}
.menu{
    float:left;
}
.menu ul li{
    float:left;
    margin-left:5px;
    margin-right:5px;
    background:#000;
    padding:3px;
    border-radius:8px 8px 0px 0px;

}
.extra{
   float:right;
}

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

Disabling the submit button on an MC form - step by step guide

In order to create a multiple-choice question with radio buttons, each question must have only one answer choice. Each question should provide three options for the user to select from. It is necessary to validate whether the user has answered every questi ...

Arranging and overlaying images with HTML and CSS

Currently, I am in the process of developing a simplistic game through the use of HTML and CSS. The game consists of a background image portraying an alleyway, and my objective is to incorporate additional images on top of this background as clues within t ...

Tips for navigating through a JSON response to find specific information:

I'm currently looking for a way to search within a JSON result that has been returned. The result that was returned looks like this: {"Result":["Css","java","jquery","asp.net","mvc","javascript","asp","c#"]} My goal is to extract all the words that ...

adjust the thumbnail size of the royal slider jquery to automatically fit the content width

Seeking assistance with the royal slider plugin. I am looking to set the width of the thumbnail images to auto, while also having the active pointer (.rsNavItem .rsThumb .rsNavSelected) width adjust dynamically based on the size of the corresponding imag ...

What strategies can I use to keep an element in place while implementing parallax scrolling?

Looking for some assistance with my Codepen project. I am attempting to replicate a layout similar to this BBC article design from the past, but hitting a roadblock with getting my image to be position fixed based on scrolling. I believe that if I can suc ...

Creating a slider directly under the header in an Ionic 3 application without any gaps

I need help with positioning a slider below the header within the ion-content. The issue is that I am experiencing unwanted white space on the top, left, and right sides, as depicted in the image. This is my HTML code for the slider: <ion-navbar colo ...

Having issues with ng-repeat not displaying any content

Let me describe the current situation I am facing: app.controller('ResourceController', function($scope, $sce){ var resourceData; $scope.data = ''; $scope.loadResources = function(){ $.get('con ...

I am having trouble placing the button within the image

Essentially, my goal is to place the button within the image and ensure it remains in its position when transitioning to mobile mode or adjusting window size. This is the desired outcome: https://example.com/image https://example.com/button-image .img ...

Finding a solution for odd css box-sizing behavior in Bootstrap 3 and eliminating the unwanted horizontal slider

My website built with Bootstrap 3 looks great in Internet Explorer, but in Chrome and Firefox there seems to be a persistent bottom slider and a small area on the right side that remains visible even when I scale down to 1%. I suspect this issue is relate ...

Ways to interact with similar dynamic controls in Javascript

I have an aspx page with a Select box control: <select name="selViewPerPage" id="selViewPerPage" style="width:30px"> To ensure consistent styling across all browsers, I am replacing this html control with a dynamic select box using "selectBox.js". ...

Is there a way to automatically scroll to the last dynamically added div?

Within the chat.html file, I have included a div tag and implemented a script that dynamically adds rows to the div when a button is clicked. In another file named list.html, I have inserted an iframe tag with the src attribute pointing to chat.html. Howev ...

What is the best way to eliminate the space between two buttons in a table row or "column"?

Below is the code snippet that I am working with. I am trying to figure out a way to eliminate the space between the buttons both horizontally and vertically. Can someone guide me on how to achieve this? <%@page contentType="text/html" pageEncodin ...

New to JavaScript and Bootstrap - eager to learn by using Bootstrap 4 Chart Template, just need help with a small issue in the code

I am eager to dive into Bootstrap 4 and data visualization charts. I want to replicate the visualizations found in the link below. However, after copying and pasting the code into Atom, it's not functioning as expected. I ensured that I copied the HT ...

The AJAX request to the GitHub OAuth API using jQuery encountered an unknown issue and returned an unexpected error

Let me start by sharing the following code snippet: var requestAuthUri = 'https://github.com/login/oauth/access_token'; var ajaxArgs = { type : 'POST', url : requestAuthUri, headers : { &ap ...

don't forget about the vertical multilevel navigation in the menu state

I've been working on creating a vertical multilevel navigation menu, but I'm having trouble figuring out how to make the last menu state stay active when switching to a new page. I've explored options like using hash locations and cookies, ...

Fade one element on top of another using Framer Motion

Looking to smoothly transition between fading out one div and fading in another using Framer Motion, but facing issues with immediate rendering causing objects to jump around. Example code snippet: const [short, setShort] = useState(false); return ( ...

Use an if statement in Angular to conditionally add a title attribute with an empty value to HTML

How can I conditionally add the title attribute to a div without creating another div and using ngIf? If the permission is true, I want to include a title in my div. Here's what my current div looks like: <div (click)="goToChangelog()&quo ...

Submitting with enter key on typeahead suggestions

Seeking guidance on Bootstrap typeahead: how can I configure it to submit the entered text upon pressing the enter key? Specifically, if I type "hello" in the typeahead input and hit enter, how can I submit "hello"? I've successfully disabled the aut ...

iOS 11's Mobile Safari presents a challenge for web apps with the nav bar overlapping the top portion of the screen, cutting off content that relies on

When using 100vh on Mobile Safari, it fails to account for the height of the lower navigation bar. For example, look at the screenshot below. To show my app-like footer, I have to manually subtract 74px from the container's height in a somewhat messy ...

Guide on How to Show Only the Initial Word of an H2 Header Using JavaScript or CSS

Is there a way to display only the first word from an h2 heading? For instance: In the website's source code, it would appear like this <h2> Stackoverflow is an Ideal Place</h2> But on the live website, it should be displayed like this ...