apply a visible border to the item that is clicked or selected by utilizing css and vue

I have a list of items that I want to display as image cards with an active blue border when clicked. Only one item can be selected at a time.

Below is the code snippet:

Template Code

<div class="container">
  <div
    v-for="(obj, index) in layoutDatas"
    :key="index"
    class="item"
    @click="getLayoutDetails(obj)"
  >
    <cmp-image-viewer
      ref="index"
      :style="'width: 250px; height:150px;'"
    />
    <div class="column">
      <div class="text1">
        {{ obj.layoutId }}
      </div>
      <div class="row">
        <div class="col-xs-9 text2 noBorder">
          {{ obj.layoutTitle }}
        </div>
      </div>
    </div>
  </div>
</div>

CSS Style Code

 .container {
  display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    margin: auto;
  height: 450px;
    border-radius: 3px;
    margin-top: 50px;
    padding: 10px;
}
.item {
  width: 250px;
  height: 220px;
  border: 0.3px solid #eaeaea;
    align-self: center;
    padding: 5px;
    border-radius: 3px;
    margin: 10px 10px;
    transition: all .15s ease-in-out;
}
.item:hover {
  border: 0.3px solid #0071c5;
  transform: scale(1.1);
}
.itemClick {
  border: 1px solid #0071c5;
}
.text1 {
  font-weight: bold;
  padding-left: 10px;
  font-size: 16px;
}
.text2 {
  color: #959595;
}

To implement the active border on the selected or clicked item using CSS and Vue, how should I proceed?

Answer №1

If my understanding is correct, you are looking to have only one card with a blue border when clicked. To achieve this, you can keep track of the clicked card by assigning it to a data property. For example, within the @getLayoutDetails function, you could include logic to set this.selectedObject = obj, where obj is the object being passed in.

Subsequently, you can utilize this data property to apply a CSS class to the selected object. This implementation would resemble the following:

<div
    v-for="(obj, index) in layoutDatas"
    :key="index"
    class="item"
    :class="obj.id === selected.id ? 'active' : 'not-active'"
    @click="getLayoutDetails(obj)"
  >

Lastly, define the styles for the active class in your CSS file:

.active {
  border: 1px solid #0071c5;
}

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

Manipulating viewport settings to simulate smaller screens on a desktop device

I am working with a parent container that contains Bootstrap div.row elements holding div.col-... child elements. I am using jQuery to adjust the width and height of the container dynamically to replicate mobile device sizes for users to preview different ...

What is the necessity of utilizing getStaticPaths() alongside getStaticProps()?

When working with dynamic routes, such as [id].js, the static pages generated using npm run build will result in an [id].html page. Any route containing /something will display "Hello World". However, when we dynamically generate content on the page by ut ...

Creating dynamic divs on button click for my project is something that I must do, and I will

When the user clicks on the Add button, a new div should be added as shown in the image above. Implementing this functionality using Bootstrap is crucial because the divs must rearrange correctly based on different resolutions such as 1920x900, 1280x600, ...

Navigate to the end in Ionic Vue

In my development of a chat app using Ionic Vue, one challenge I face is ensuring that the latest messages are always visible by automatically scrolling to the bottom. While vue-chat-scroll works well for web applications, it does not seem to be compatibl ...

Centering numerous elements on all screen sizes and devices

Is there a way to align elements in the center of the screen both vertically and horizontally without specifying width and height for mobile and desktop views? How can I make it responsive so that it appears centered on all devices? .parent-container{ ...

Secure Authentication using Tokens in Laravel 5.5

Right from the start, Laravel's auth configuration sets up a token-based authentication system for users: 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' =& ...

How can I change the displayed value of a 'select' element programmatically in Internet Explorer?

My interactive graphic has a drop-down menu implemented with a <select> element. Everything functions correctly, except when using Internet Explorer. The issue arises when attempting to programmatically change the selected value of the <select> ...

Event handler for the MouseLeave event is not successfully triggering when dealing with anchor

When viewing a link to a Codepen, the issue is most noticeable in Chrome: https://codepen.io/pkroupoderov/pen/jdRowv Sometimes, the mouseLeave event fails to trigger when a user quickly moves the cursor over multiple images, resulting in some images reta ...

When resizing, headers within Bootstrap text fail to adjust accordingly

I have created a card-like component in my HTML with text inside. My issue is that when I resize the page, the card shrinks but the text overflows. Currently, I am using Bootstrap 5 and its h4 class like this: <div class="card bg-white"> ...

Include a clickable hyperlink within a column in JQGrid that, when clicked, triggers a specific Jquery function

I am dealing with a JQgrid that only has 5 columns. Below is the code I have attempted: jQuery("#grdAnn6InvstDetails").jqGrid({ url: RootUrl + 'FDIAS/Ann6InvDtlsGridData', datatype: 'json', mtype: 'POST&ap ...

Tips for displaying dynamic content in VueJS?

I'm currently working on an app that allows users to choose which type of vuetify element they want to display on the page. There are 4 options available for selection. My goal is to render the corresponding vuetify component when a user clicks on the ...

Is it possible to create a CSS1 sprite animation triggered by a mouse hover

Is there a way to create sequential image loading on mouse hover for a CSS1 Sprite, similar to an animation? Please refrain from suggesting CSS3 solutions as not all browsers fully support CSS3 animations. Thank you. ...

Encountered a JQuery error in the application: trying to call the 'open' method on dialog before initialization is complete

I am having trouble integrating a dialog box into my application and encountering the error mentioned above. Here is the jQuery code I'm using: $( "#dialog" ).dialog({ autoOpen: false, width: 450, modal: true, ...

Transmit information from Ajax to CodeIgniter's controller

Right now, I am facing an issue with sending data from my JavaScript to a function in the controller using AJAX. Despite my best efforts, AJAX is not sending the data. Below, you can find the code that I have been working on: The JavaScript Function var ...

leveraging the default browser behavior for the href and target attributes within an <a> element in Angular 2

How can the behavior of a simple anchor tag in Angular 2 be implemented without being overridden by the routing module? <a href="some url" target="_whatever"> It is crucial to prevent the routing module from highjacking the URL using the base href. ...

Error: The PHP contact form is displaying field names instead of the actual values being entered

I am completely new to this and would appreciate some guidance. I have set up a contact form on a website, but I seem to be encountering some errors. Here is the email content I receive from the contact form: <p>$usersname has contacted you from you ...

Maintain original image file name when downloading

I have successfully created a download link containing a base 64 encoded image. The only issue is that I need to retain the original file name, which is dynamic and cannot be hardcoded. downloadImage: function(){ var image_url = document.getEleme ...

Unable to retrieve class attributes within a function

I have recently started delving into the world of node.js, and I am facing some challenges with a middleware that I created. The purpose of this middleware is to act as an Error handler. However, I am encountering difficulties in accessing properties that ...

Creating an X pattern on an HTML5 canvas and detecting intersections with a perimeter

I am currently developing a maze game using HTML 5. Below is the function I have implemented to draw an "X" on the canvas (the player will guide the X through the maze using touchpad). dim = 8; function rect(x,y,xdim){ ctx.beginPath(); ctx.moveT ...

Opting for <button> over <a>

I am currently working with ReactJS in conjunction with a Bootstrap Nav Bar. Bootstrap utilizes an <a> tag for the navigation buttons. I am aiming to have the buttons scroll down to a different component on the page without resorting to using an href ...