What is the best way to remove the responsive features of a Bootstrap website when the width is less than 786

My current dilemma is with my Bootstrap-based website. I am trying to make it unresponsive for devices with a screen width of less than 768px, but responsive as usual for widths greater than or equal to 768px.

This is what I have attempted so far. In my global viewport setting:

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

I have also experimented with adding a CSS snippet like this:

@media (max-width: 768px) {
  @viewport {
    width: 1024px !important;
  }
}

However, this method did not produce the desired result of mimicking a width of 1024px. Any advice from those who have encountered similar challenges would be greatly appreciated. Thank you.

Answer №1

As stated in the Bootstrap documentation:

Steps to eliminate page responsiveness

  1. Exclude the viewport <meta> as mentioned in the CSS docs

  2. Override the width on each grid tier's .container with a single width value, for example width: 970px !important;. Ensure this is applied after Bootstrap's default CSS. If needed, use media queries or specific selectors instead of !important.

  3. If using navbars, eliminate all collapsing and expanding behavior. For grid layouts, incorporate .col-xs-* classes along with or instead of medium/large ones. The extra-small device grid will adapt to all screen resolutions.


Conditional exclusion of the viewport

To dynamically adjust the viewport, consider using JavaScript. Assign an id to your viewport meta element so it can be modified when the window width changes. For instance:

<meta name="viewport" content="width=device-width, initial-scale=1" id="viewport">

<script>
    window.addEventListener('resize', function() {
        var vp = document.getElementById("viewport");
        if (window.innerWidth <= 768) {
            vp.setAttribute('content', '');
        } else {
            vp.setAttribute('content', 'width=device-width, initial-scale=1');
        }
    }, true);
</script>

Overriding styles

Simply utilize media queries, as demonstrated before.

Answer №2

To achieve your desired outcome, consider the example below. It is important to highlight that @viewport has been directly defined in the CSS.

CSS

.col-md-2 {
  height:200px;
}
@viewport {
  width:device-width;
  initial-scale:1;
}

@media (min-width: 1000px) {
.col-md-2 {
    background:#ff0000;
    width:100%;
    zoom:.1;
  }
}
@media (max-width: 1000px){
.col-md-2 {
    background:#fff000;
    width:200px;
  }
  @viewport {
    width:1000px;
    initial-scale:1;
    zoom: 1;
  }
}

HTML

<div class="container">
    <div class="col-md-2"></div>
</div>

For a live demonstration of this example, feel free to click on this link. Notice how the zoom factor adjusts significantly when resizing the browser window.

It is worth mentioning that @viewport currently lacks formal standardization. You can check for supported browsers on this page.

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

Using flexbox for layout can cause issues when trying to position elements

I am facing a styling challenge with these buttons contained within a specific div. The CSS for this div is as follows: div { font-size: 5vw; font-family: Calibri, Helvetica, sans-serif; } div.IFlexible { display:flex; } div. ...

CSS reinitialization for the HTML5 button element

Is there a way to reset the HTML5 button tag so that it behaves consistently across all browsers? Currently experiencing issues with IE9 going haywire when trying to style the button tag. I am aware of using display:block; but what other solutions exist.. ...

Searching for a table row that corresponds to the content of a cell using Python and Selenium

If you need to retrieve the row element from an HTML table where the text in a specific cell matches the string 'Mathematik & Informatik'. Here is the structure of the HTML: <table class="views-table cols-4"> <thead> ...

Placing Django Template Blocks in Custom Locations within a Page

