Applying media queries to a <div> instead of the entire viewport can be a useful technique, especially when used in conjunction with

I am looking to create a dynamic layout where different content such as tables and masks can be displayed in multiple areas or columns on a website. Typically, the left column will contain a list, the middle column details of an entry, and the right column notes, help, and additional details. Since there are over 500 possible configurations with datatables.js, it's not feasible to define everything statically. Depending on the viewport size, only one or two of these areas may be visible at a time.

Users should be able to adjust the width of each area based on the total available space, so I am considering using Split.js (). The goal is for these areas to adapt to the available space within their container rather than the viewport directly. Unfortunately, this functionality does not exist natively.

My initial idea is to define styles for various width configurations using SCSS mixins and Bootstrap Mixin. Then, I would use media queries to apply these styles dynamically based on the current width set by split.js and window resize events. While this approach may work, it has limitations such as handling resize events and requiring manual setup.

<div>
    <div class="split" id="one"></div>
    <div class="split" id="two"><</div>
</div>
------------
@mixin one_xs {@include make-col($size, $columns: $grid-columns) } /*style for small list */
@mixin one_sd {..}
@mixin one_md {..}
@mixin one_lg {..}

@mixin two_xs {..}
@mixin two_sd {..}
@mixin two_md {..}
@mixin two_lg {..}

@include media-breakpoint-up(xs) {
    @include one_xs;
    #two { display: none}
}
…

@include media-breakpoint-up(lg) {
    #one .detect_xs {@include one_xs;}
    #one .detect_sd {@include one_sd;}
    #one .detect_lg {@include one_lg;}
    #two .detect_xsmall {@include two_xs;}
    …
}

