Broaden card module and position it centrally after concealing other modules in Vuetify

After creating a button that hides all other components on the page except one and expands the remaining one, I am having trouble aligning the expanded component in the center after clicking the button.

If you want to see the current behavior, check out this codepen link.

new Vue({
  el: '#app',
  data: () => ({
    lorem: `Lorem ipsum dolor sit amet, mel at clita quando. Te sit oratio vituperatoribus, nam ad ipsum posidonium mediocritatem, explicari dissentiunt cu mea. Repudiare disputationi vim in, mollis iriure nec cu, alienum argumentum ius ad. Pri eu justo aeque torquatos.`,
    show1: true,
    show2: true,
    show3: true,
    show4: true,
    show5: true,
    expand1:true
    
  }),
  methods: {
    hideothers() {
        this.show2=!this.show2,
        this.show3=!this.show3,
        this.show4=!this.show4,
        this.show5=!this.show5,
        this.expand1=!this.expand1
                 }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <v-app id="inspire">
    <v-container fluid grid-list-sm>
      <v-layout row wrap>
<!-- top starts here-->
        <v-flex d-flex xs12 sm4 child-flex>
          <v-card color="orange lighten-2" tile flat v-show="show1"> 
            <v-card-text>Card 1</v-card-text>
             <v-btn flat  @click="hideothers()">Expand</v-btn>
             <v-card-text>
                  <v-expand-transition>
                    <div v-show="expand1">This is a short paragraph</div>
                  </v-expand-transition>
                  <v-expand-transition>
                    <div v-show="!expand1">
                      <p>A looooong</p>
                      <p>paragraph</p>
                    </div>
                  </v-expand-transition>
                </v-card-text>
          </v-card>
        </v-flex>
        
         <v-flex d-flex xs12 sm4 child-flex>
           <v-fade-transition>
             
            
          <v-card color="orange lighten-2" tile flat v-show="show2">
            <v-card-text>
            <v-layout row wrap>
              <v-flex sm6>
                 Card1
              </v-flex>
              <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
            </v-layout>
            </v-card-text>
          </v-card>
             </v-fade-transition>
        </v-flex>

        <v-flex d-flex xs12 sm4>
          <v-card color="red lighten-2" dark tile flat v-show="show3">
            <v-card-text>{{ lorem.slice(0, 100) }}</v-card-text>
          </v-card>
        </v-flex>
  <!-- TOP part ends here-->     
        
         <v-flex d-flex xs12 sm4 child-flex>
          <v-card color="purple lighten-1" tile flat v-show="show4">
            <v-card-text>{{lorem}}</v-card-text>
          </v-card>
        </v-flex>
        <v-flex xs12 sm4 child-flex v-show="show5">
          <v-card color="green lighten-2" tile flat>
            <v-card-text>{{lorem}}</v-card-text>
          </v-card>
        </v-flex>
       
      </v-layout>
    </v-container>
  </v-app>
</div>

Answer №1

Essentially modify the line below

<v-flex xs12 sm4 child-flex v-show="show2" :class="{ 'd-flex': show2 }">

Apply the d-flex class only when it is visible and also hide this div when the parameter is false.

Additionally, add justify-content: center CSS to the wrapper of all the 5 divs.

Check out the updated codepen

new Vue({
  el: '#app',
  data: () => ({
    lorem: `Lorem ipsum dolor sit amet, mel at clita quando. Te sit oratio vituperatoribus, nam ad ipsum posidonium mediocritatem, explicari dissentiunt cu mea. Repudiare disputationi vim in, mollis iriure nec cu, alienum argumentum ius ad. Pri eu justo aeque torquatos.`,
    show1: true,
    show2: true,
    show3: true,
    show4: true,
    show5: true,
    expand1: true

  }),
  methods: {
    hideothers() {
      this.show2 = !this.show2,
        this.show3 = !this.show3,
        this.show4 = !this.show4,
        this.show5 = !this.show5,
        this.expand1 = !this.expand1
    }
  }
})
.custom-class {
  justify-content: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f595a4a5b4649566f1e011a011d1d">[email protected]</a>/dist/vuetify.min.css>

<div id="app">
  <v-app id="inspire">
    <v-container fluid grid-list-sm>
      <v-layout row wrap :class="{ 'custom-class': !show2 }">
<!-- top starts here-->
        <v-flex d-flex xs12 sm4 child-flex v-show="show1">
          <v-card color="orange lighten-2" tile flat>
            <v-card-text>Card 1</v-card-text>
             <v-btn flat  @click="hideothers()">Expand</v-btn>
             <v-card-text>
                  <v-expand-transition>
                    <div v-show="expand1">This is a short paragraph</div>
                  </v-expand-transition>
                  <v-expand-transition>
                    <div v-show="!expand1">
                      <p>A looooong</p>
                      <p>paragraph</p>
                    </div>
                  </v-expand-transition>
                </v-card-text>
          </v-card>
        </v-flex>

         <v-flex xs12 sm4 child-flex v-show="show2" :class="{ 'd-flex': show2 }">
           <v-fade-transition>


          <v-card color="orange lighten-2" tile flat v-show="show2">
            <v-card-text>
            <v-layout row wrap>
              <v-flex sm6>
                 Card1
              </v-flex>
              <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
            </v-layout>
            </v-card-text>
          </v-card>
             </v-fade-transition>
        </v-flex>

        <v-flex xs12 sm4 v-show="show3" :class="{ 'd-flex': show3 }">
          <v-card color="red lighten-2" dark tile flat v-show="show3">
            <v-card-text>{{ lorem.slice(0, 100) }}</v-card-text>
          </v-card>
        </v-flex>
  <!-- TOP part ends here-->

         <v-flex xs12 sm4 child-flex v-show="show4" :class="{ 'd-flex': show4 }">
          <v-card color="purple lighten-1" tile flat v-show="show4">
            <v-card-text>{{lorem}}</v-card-text>
          </v-card>
        </v-flex>
        <v-flex xs12 sm4 child-flex v-show="show5" :class="{ 'd-flex': show2 }">
          <v-card color="green lighten-2" tile flat>
            <v-card-text>{{lorem}}</v-card-text>
          </v-card>
        </v-flex>

      </v-layout>
    </v-container>
  </v-app>
</div>

Answer №2

To determine the necessary widths for md4 and md12 based on whether it is expanded or not, you can use this code snippet:

<v-flex d-flex xs12 :sm4="expand1" :sm12="!expand1" child-flex>

For a demonstration, check out this pen: see the pen

Answer №3

Give this a try:

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <v-app id="inspire">
    <v-container fluid grid-list-sm>
      <v-layout row wrap :justify-center="!expand1">
<!-- begin top section-->
        <v-flex d-flex xs12 sm4 child-flex>
          <v-card color="orange lighten-2" tile flat v-show="show1"> 
            <v-card-text>Card 1</v-card-text>
             <v-btn flat  @click="hideothers()">Expand</v-btn>
             <v-card-text>
                  <v-expand-transition>
                    <div v-show="expand1">This is a short paragraph</div>
                  </v-expand-transition>
                  <v-expand-transition>
                    <div v-show="!expand1">
                      <p>A looooong</p>
                      <p>paragraph</p>
                    </div>
                  </v-expand-transition>
                </v-card-text>
          </v-card>
        </v-flex>

         <v-flex d-flex xs12 sm4 child-flex v-if="show2">
           <v-fade-transition>


          <v-card color="orange lighten-2" tile flat>
            <v-card-text>
            <v-layout row wrap>
              <v-flex sm6>
                 Card1
              </v-flex>
              <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
               <v-flex sm6>
                 Card1
              </v-flex>
            </v-layout>
            </v-card-text>
          </v-card>
             </v-fade-transition>
        </v-flex>

        <v-flex d-flex xs12 sm4 v-if="show3">
          <v-card color="red lighten-2" dark tile flat>
            <v-card-text>{{ lorem.slice(0, 100) }}</v-card-text>
          </v-card>
        </v-flex>
  <!-- End of top section-->     

         <v-flex d-flex xs12 sm4 child-flex v-if="show4">
          <v-card color="purple lighten-1" tile flat>
            <v-card-text>{{lorem}}</v-card-text>
          </v-card>
        </v-flex>
        <v-flex xs12 sm4 child-flex v-show="show5">
          <v-card color="green lighten-2" tile flat>
            <v-card-text>{{lorem}}</v-card-text>
          </v-card>
        </v-flex>


      </v-layout>
    </v-container>
  </v-app>
</div>

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

Resource loading unsuccessful: server returned a 401 status code for React webpage

( ) I'm currently working on a website dedicated to searching for GitHub users as part of my React course. However, I seem to be facing an issue with the website not fetching the response properly, possibly due to an Axios error. When searching for ...

Creating a new object through manipulation of existing objects

In my attempt to transform an existing object into a new object structure, I am facing some challenges. Here is the current data set: const jsonStructure = { "a11/a22/animations": "snimations", "a11/a22/colours": "sl/colours", "a11/a22/fonts" ...

Converting a class component into a functional component

I am looking to convert this class component code into a functional component. Can you please provide guidance on the steps required for converting this class component to a functional one? I prefer using functional components and would like to see this ...

Styling Borders with CSS in Electron's WebView Component

Is there a way to add border radius to Electron's <webview> tag? If not, is there a list of supported styles available? HTML <body> <aside> </aside> <main> <webview id="view" src="h ...

Executing an automated process of adding items to the shopping cart using Python without the need to have a

Does anyone know of a way to automate the add-to-cart process using Python without the need for an open browser window? I've experimented with modules like mechanize, but they lack the ability to directly interact with web elements. Currently, I&apo ...

The Vue container is having trouble accessing the URL from the app, but it is able to access it from the container

I currently have three distinct containers set up as follows: 1. UI Container running a Vue SPA 2. Backend Container with a Spring Boot application 3. MYSql DB container Here is the configuration from my docker-compose file: version: '3' servi ...

JavaScript's method of organizing website loading sequences

I am currently facing a challenge with my web page that features a chart displaying a large amount of data using a 3rd party flash component. The issue arises when a significant portion of the data is lazy loaded and added to the chart via AJAX post initi ...

Receiving Console Error When Attempting to Implement ngClass Directive Within Another Directive

I have encountered a console error while trying to utilize ngClass within my directive. The specific error message reads: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! To demonstrate this issue, here is a simplified version of the ...

Is there a way to make the scrollbar-react component extend to full page width?

I'm currently in the process of developing a to-do application that consists of a sidebar and a page for listing tasks. My goal is to have the page fill the entire screen without specifying a fixed height. Would it be feasible to achieve this using s ...

Conceal anchor links using jQuery by targeting their title attribute

Looking at the html below <li class="static"> <a title="blog" class="static menu-item" href="http://google.com">Blog</a> </li> <li class="static"> <a title="profile" class="static menu-item" href="http://profile.com"> ...

Avoid using a for loop to alternate between pushing items into an array

I have a code snippet that currently functions like this: let result = [] const number for (let i = 0; i < number; i++) { result.push(f(i)) result.push(g(i)) } return ( <div> {result} </div> ) The functions f(i) and g(i) each ...

Mysterious spectral division titled as a <div id="checkdv_1">

label appearing upon loading, the mysterious div lingering below my app div. I am not familiar with it and encountering it for the first time in my Vue project. I have checked extensions and attempted to search online to understand it, but no luck so far. ...

The usage of $http.post in combination with TypeScript accessors

Currently, I am developing an AngularJS application (v1.3.15) using TypeScript 1.5 in Visual Studio 2013. I have encountered a challenge related to TypeScript object properties and JSON serialization while utilizing $http.post(). Although I consider myself ...

Persist user input even after reloading the page

In order to enhance the user experience, I would like to implement a feature where the data entered by the user is preserved even if they refresh, reload, or close the page. This includes retaining the selections made in the select elements. Additionally, ...

Waiting for the result of an AngularJS promise

When I click a button in my AngularJS app, the following code is executed: if (!$scope.isChecked) { $scope.getExistingName($scope.userName).then(function (data) { $scope.userName = data; }); } // Additional processing code foll ...

Setting a timeout from the frontend in the AWS apigClient can be accomplished by adjusting the

I am currently integrating the Amazon API Client Gateway into my project and I have successfully set up all the necessary requests and responses. Now, I am trying to implement a timeout feature by adding the following code snippet: apigClient.me ...

What is the best way to apply a background image to a DIV element using CSS

The main aim is to change the background image of a DIV using AJAX. $.getJSON("https://itunes.apple.com/search?term=" + searchTerm + '&limit=1' + '&callback=?', function(data) { $.each(data.results, fun ...

Trouble encountered when attempting to POST with AJAX in Codeigniter

Wondering if I might have missed something here. I've been searching for a while now and can't seem to find a solution. In my CodeIgniter project, I'm attempting to use AJAX to make a POST request in an onClick event. This event should add ...

Steps for configuring jQuery hide(), adding Class, and remove Class for flawless execution

My HTML Code is structured as follows : ... @foreach($hotel as $key=>$value) ... <div class="iteration"> <input type='hidden' value='<?php echo $value['HCode'].'#' ...

What is the problem with locating elements in Selenium with Java?

I've been encountering difficulties in finding elements on a webpage structured like this: <tr id="filter100" style="...." idx=0 <td> <div onclick=... style=... <table dir = "fil"> <tbody> ...