I am attempting a task in Django Templating Language without certainty of its feasibility (without relying on JS or similar methods). The code below (from Django-Oscar) displays 3 blocks of promotions on the main page: {# Render promotions #} <div id= ...

Personalize the color and icon of the checkbox marks in sapui5

I'm trying to customize the color of the tick on a UI5 checkbox. After inspecting the CSS, I noticed that it can be modified using the ::before selector: https://i.sstatic.net/2IMc4.png To target the checkbox, I added a class called .accept and defi ...

Editing HTML on an ASPX website can be a breeze with

Hello there, I've been tasked with editing a website for a client, but the site is located on a local web server and was designed using aspx. As I review all the files, I am encountering difficulty finding the HTML code associated with runat=server w ...

Styling is applied by Bootstrap to inputs in a form that are not required

I am currently working on validating a form for empty fields using Bootstrap. When submitting and validating the form with the form.checkValidity() method, I noticed that even the non-required fields are being styled as if they are required. Is this normal ...

The argument 'TabsCtrl1' is throwing an error as it is not recognized as a valid function and is showing as

I have encountered a problem with my controller, and I am seeing the following error message: Error: [ng:areq] Argument 'TabsCtrl1' is not a function, got undefined http://errors.angularjs.org/1.3.0-beta.11/ng/areq?p0=TabsCtrl1&p1=not%20a%20 ...

Utilizing CSS to incorporate percentage points

Currently, I am facing a challenge in implementing a vertical line with percentage marks. It needs to be positioned relative to the percentage bar, just like how it appears in the screenshot below: https://i.stack.imgur.com/CNWUV.png I attempted a basic ...

Combining Bootstrap with Rails

As I delve into the official documentation on incorporating Twitter Bootstrap in Rails, I stumbled upon an interesting tidbit: It mentions to eliminate all the *= require_self and *= require_tree . statements from the Sass file and opt for @import to im ...

Override the class inside the ul div

I am utilizing Dreamweaver's Spy menu without any sub items. By using a background image for "not active", another for "rollover" and attempting to apply one for "active". I have created a class for "active" and assigned it to one of the ul items. How ...

Forced line break at particular point in text

I would love to implement a line break right before the "+" character, either using css styling or through a different method. Is this task achievable? #myDiv{ width: 80% } #myP{ c ...

A guide on applying color from an API response to the border-color property in an Angular application

When I fetch categoryColor from the API Response, I set border-left: 3px solid {{element.categoryColor}} in inline style. Everything is functioning correctly with no development issues; however, in Visual Studio, the file name appears red as shown in the i ...

Navigating to DIV position while rendering JSP

Is it possible to make the browser automatically scroll to a specific DIV location when loading a JSP page? The DIV could be placed anywhere on the page and has a unique identifier. I am aware that this can be achieved using Javascript/jQuery, but I speci ...

Retrieving the specific value of an input from a group of inputs sharing a common class

After extensive research, I have not found a suitable solution to my specific issue. I am creating a block of HTML elements such as <div>, <span>, <i>, and <input> multiple times using a for loop (the number of times depends on the ...

Incorporating a classList.toggle into a snippet of code

button, p, h1, h2, h3, h4, h5, a{ /* Define specific elements to use "fantasy" font */ font-family: Tahoma; } #main_body{ margin: 0px auto; background-color: #dedede; } #top_body{ /* Remove margin for simplicity */ } #t ...

Tips on positioning an image at the center of an HTML page

When designing a website, I encountered an issue where only a portion of the image was displaying in the slider due to the fixed height of the div being set to 500. I want the full image to be displayed centered within the same height. <div id="myCar ...

Struggling to adjust the width of a div accurately following the population of AJAX content

This particular piece of code is responsible for populating an inner div within an image slider by making an Ajax call : $.ajax({ type: "GET", dataType: 'json', url: $(this).attr('href') }).done(function (result) { ...

Struggling to figure out the correct method for aligning calendar using bootstrap-datetimepicker?

Struggling with aligning the calendar correctly under a textbox while using bootstrap-datetimepicker in a form? The positioning seems off, and the calendar icon isn't where it should be. It's not behaving like a simple datetimepicker as shown in ...

Enhance the appearance of CardMedia in React Material UI with custom rendering options

I am curious about how I can customize the CardMedia component of React Material UI to achieve a design similar to this: https://i.sstatic.net/Spdbz.png In the desired result, there are 3 elements: The image itself in WebP format (see example) A dur ...