The use of CSS position: fixed can have a significant impact on

Having trouble with responsiveness in my nav-tabs when I apply position:fixed.

https://i.sstatic.net/BSiBe.png

The image above shows the actual view of my setup. I have two iframes - on the left side is the nav-tab (text-bucket, image-bucket...), in the middle is a slider, and on the right is another frame.

This is the HTML for the nav-tab:

<ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="#home">Text Bucket</a></li>
            <li><a data-toggle="tab" href="#menu1">Image Bucket</a></li>
            <li><a data-toggle="tab" href="#menu2">Table Bucket</a></li>
            <li><a data-toggle="tab" href="#menu3">View Selected Items</a></li>
            <li><a data-toggle="tab" class="prev" href="#preview">Preview</a></li>
</ul>

I tried to make the entire nav-tab section fixed by adding position:fixed.

CSS:-

.nav {
    padding-left: 0;
    margin-bottom: 0;
    list-style: none;
}
ul.nav-tabs {
    position: fixed;
    background-color: #fff;
    z-index: 1;
    /* width: 48%; */
}
.nav>li {
    position: relative;
    display: block;
}
.nav-tabs>li {
    float: left;
    margin-bottom: -1px;
}

https://i.sstatic.net/S4JTz.png

In the second image above, you can see that the preview tab stays out when I drag the middle slider to the left. This issue arises due to the use of position:fixed. If I remove it, the preview tab comes down responsively as expected.

Is there a solution to this? I want the tabs to remain position:fixed, but also be able to adjust when dragging the slider.

Answer №1

If you want to eliminate the position:fixed property for small devices, you can achieve this by utilizing media queries.

@media (max-width:992px){
  ul.nav-tabs { position:static; }
}

Answer №2

Adjust the width of .nav-tabs by adding a percentage value, similar to how it was done in the comment. For example:

.nav-tabs {
    left: 5%;
    width: 44%
}

Alternatively, you can try this:

.nav-tabs { 
left:0; 
width: 49%; 
padding-left: 50px; 
background:none;
} 

The icon position is determined by the padding left property.

If the solution provided does not work for your iframe setup, please feel free to clarify so I can adjust accordingly.

Answer №3

Alright, let's tackle this problem together.

I believe the issue lies in the positioning of your elements. When an element has a "fixed" position, it is taken out of the normal HTML flow and can be unaffected by other elements' positions (such as your panel on the right side).

To resolve this, I recommend using a bit of jQuery.

You can get the width of any element on the left side that takes up 100% of its container width (perhaps your slider) and apply this width to your fixed element. This should be done on page load and on resize so that it recalculates if the user manually changes the browser width.

Here's a sample code snippet to achieve this:

$(window).resize(function () {
    $('.nav-tabs').outerWidth($('.stuff').width());
}).resize();

In this code, replace stuff with the specific element on your left side mentioned earlier.

Feel free to check out the demonstration here: JSFIDDLE

Answer №4

Take a look at this clean Bootstrap solution I've put together: jsfiddle.net/6n0fctpc/

Here's the snippet with the code:

