What is the best way to ensure that a square div is completely clickable using CSS?

Here's a project I'm currently working on: http://jsfiddle.net/hjkryc41/1/

The focus is on creating a responsive grid in CSS within a horizontally scrolling page. The grid consists of square divs arranged from top to bottom and left to right, each containing a link, an image, and a title.

Below is the HTML structure:

<div class="masonry"> 
    <div class="item"><a href="http://arkhana.fr/img/2.png"><img src="http://arkhana.fr/img/2.png" /></a><div class="title">test2</div></div>
    <div class="item"><a href="http://arkhana.fr/img/3.png"><img src="http://arkhana.fr/img/3.png" /></a><div class="title">test3</div></div>
    <div class="item"><a href="http://arkhana.fr/img/4.png"><img src="http://arkhana.fr/img/4.png" /></a><div class="title">test4</div></div>
    <div class="item"><a href="http://arkhana.fr/img/5.png"><img src="http://arkhana.fr/img/5.png" /></a><div class="title">test5</div></div>
    <div class="item"><a href="http://arkhana.fr/img/6.png"><img src="http://arkhana.fr/img/6.png" /></a><div class="title">test6</div></div>
    ...
</div>

And here's the accompanying CSS:

body {
    margin: 0;
    background: #e9e9e9;
    height:100%;
    padding:1em;
}
.masonry {
    position:absolute;
    height:auto;
    top:0px;
    bottom:0px;
    margin: 0;
    padding: 20px;
    -moz-column-gap: 1em;
    -webkit-column-gap: 1em;
    column-gap: 1em;
    -moz-column-width: 220px;
    -webkit-column-width: 220px;
    column-width: 220px;
}
.item {
    width:100%;
    display: block;
    position:relative;
    margin: 0 0 1.5em;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
}
.item img {
    width:100%;
}
.title {
    background-image: linear-gradient(transparent, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.8));
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4em 1em 1em 1em;
    color:white;
    font-family:'open sans';
    font-weight:100;
    font-size:16px;
    line-height:25px;
    text-align:right;
}

I'm trying to achieve full clickability for each square element. However, there seems to be an issue with the title zone not being clickable. Is there a way to make the entire square clickable without adding a secondary link inside the div?

Answer №1

Organize each of your div elements in this manner:

<div class="item">
   <a href="http://uniquewebsite.com/img/1.jpg">
       <img src="http://uniquewebsite.com/img/1.jpg" /><span class="description">example</span>
   </a>
</div>

Now the anchor tag will encompass the .description division as well.

Answer №2

Simple solution: Include pointer-events none in the styles for .heading:

.heading { 
  pointer-events: none;
}

Code Example

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

Two boxes each taking up half of the width, with content placed inside a container

How can I achieve the appearance seen in this image? https://i.sstatic.net/2oZW8.png The layout consists of four columns using regular Bootstrap code. The first two columns should have a white background within a .container, while the other two columns s ...

Transforming images with Imagick

I've been trying to generate thumbnails from PDF uploads using Imagick. I have a script that is supposed to handle this task, but unfortunately, it only uploads the file without creating a thumbnail. I know some of you may find this basic, but PHP is ...

Incorporating jQuery functions in the Angular app's main component file, app

I've been working on an Angular application and recently added the jQuery package with the following code: $ npm install jquery --save Now, I am attempting to transfer data from my HTML web page's .js file to the app.component.ts in Angular. I ...

What is the best way to align every element in a single corner using Flexbox CSS?

