Expanding Overlay Width in Vuejs and CSS for Small Devices under 500px

How can I adjust the width of the overlay nav specifically for small devices in Vue or CSS? My current width is set to 25% for devices with a width of 1000px or more, but I need a different width of 35% or more for smaller devices to improve text visibility. Are there any solutions for this problem?

new Vue({
  el: '#app',
  data: () => ({
    open: false,
  }),
  methods: {
    changeP () {
      this.arrowP = (this.arrowP === 'arrow-right') ? 'angle-down' : 'arrow-right'
    },
    setProperty (event) {
      this.$store.dispatch('display', event)
    },
    toggleOverlay () {
      this.open = !this.open
    }
  },
  
})

$(function () {
  openNav()
  closeNav()
})
.navbar-icon {
    outline: none;
    border: 0;
    box-shadow: none;
    background: inherit;
  }

  .navbar-icon::before {
    content: '\F0C9';
    font-family: 'FontAwesome', serif;
    font-size: 24px;
  }
  
  /* Other CSS styles here */
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-vue/2.15.0/bootstrap-vue-icons.common.js"></script>
<div id="app" class="container-fluid admin-panel p-0">
    <b-container fluid="lg" id="myNav" class="overlay p-0"
                 :style="{ width: open ? '25%': '0' }">
      <b-button class="close" @click="toggleOverlay"/>

      <b-container class="overlay-content">
        <b-row class="bottom-border">
          <b-container fluid="sm" class="image-cropper">
            <img :src="pImage" alt="" class="profile-pic">
          </b-container>
          <b-container fluid="sm" class="profile-name">
            <h5>Shah Rukh Khan</h5>
            <b-row class="profile-row">
              <b-button
                class="button new-user"
                v-b-popover.hover.bottom="'User'" />
              <b-button class="button setting"
                        v-b-popover.hover.bottom="'Setting'" />
              <b-button class="button logout"
                        v-b-popover.hover.bottom="'Logout'"  />
            </b-row>
          </b-container>
        </b-row>
        <b-button @click="changeP()"
                  :class="'sub-title product ' + arrowP"
                  v-b-toggle.collapse-product
                  v-text="'Product'"/>
        <b-collapse id="collapse-product" class="dropdown-list">
          <b-button class="button" v-text="'Product List'"/>
          <br>
          <b-button class="button" v-text="'New Product'"/>
          <br>
          <b-button class="button" v-text="'Update Product'"/>
        </b-collapse>
       
      </b-container>
    </b-container>
  </div>

Answer №1

It is recommended not to set the width directly on the element. Instead, consider adding a class dynamically when you want the overlay to be open.

By doing this, you can utilize CSS and media queries to adapt the width based on the screen size.

/* Default */
.overlay {
  height: 100%;
  width: 0;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background: #393F4D;
  ;
  overflow-x: hidden;
  transition: 0.5s;
}

/* Applied when 'open' class is added */
.overlay.open {
  width: 25%;
}

@media screen and (max-width: 992px) {
  .overlay.open {
    width: 35%;
  }
}

@media screen and (max-width: 768px) {
  .overlay.open {
    width: 50%;
  }
}

@media screen and (max-width: 548px) {
  .overlay.open {
    width: 90%;
  }
}

/* Your JavaScript code goes here */
/* Your custom CSS code goes here */
/* Your external libraries and resources go here */

On a side note, if you are using Bootstrap-Vue, you may want to explore b-sidebar to simplify the creation of sidebars.

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

Personalized Carousel using Ng-Bootstrap, showcasing image and description data fields

I have been working on customizing an Angular Bootstrap Carousel and have managed to successfully change the layout. I now have two columns - with the image on the right and text along with custom arrows on the left. My goal is twofold: First, I am lookin ...

Scrolling animations do not support the Translate3d feature

I'm struggling to implement a smooth scroll effect on the header of my website. My approach involves using transform:translate3d for animation, with the goal of keeping the header fixed at the top and moving it out of view as the user scrolls down. I ...

Looking to maintain the value of a toggle button in a specific state depending on certain condition checks

I have a situation where I need to keep a toggle button set to "off" if my collection object is empty. Previously, I was using v-model to update the value of the toggle button. However, now I am attempting to use :value and input events, but I am strugglin ...

Importing a Vue component within a functional component