<script> 
Split(['#one', '#two']);
...
window.addEventListener('resize', function() {
…
if ( $('#one').width() ) > 1024) { 
$('#one').AddClass(".detect_md");
…
}

Do you think this approach would work effectively? Are there alternative methods for implementing this concept more efficiently without necessarily relying on Split.js or Bootstrap? Any ideas or suggestions would be greatly appreciated.

Answer №1

After much searching, I have finally found a solution:

https://codepen.io/MichaelBootstrap/pen/vYLrzVE

This solution combines several elements:

The answer to the question at hand: jQuery UI Resizable alsoResize reverse

The library utilized can be found here:

Additionally, jQuery, Bootstrap, and DataTables are used. (No split.js was used)

You can implement Bootstrap and DataTables in each tab in a fully responsive manner and create your own CSS rules like so:

.your-tab[min-width~="400px"] h2 {
    font-size: 18px;
}

Utilize the Bootstrap mixin in conjunction with the above rule:

.your-tab[min-width~="400px"] h2 {
    @include make-col($size, $columns: $grid-columns)
}

Everything works smoothly. Please keep in mind that the deactivation of tabs shown in the example may not function correctly (Hardcoded for the second tab only).

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

Once the hidden DIV is revealed, the Youtube video within it begins to load

I currently have a hidden DIV on my website that contains a YouTube clip. My goal is to load the video in the background once the page has fully loaded, so that it's ready to play when the user clicks the button to reveal the DIV. However, at the mo ...

Content in Slider Exceeding Container Bounds

After successfully creating a slider using jQuery with the help of some Stack Overflow users, everything was working perfectly. However, when attempting to change the layout of the slider, it somehow broke and now all slides are being pushed out of the con ...

Modifying the input placeholder color with ng-style

I am working on setting the color of my input placeholder using a dynamic color defined in a $scope variable in my controller for my HTML code. The $scope variable is structured as follows: $scope.primaryColor={"color":colorVar}; //colorVar represents th ...

Transmit data to a modal using JSX mapping technique

When working with a map that renders multiple items, how can I efficiently pass parameters like the item's name and ID to a modal component? render(){ return( <div> <Modal isOpen={this.state.OpenDel ...

Retrieve the input value using jQuery

I'm having trouble retrieving the value from the first name input and passing it to a bootstrap alert when the user clicks the submit button. Below is the code snippet I have been working on: $(document).ready(function() { $("#submit-button").cl ...

Is there a way to determine if any word within a given text is present in an array?

Imagine you have the following full text: var nation = "Piazza delle Medaglie d'Oro 40121 Bologna Italy" And a given array like: ["Afghanistan", "Italy", "Albania", "United Arab Emirates"] How can we verify if the exact word Italy within that ent ...

Issue with Firefox mobile's camera functionality

I am facing an issue with my web app for mobile devices where I am trying to display the mobile camera using Firefox mobile browser. I am using nodejs with express as a server and connecting to the server via localhost with my smartphone. Although Firefox ...

Utilizing jQuery for Summation Calculation

How can I use jQuery to calculate the total sum of prices for all products in a table with the column name "price"? Once calculated, how do I store this sum in a variable? <table id ="tab"> <th>Product</th><th>Price</th> ...

The basic Node.js API for greeting the world encountered a connection failure

I'm currently working on setting up a basic hello world route using nodejs and express. After running node index.js, I see listening on port 3000 in the console, but when I attempt to access http://localhost:3000/helloworld, it just keeps trying to co ...

Choose the initial offspring from a shared category and assign a specific class identifier

I am trying to figure out how to apply the "active" class to the first tab-pane within each tab-content section in my HTML code. Here is an example of what I'm working with: <div class="tab-content"> <div class='tab-pane'>< ...

Active positioning within a parent div

I'm having difficulty getting a color picker JavaScript widget to function properly within a webpage that contains unchangeable elements. Some of these elements are causing the color picker to be displayed far below the link once clicked. Here is a si ...

Tips for transferring data from an HTML textbox to a JavaScript variable

I'm currently working on a form that fetches data from a database and dynamically stores it in a table. There's a button labeled "add" which, when pressed by the user, adds a new row to the table. I also have a hidden counter that keeps track of ...

Angular 6 TypeScript allows for efficient comparison and updating of keys within arrays of objects. By leveraging this feature

arrayOne: [ { id: 1, compId: 11, active: false, }, { id: 2, compId: 22, active: false, }, { id: 3, compId: 33, active: false, }, ] arrayTwo: [ { id: 1, compId: 11, active: true, }, { id: 2, compId: 33, active: false, ...

Hear and register keypress in Angular service

I offer a dialog service Check it out below @Injectable() export class HomeDialogService { public constructor(private readonly dialogService: DialogService, private readonly userAgent: UserAgentService) {} @HostListener('document:keydown.escape ...

Warning: Unhandled promise rejection - Type error encountered when trying to access property

While working on a simple login validation, I encountered an issue when deliberately inputting an incorrect email in the login post method via postman. UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'password' of null at C:&b ...

``How can I easily navigate to the top of the page when changing routes in React Router DOM v6?

What is the best way to scroll to the top when a route changes in react router dom v6? In the past, I used a solution from this StackOverflow post to make my page automatically scroll to the top every time a route changed with react-router-dom v5. However ...

Angular 12 - Encountering an issue with undefined properties when trying to access 'values'

Currently in the process of upgrading Angular Version from 8 to 12. Successfully made the upgrade from 8 to 11 without any issues. However, upon updating Angular to version 12, encountered an error stating "loadComponent TypeError: Cannot read propert ...

Nesting objects within arrays using Typescript Generics

Hello, I am currently attempting to assign the correct type to an object with nested values. Here is a link to the code in the sandbox: https://codesandbox.io/s/0tftsf interface Product { name: string, id: number productList?:ProductItem[] } interf ...

What is preventing me from running my alert script in JavaScript?

Need some assistance here. I have a simple question. I am trying to create an alert function using JavaScript, but it is not working. <script type="text/javascript"> $(".delete").click(function(){ alert("Are you sure?&q ...

Activate the initial tab in JQuery UI accordion upon initialization

Hello, I have implemented a simple sidenav menu on my website. It consists of parent items and child items structured according to the h3 > div format as suggested by JQuery's documentation. My challenge now is to automatically open the "active" t ...