transitioning a <div> between dimensions with a snap effect

It seems like it should be straightforward to achieve with bootstrap/grid, but I seem to be overlooking something. I have a container div with two column divs within it. Once the screen size hits a certain point, I want the container to transition directly from the expanded size (780px in this case) to the compact size (just enough for the viewport div, approximately 620px). While I can get the internal divs to behave correctly, the container div sort of "slides" from the expanded size to the compact size. I'd prefer it to switch abruptly between one width or the other.

Here's my HTML:

<div id="mc-container" class="d-flex flex-row flex-wrap">
    <div id="mc-header">Title Bar</div>
    <div id='mc-viewport'>Viewport</div>
    <div id="mc-column">
        <div id='mc-list' class="d-flex flex-row flex-wrap">
            <div *ngFor="let l of list">
                <div id="mc-list-item">{{l}}</div>
            </div>
        </div>
        <div id="mc-controls" class="d-flex flex-row flex-wrap">
            <div class="control-placeholder" style="width: 150px">Input Box</div>
            <div class="control-placeholder" style="width: 75px">Fan</div>
            <div class="control-placeholder" style="width: 75px">Net New</div>
            <div class="control-placeholder" style="width: 150px">Download DXF</div>
        </div>
    </div>
</div>

And here's my CSS:

#mc-container {
  background-color: #ccccff;
  margin: 5px;
  max-width: 780px;
  width: 90%;
}

#mc-column {
  background-color: #dddddd;
  min-width: 150px;
  width: auto;
  height: auto;
  margin: 10px;
  margin-right: 0px;
  max-width: 600px;

  flex: 1 1 0;
}

#mc-viewport {
  background-color: lightsalmon;
  width: 600px;
  height: 400px;
  margin: 10px;
  margin-right: 0px;
}

#mc-list {
  background-color: lightcyan;
  width: 100%;
}
#mc-list-item {
  min-width: 150px;
  outline: whitesmoke solid 1px;

}

#mc-controls {
  background-color: lightgreen;
  width: 100%;
  margin-top: 10px;
  margin-bottom: auto;
}

.control-placeholder {
  outline: whitesmoke solid 1px;
  font-size: small;
}

#mc-header {
  background-color: whitesmoke;
  width: 100%;
}

Answer №1

My recommendation would be to opt for width as a percentage rather than using pixels

Answer №2

When using the col-xl class, it tends to snap at a larger size.

You can also experiment with @media only screen and (max-width: 620px) or by adjusting the min-width property.

I may have this mixed up but something like

@media only screen and (min-width: 620px) {
.someclass{
    display:none;
}
}

@media only screen and (max-width: 620px) {
.someclass{
    display:block;

} }

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

In Bootstrap 4, the text exceeds the boundaries of the card

I am looking to overlay text on an image using the bootstrap card-img-overlay feature. Here is the code I have written: <div class="h-100"> <div class="card h-100"> <img class="card-img" src="../imgs/header.jpg" alt="Card image"& ...

Add a Variety of Data Entries to a Table

I am currently attempting to add multiple pieces of data (from a date form) into a table using Jquery and MomentJS. However, the output does not appear as desired. Below is my code: $(".btnNext").on('click', function(e) { var Day = 1; ...

Oops! Looks like we have encountered an issue with reading the property 'checked' of nothing

Whenever I click the checkbox, an image should be displayed. Unfortunately, I encountered an error: Uncaught TypeError: Cannot read property 'checked' of null at (index):185 at dispatch (VM576 jquery.min.js:3) at i (VM5 ...

Including emoticons in text without impacting the 'line-height'

Is there a way to add an emoticon within a paragraph without altering the line-height, regardless of the size of the emoticon? For example: I've tried using position: absolute or vertical-align: text-top, but neither seems to work. p img { hei ...

Trouble with CSS styling in Asp.Net MVC dropdown list

I have encountered an issue while trying to apply a CSS class to an ASP.NET MVC dropdown list. The CSS class works fine for the EditorFor case, but not for the DropDownListFor case. I am wondering what could be missing from my code? Here is the working CS ...

Tips for increasing the number of pixels in the current position of an element?

I need to shift an image to the right by adding pixels to its current left position. The challenge arises when the image, positioned absolutely, goes back to its nearest relative parent (the container) and creates a strange visual effect. Within my flex c ...

The functionality of jQuery .rotate() appears to be malfunctioning

I'm struggling to get this code working properly. My jQuery version is 2.1.0. Here's the code snippet: $("a.shownav img").rotate(180); Any suggestions on how to make it function correctly without relying on a plugin? ...

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 & ...

Commencing CSS Animation Post Full Page Loading

I am looking for a solution using WordPress. In my specific case, I want the CSS Animations to take effect only after the page has completely loaded. For example: click here This is my HTML: <div class="svg-one"> <svg xmlns="ht ...

Rearranging columns in Bootstrap 4 beta across multiple containers

Sorry for any language issues in my English. This shows my regular grid: ------------------------------- | A | B | C | ------------------------------- | D (horizontal menu) | ------------------------------- Is it possible to d ...

Using AngularJS to dynamically swap out {{post.title}} with a different HTML file

I want to update the value of {{post.title}} within my HTML to redirect to another HTML file. <div ng-repeat="post in posts"> <h2> {{post.title}} <a ng-click="editPost(post._id)" class="pull-r ...

Pass an array from a script file in JavaScript to index.js within the Express framework

I've encountered a challenge in sending an array (or JSON object) from script.js to index.js, my express server file. I've explored various solutions such as passing the variable through an HTML file and then to another JavaScript file, utilizing ...

Can you explain the HTML semantic layout for having multiple titles matched with their respective lists?

In my directional segment, I have included details such as the address, phone number, email, and service date/time. I envision it looking like the example below: https://i.sstatic.net/5h4SM.jpg Currently, my code appears as follows: <div class="co ...

Is it possible to change the style of the current page in PHP using the ?page href method?

Currently, I am facing an issue with styling in my code. Specifically, I want to style the page numbers that are currently open or active. For example, if a page is open, I would like its corresponding number to be displayed in a different color or style. ...

Creating a dynamic shift in background color

Is it possible to use jQuery to slowly change the color of diagonal lines in a background styled with CSS, while also adding a fading effect? I have created a fiddle with the necessary CSS to display a static background. You can view it here: http://jsfid ...

Using the background-size cover property in Firefox

While working on a website, I encountered an issue where the background image did not display correctly across different browsers. Specifically, when using the background-size: cover property in Chrome and Safari, the image filled up the entire screen as i ...

D3 Chart: What is the best way to insert images into a node?

Within the jsFiddle demo provided in this query, there is code displayed. I am curious about how I can assign images to each node. var graph = { "nodes":[ {"name":"1","rating":90,"id":2951}, ] } You can access my jsFiddle Demo through this ...

Arranging a variety of sophisticated charts side by side using Bokeh

Is there a way to display two or more Bar charts together in a single html file using Bokeh? I have found examples of laying out figures like triangle, square from bokeh.plotting together on this page: However, I have not been able to find any examples s ...

Insert an HTML element or Angular component dynamically when a specific function is called in an Angular application

Currently, I am working on a component that contains a button connected to a function in the .ts file. My goal is to have this function add an HTML element or make it visible when the button is clicked. Specifically, I would like a dynamic <div> elem ...

Blazor Bootstrap - Issue with Dropdown Remaining Open When Clicking Outside Element

Having trouble implementing the default Bootstrap dropdown behavior in my Blazor Server app. I need the dropdown menu to close when I click anywhere outside of it. I attempted using @onfocusout, but ran into issues. If I click inside a form input and then ...