I've developed a component named SpotifyButton within the components directory, and here's how it looks: <template functional> <b-button pill size="sm" :href="props.spotifyUri" class="spotify-green"> ...

I am struggling to make my button hover effects to function properly despite trying out numerous suggestions to fix it

As a newcomer, this is my first real assignment. I've managed to tackle other challenges successfully, but this one seems a bit more complex and I'm struggling to pinpoint where I'm going wrong. Despite googling various solutions, none of th ...

Restrict the child's height to the remaining space within the parent container

I'm attempting to divide the viewport's height between two divs. In the top div, there is a small div followed by a larger div that should scroll if it doesn't fit within the remaining space of the parent div. Below is the structure of my HT ...

Utilize text wrapping to ensure a fixed maximum height for content display

I am in need of a div that contains text spanning multiple lines, with both a fixed width and a maximum height. Currently, I have applied the CSS property overflow: hidden;. However, my issue arises when the last line of text exceeds the maximum height of ...

Vue.js and the flexibility of component paths

I decided to break up my vuejs application into components, but whenever I make updates to the architecture, it becomes a challenge to adjust the component paths accordingly. To simplify maintenance, I am attempting to store the component path in a setting ...

Exploring alternatives to ref() when not responsive to reassignments in the Composition API

Check out this easy carousel: <template> <div ref="wrapperRef" class="js-carousel container"> <div class="row"> <slot></slot> </div> <div class=&q ...

CSS3 keyframes hover animation for Firefox

I implemented keyframes animation for a div on mouse hover using pure CSS3. The animation runs smoothly on all browsers (Google Chrome, Safari, IE, Opera) except for Firefox! I'm puzzled as to why it doesn't work only in Firefox. The animation ...

What is the best way to dynamically change the color of a Vue component button through a function?

Can anyone provide guidance on how to change the button color of a Vue component using a function while utilizing Bootstrap-vue? The code snippet below demonstrates how a tooltip can be altered through a function, but how can this concept be extended to mo ...

Linking all styles with Angular 2

Is it possible to apply a style when the exact nature of that style is unknown? Consider a scenario where I have a model containing string variables defining styles, as shown below: myStyle1:string="margin-left:10px"; myStyle2:string="margin ...

What is the process for developing multiple screens or views in PhoneGap?

Currently working on a reading app and decided to give phoneGap a shot for the first time. I'm pretty proficient in HTML, CSS, and JS, but not very familiar with xCode. In this app, I plan to have a button on the home screen that redirects users to an ...

Troubleshooting Cascading Style Sheet problem on Samsung Galaxy S5

In developing a Cordova Android application, I designed a CSS specifically for screen resolutions of 1080 x 1920. This CSS is accessed using media queries. @media screen and (max-width: 680px) and (orientation:portrait) //Compatible with Galaxy S5 or @m ...

Searchbox aligned to the right using Bootstrap

Looking to place a searchbox on the right next to another container aligned left: <div> <div class="pull-left"><span>SOME TEXT</span></div> <div class="pull-right"> <div class="row"> ...

Can you employ a right-side offset in Bootstrap 4?

Is it possible to align a button with a textbox using the Bootstrap 4 layout system? https://i.sstatic.net/tN9II.png <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/> <div ...

Strategies for aligning a div element in the middle of the screen

Positioned in the center of the current viewport, above all other elements. Compatible across different browsers without relying on third-party plugins, etc. Can be achieved using CSS or JavaScript UPDATE: I attempted to use Javascript's Sys.UI.Dom ...

Utilize a class within a Framer Motion element to incorporate animations or set initial properties

Is there a way to apply a class using Framer Motion tag in the animate and initial props? Here's an example: <motion.div initial={{ className: 'hidden' }} animate={{ className: 'visible' }} > <div>yo</div> & ...

Tips for setting uniform line-height across an entire project by adding a fixed value to the font size

I need to update line heights for a complete project. The requirement is that all line heights should equal the font size plus 4 pixels. Is there a simple way to do this using SCSS? Adjusting based on percentage would be easy, but the specific value is g ...

Is it possible for me to add a div that consistently hovers above other divs on the page

Beginner in the world of CSS. Currently, I am developing a Safari extension where clicking its toolbar button will display a 'dialog banner' (comprising text and a few buttons) on the web page. This banner, in the form of a div, is dynamically a ...