.right, .left {
  height:200px;
  background-color:orange;
  border: 1px solid white;
}
.left {background-color:green;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
  <nav class="navbar-fixed-top">
    <div class="container-fluid">
      <div class="row">
        <div class="col-xs-6">
          <nav class="navbar navbar-default">
            <ul class="nav nav-tabs">
              <li class="active"><a data-toggle="tab" href="#home">Text Bucket</a></li>
              <li><a data-toggle="tab" href="#menu1">Image Bucket</a></li>
              <li><a data-toggle="tab" href="#menu2">Table Bucket</a></li>
              <li><a data-toggle="tab" href="#menu3">View Selected Items</a></li>
              <li><a data-toggle="tab" class="prev" href="#preview">Preview</a></li>
            </ul>
          </nav>
        </div>
        <div class="col-xs-6"></div>
      </div>
    </div>
  </nav>
  <div class="row">
    <div class="col-xs-6 left">left </div>
    <div class="col-xs-6 right">right</div>
  </div>
  <div class="row">
    <div class="col-xs-6 left">left </div>
    <div class="col-xs-6 right">right</div>
  </div>
  <div class="row">
    <div class="col-xs-6 left">left </div>
    <div class="col-xs-6 right">right</div>
  </div>
  <div class="row">
    <div class="col-xs-6 left">left </div>
    <div class="col-xs-6 right">right</div>
  </div>
</div>

If you're interested in a similar issue with a narrowed fixed footer, check out my solution here.

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

Stop Bootstrap 4 from automatically wrapping columns to the next row

I'm experiencing an issue with a component using Bootstrap 4 where a column is expanding to another row due to the presence of a long text element with the "text-truncate" class. This results in Chrome vertically stacking the column below its intended ...

The copying of array values is not supported by Chromium

While utilizing Webworker to process an array of pixels from Canvas and then assign it back, I encountered a strange behavior. Firefox works flawlessly in this scenario, however, Chromium seems to insert an empty pixel array into the Canvas. Upon further ...

Changing the href attribute of a link element when it is clicked

Currently, I am in the process of developing a dynamic hyperlink that enables the downloading of an image fetched from the server. Below is the code snippet I have been working with: In HTML: <a class="btn" id="controlDownloadJPEG" download>Save & ...

Having trouble getting Bootstrap CSS to load in an .ejs file?

I am new to ejs and Node.js. I have a Node.js file. Whenever the localhost receives a get request, I redirect to the index.ejs file. The data is displayed in the browser, but the CSS is not loaded. Can someone help me identify the issue in this code? I hav ...

How can I remove the blue highlight on text fields in a Chrome Extension?

I am currently developing a Chrome extension that allows users to edit a small text field. However, I am encountering an issue with the blue highlight that appears around the text field when clicked - I find it quite bothersome. Is there a way, possibly t ...

Making a dropdown menu spin using Jquery and Javascript

I am in need of a unique solution for a dropdown menu that appears rotated 90 degrees anticlockwise. The goal is to have the dropdown select "button" text displayed vertically, with the options sliding out in a similarly rotated, sideways manner featuring ...

Horizontal scroll through Bootstrap 4 navigation tabs

I'm currently using the newest Bootstrap 4 nav-tabs feature to create tabs and I'm aiming to keep all the tabs in a single horizontal line that can be scrolled. I've attempted to use various JavaScript plugins, but none of them seem to func ...

Interactive chart embedded within a container

I have recently designed a card using Bootstrap and I would like to include a table with some data in it. However, I am facing an issue where the table data spills out of the card when I reduce the screen size for responsiveness testing. Could someone pl ...

How is it that the browser can determine my preferred font when all of them are labeled as Roboto?

Forgive my lack of expertise, but I have a question to ask... I've come across many examples that use the following method to load fonts from a local server: @font-face { font-family: "Roboto"; src: local(Roboto Thin), url("#{$robot ...

When a user repeatedly clicks the "see more" button, they will continue to receive no results multiple times

I have created a partial view and added the rendering in the Index page. A button (See More) triggers an AJAX call to the controller each time it is clicked, appending new data to the screen. The issue arises when there are no results left to display, and ...

Text obstructed by a sticky sidebar in Bootstrap

Currently, I am utilizing bootstrap to create a webpage featuring an affixed sidebar. However, I have encountered two issues when adjusting the screen size to that of a phone: The sidebar obstructs the text behind it, halting its movement beneath the sid ...

Adding an item to the shopping basket using a hyperlink in JSP

As a beginner in JSP, I am attempting to incorporate products from viewProduct.jsp into a basket found in basket.jsp. To achieve this, I understand that it requires an appropriate hyperlink that directs to basket.jsp within viewProduct.jsp. In my attempt, ...

Issue with Expo Google Places Autocomplete: ListView not clickable

I am currently encountering an issue with the GooglePlacesAutocomplete feature. When I input the address query, such as "São C," the 'listView' returns options like "São Caetano, São Paulo ...", however, when I attempt to select an option from ...

Troubleshooting Problem with Flexbox and Expandable/Accordion Side Menu

I currently have a wrapper class that contains an expandable side menu and main content section positioned side by side. The side menu acts as a filter for the content displayed in the main area, but I am encountering an issue where the rows separate when ...

Maintaining nth-child(odd) following filtering using jQuery

I am using a jQuery script to filter a table with multiple entries on this site. The filtering works well, but the issue arises when it comes to maintaining the correct tr:nth-child(odd) color that I have specified in my CSS. After filtering, the original ...

Entering numbers using <input type="number"> does not restrict invalid inputs, while accessing "element.value" does not give me the ability to make corrections

According to the MDN documentation on the topic of <input type="number">: It is said that they have built-in validation to reject entries that are not numerical. But does this mean it will only reject non-numerical inputs when trying to ...

Create a 2x2 HTML table where the first row remains undivided

I am working with an HTML table that is 2x2. Within this table, I am trying to achieve a layout where the first row consists of only one cell that spans the full width of the table, without being divided into two parts. ------- | | ------- | | | -- ...

A Bootstrap navigation sidebar with a secure footer and a div that can be scrolled

In the image below, you can see that the scrollable TreeView in the sidebar is not functioning properly. Additionally, I need to have a fixed footer for this sidebar that remains in place when users scroll through the content. How can I resolve this? http ...

javascript variable pointing to an unknown object

Below is the essential code snippet to consider: JS function ToggleRow(objTwistie, objRow) { if (objRow.style.display == "none") { objRow.style.display = ""; objTwistie.src = "../Images/SectionDown.gif"; } else { objRow.style.display = "n ...

What is the best way to center the text in the middle of a flex container?

I am struggling with the alignment of elements in my code. Here is what I currently have: HTML: </div class="container"> <footer>Maximilian Crosby ©</footer> </div> <div class="bot-bar" > <a href="./contact-u ...