What is the best way to implement a clickable grid row using CSS?

My grid layout consists of 1 row and 4 columns, with the row occupying 85% of the width. I want the entire row to change color when hovered over and be clickable to access another page.

Currently, the row changes colors when hovered over and is clickable, but the link remains active even outside the 85% width. This means that clicking anywhere to the left or right of the row triggers the link. I only want the link to be active when clicked directly on the row itself.

/* CSS CODE */
.ListWrapper {
    display:grid;
    grid-template-columns:1.5fr 1.8fr 1.5fr 1fr;
    grid-template-rows:1fr;
    grid-template-areas: "ListTitleTxt email phone groups";
    background-color:#EDF5FC;
    cursor:pointer;
    margin:auto;
    width:85% }

.ListWrapper:hover { background-color:#1b9bff; color:white; }

.BlackLink:link { text-decoration:none; color:black; }

/* HTML CODE */
<a class='BlackLink' href='#'>
<div class='ListWrapper'>
    <div class='ListTitleTxt'>name</div>
    <div class='email'>email</div>
    <div class='phone'>phone</div>
    <div class='groups'>groups</div></div>
</div></a>

Answer №1

This issue was resolved by introducing an additional div before the a tag, setting its width to 85%, and adjusting the ListWrapper width to 100%.

Check out this example on JSFiddle

.ListLink { width:80%; margin:auto; }
.ListLink:hover { background-color:#1b9bff; color:white; }

.ListWrapper {
    display:grid;
    grid-template-columns:1.5fr 1.8fr 1.5fr 1fr;
    grid-template-rows:1fr;
    grid-template-areas: "ListTitleTxt email phone groups";
    background-color:#EDF5FC;
    cursor:pointer;
    margin:auto;
    width:100% }

.ListWrapper:hover { background-color:#1b9bff; color:white; }
.BlackLink:link { text-decoration:none; color:black; }

<div class='ListLink'>
<a href='#' class='BlackLink'>
<div class='ListWrapper'>
    <div class='ListTitleTxt'>name</div>
    <div class='email'>email</div>
    <div class='phone'>phone</div>
    <div class='groups'>groups</div>
</div></a>
</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

Having trouble getting the image to show up in Django from the static directory

In the code snippet below, the image is referenced: Found inside the HTML and CSS files: <button type="submit" class="task-item-button"> <img src="{% static 'x.svg' %}" alt="Close icon"> </b ...

Adjust Side Navigation Bar based on window size alteration

I am currently working on implementing a side navigation bar for a website. At the moment, I am utilizing a <nav> element and populating it with <li> items to establish my sidebar. My code snippet is as follows (note: in-line styling is tempor ...

Encasing distinct HTML text with a custom color palette

How can I create a specific color scheme for my HTML table's Status parameter, where the values can be SUCCESS, FAILURE, or IN PROGRESS? I'm utilizing Angular 4 (HTML and TypeScript) for this task. Any tips on how to achieve this? ...

I have a task of verifying nine numbers that are similar in all digits

Can someone guide me on generating a pattern in PHP to ensure that these repetitive numbers do not occur in my text input? 000000000 111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 999999999 ...

Trigger the ng-enter event without invoking any functions

This is a snippet from a todo-list code. The first line features an input box with its value accessible via newTodo. This input box is utilized for entering new tasks in the todo-list. <input class="todoField" id="newTodoField" type="text" ng-model=" ...

Is it possible to create a special case for the beforeunload function?

Is there a way to exclude a specific URL or form button from the beforeunload event in JavaScript? I want to exempt them, not as error handling exceptions but to customize how they interact with this event. Here is the relevant JavaScript code: if(loggedi ...

Struggling to send form data to the database

I've been working on sending form data to a database but for some reason, the data doesn't seem to be showing up when I check the database. Can anyone help me figure out what I'm doing wrong? I followed a tutorial on YouTube pretty closely, ...

What are the reasons why Bootstrap icons are not functioning properly in ReactJS?

I am facing an issue with bootstrap icons not working in ReactJS. Click here to view my buttons This is the code for my post items: import React from 'react'; const PostListItem = () => { return ( <li className="app-list ...

Is it possible to insert an image into a text box? If yes, what is the process for doing

Is there a way to create a text area where users can upload images with the click of a button, similar to how Orkut allows for image insertion? I want the user to be able to select an image to be uploaded and have it automatically added to the text area ...

Steer clear of moving elements around in d-flex or similar layouts

I am looking to arrange elements in a linear manner with equal spacing between them. While I can achieve this using Bootstrap 5 flex, the spacing changes when the text length of a button is altered. https://i.sstatic.net/kVc8l.png For example, the element ...

Adjusting the settings on my lightbox

Recently, I created a basic lightbox with the following code snippet: Here is the jQuery code: var $overlay =$('<div class="overlay"></div>'); $('body').append($overlay); $('img').click(function(){ $overlay.sho ...

Create dynamic animations using AngularJS to transition between different states within an ng-repeat loop

Here's a simplified explanation of my current dilemma: I have an array containing a list of items that are being displayed in an Angular view using ng-repeat, like... <li ng-repeat="item in items"> <div class="bar" ng-style="{'width ...

Inject $scope into ng-click to access its properties and methods efficiently

While I know this question has been asked before, my situation is a bit unique. <div ng-repeat="hello in hello track by $index"> <div ng-click="data($index)"> {{data}} </div> </div> $scope.data = function($index) { $scope.sweet ...

How can I line up elements in different divs when the width is adjusting based on the window size?

Trying to align a search input and a result element in separate containers when the window size changes. Looking for a solution without using Javascript. One window size: https://i.sstatic.net/LiQtY.png A smaller window: https://i.sstatic.net/dgj4I.png C ...

The text from the textarea in the form is not directly saved in mongoose, but it can be accessed and logged in the server-side code as req

<form> <input1> ... ... <textarea name="yourbio" rows="3" value="<%= user.bio %>"></textarea> <submit....> <form> Utilizing $set: {req.body} to make updates to the user data. All fields can be successfully updated ...

Discover the steps for incorporating the substring method into JavaScript to manipulate input strings

Is there a way to extract the specified portion of text from an input string using HTML and Javascript? <!DOCTYPE html> <html> <body> <input type="text" value="exampleString"></input> <button onclick=& ...

Displaying PHP errors in input fields

I have noticed that this particular code is functioning correctly. However, I am wondering why I receive an error when I remove the foreach loop ($rows as $row). Is there a method to display the data without utilizing it? <?php require("coneccion.php ...

Styling Tables Dynamically With HTML, CSS, and JavaScript Based on Data

Although I've already searched for solutions, nothing seems to be working, so I'm reaching out again. My issue involves an HTML table: <table class="table1"> <tr> <th>Rank</th> <th>Na ...

Unlimited webpage scrolling downward

Recently, I was given a project to enhance a webpage and encountered an unusual issue. When the screen resolution drops below 900px (such as on small laptops and tablets) and you reach the bottom of the page, you can continue scrolling endlessly after seei ...

issue with visibility of Angular Component

After following a straightforward YouTube tutorial for beginners on Angular, I encountered an issue. The tutorial covers how to use components, and even though I understand the concept well, the component simply does not appear no matter what I try. Here i ...