My goal is to place a link in each corner (left, top, right, bottom) using Flexbox. I attempted using top: 0 or adjusting the flex-direction to column. .container { position: relative; } .top { display: flex; justify-content: space-b ...

Enhance your viewing experience with the Zoom feature that activates when

I recently noticed on that I am able to zoom/enlarge a photo by clicking on it. Is there a way for me to incorporate this feature without purchasing the entire theme? While I understand the theme is designed for purchase, I only need this specific functi ...

What is the best way to transition an absolute positioned element from right to center?

When hovering over an overlay element, I want the <h3> tag to appear with a transition effect from right to center, similar to the example shown here. Could someone please assist me in achieving this? Thank you in advance. HTML <div class="row m ...

Encountered an issue while attempting to verify email through ajax with the database

After reviewing responses from multiple users here, I am aiming to verify if an email is already in the database. Below is the code snippet I am using: **HTML CODE** <div class="form-group"> <div class="col-sm-12"> ...

Implementing Angular JS to Fill a Drop-down Menu with JSON Data

Here is my HTML code: <body ng-app="mainApp"> <div ng-controller="myController"> <select> <option ng-repeat="person in persons">{{ person.data }}</option> </select> </div> </body> This is my JavaScript ...

determine the height of div element for A4 size paper dimensions

Is there a way to calculate how many A4 papers would fit into a div on my website? I am aware that the size of an A4 paper in pixels varies depending on the screen's DPI. I am exploring methods to determine the user's screen DPI, convert it to A4 ...

Ways to determine whether an element is presently engaged in scrolling

Is there a way to determine if certain actions can be disabled while an element is being scrolled? The scrolling may be triggered by using the mouse wheel or mouse pad, or by calling scrollIntoView(). Can we detect if an element is currently being scroll ...

How can you determine if an SVG element has been resized, such as through a resize event?

Within a <div>, I have an embedded <svg> element. Whenever the parent <div> is resized, the <svg> drawing also resizes perfectly. My query is: Is there a method to receive notification after the resizing of the <svg> elemen ...

Is there a way for me to determine if a user has engaged with a form?

I'm surprised by how difficult it was to find information on this topic through Google. Currently, my struggle lies in wanting my form fields to change color based on validity only after the user has interacted with the form. I don't want invali ...

Developing a transparent "cutout" within a colored container using CSS in React Native (Layout design for a QR code scanner)

I'm currently utilizing react-native-camera for QR scanning, which is functioning properly. However, I want to implement a white screen with opacity above the camera, with a blank square in the middle to indicate where the user should scan the QR code ...

Adjust the header's alignment to seamlessly coincide with the uppermost part of the

I'm encountering this peculiar issue with a website I recently started designing. My aim is to make the header perfectly aligned with the top of the page. However, despite my attempts, there persists a stubborn gap that measures around 20px, defying a ...

Tips for positioning text within an input field above a div element

When a div is placed behind another div, the text in both div elements aligns. .wrapper { box-sizing: border-box; padding: 0; margin: 0; outline: none; padding-right: 20px; } .box { height: 34px; width: 130px; padding: 6px 12px; fon ...

A commonly used method to adjust the width of a table column to accommodate the size of the child element

I have a specific table width of 776 pixels with three columns. The third column has a fixed width of 216 pixels, but the widths of the other two are unknown. I want the second column to adjust its width based on its content, and whatever space is left aft ...

Preventing the ScrollTop Function from Triggering in Jquery Upon Link Click

Hey there! I'm currently facing an issue with jquery scrollTop. Whenever I navigate to the id #linkA and click it again, an unnecessary scroll is added. I'd like to prevent scrolling after clicking the link. Imagine these three paragraphs have a ...

import an external JavaScript file into another JavaScript file

Is there a way to include an external JavaScript file into tinyMCE and access all its functions? For example - I want to integrate jQuery Mobile with tinyMCE and make all its functions available. This problem arose while attempting to incorporate the jQ ...

Tips for Successfully Passing Personal Parameters Using Html.BeginForm

I am looking to pass some additional parameters from my MVC Form to the Controller. Can anyone provide guidance on how to accomplish this? Specifically, I want to pass parameters for StateName and CityName with values from the form so that I can retrieve t ...

Clicking on the FLOT graph will trigger an expansion of the visualization

Currently, I am utilizing the flot library for data plotting functionality. Flot utilizes the height and width properties of a div to create the plotted data, as shown below: <div id="graph" style="width: 300px; height: 300px;"></div> I am in ...