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

Utilizing Jquery to Add Elements and Adjust Element Height

Encountering an unusual issue where the height of a div is not updating when content is appended to it using JQuery. To demonstrate the problem, I have created a simple JSFiddle: http://jsfiddle.net/hf66v/5/ Here is the initial HTML structure: <div i ...

I am attempting to secure a webpage with a password using JavaScript

I've been working on adding password protection to my webpage at , with the goal of allowing users to enter the password once per session. However, I've encountered an issue: if a user cancels out of the initial prompt or enters the wrong passwor ...

Can a PHP script be executed through an Ajax event?

Is it feasible to execute the script of a PHP file when an AJAX event is triggered? Consider this scenario: on the AJAX error, could we send the data to the error.php file, record the error, notify the admin via email, and perform any other desired action ...

Building the logic context using NodeJS, SocketIO, and Express for development

Exploring the world of Express and SocketIO has been quite an eye-opener for me. It's surprising how most examples you come across simply involve transmitting a "Hello" directly from app.js. However, reality is far more complex than that. I've hi ...

Identifying Master Page Controls Post-Rendering

Within my asp.net projects, I have noticed a discrepancy in the control id on the master page's Contentplaceholder1. On my local server, the id appears as "ctl00_Contentplaceholder1_control" after rendering. However, when the application is deployed t ...

Overlap of columns within a nested flexbox arrangement

While working with React and Styled Components, I encountered a problem of elements overlapping each other: https://i.stack.imgur.com/RuCYu.png There are a few instances of overlap, including: The padding below the <ul> element is colliding with ...

Google Chrome does not support inlined sources when it comes to source maps

Greetings to all who venture across the vast expanse of the internet! I am currently delving into the realm of typescript-code and transcending it into javascript. With the utilization of both --inlineSourceMap and --inlineSources flags, I have observed t ...

What is the best way to define a function in React hooks - using a function statement or

When working with a react hook and needing to define a function inside it, which approach is preferable? useEffect(() => { //... function handler() {} //... }, []); or should I use the newer const declaration instead? useEffect(() => { ...

Tips for breaking out of the foundation row and aligning with the right edge of the viewport

I have a CodePen example showcasing the Zurb Foundation grid. I am looking for a way to make a div extend to the right edge of the viewport while keeping the left edge in line with the grid as the viewport is resized. <div class="row"> <div cla ...

Generating a chart using solely the existing data components (values)

I have the following arrays: const elements = ['12345', '12346', '12347', '12348', '12349', '12350']; const fruits = ['Apple', 'Ball']; I want to create a Map using array ele ...

Vuex computed property not updating when listening to getter

Does anyone know why my computed properties, which essentially just call a store getter with an ID, are not being re-computed when the store changes? The relevant computed property is 'isInCart' for a product: isInCart() { var isInCart = th ...

Sending data from TextBoxFor to controller with @Ajax.ActionLink in MVC

I’ve gone through numerous questions dealing with the same issue, yet none of them seem to solve my problem (or I’m completely missing the point). As the title suggests, I am attempting to transfer the value from a TextBoxFor to my controller using an ...

Cypress testing with Vue: a guide to mocking API calls using actions in Vue

Could someone help me test an action involving an API call? This is the action in my Vuex store: The file containing actions in my store is 'ex.js', and it includes exActions.js export const exActions = { getExFromApi({ commit, rootGetters ...

Creating boxes with equal heights in HTML and CSS

I have created this menu using a combination of html and css. The layout consists of 3 boxes, each with different content. My goal is to ensure that all boxes are the same height within the design. However, due to specific responsive requirements, I cannot ...

Constructing Browserify with dependencies containing require statements within a try-catch block

When attempting to integrate timbre.js (npm version) with Browserify, I encountered an issue where require statements for optional dependencies were enclosed in a try statement (check the source here). This resulted in a browserify build error displaying: ...

Whenever a user tries to retrieve a page using ajax and then proceeds to submit the form associated with that page, they encounter

In my addQuestions.php file, I have four options available - single, multiple, matrix, and true false type questions with values 1-4 assigned to each respectively. To dynamically load the appropriate question type based on user selection, I am using AJAX w ...

Leveraging the power of "react-bootstrap" through the npm package manager

I have a project in mind that involves using npm. Specifically, I want to incorporate react-bootstrap into it. To kick things off, I already have a package.json file with the necessary dependencies. { "name": "simple-webapp", " ...

Struggling to make PayPal Cordova Plugin function properly in both production and sandbox modes

While using the cordova paypal plugin and switching to sandbox mode, I encountered an error. The plugin can be found at https://github.com/paypal/PayPal-Cordova-Plugin https://i.stack.imgur.com/lD2EH.png Running the plugin in PayPalEnvironmentNoNetwork m ...

What seems to be the issue with my code for Javascript Math functions?

Welcome to the number game slider! If you roll above 50, you will get double the amount bet. Use the slider to choose your desired betting amount. Issue 1: After a win, the score does not update correctly. Instead of showing increments of 5, it displays s ...

Add navigation dots to the slider in order to align them with the specified div element

Visit this JSFiddle link for the code <html> <link href="./style.css" rel="stylesheet" type="text/css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script&g ...