Generating a Grid List featuring Direct Links

Struggling to create a grid layout with images, titles, and descriptions that are all clickable links? The challenge is in making the entire list item act as a link, rather than just specific elements within it. Take a look at the demo below, where clicking on empty space within a list item may yield no action.

Check out the Fiddle Demo here

HTML Code Snippet:

<ul class="grid-list">
    <li>
            <a class="grid-list-content" href="#">
                <img class="grid-list-icon" src="https://www.wds-solutions.com/images/color_swatches.png" />
                <p class="grid-list-title">Title</p>
                <p class="grid-list-description"></p>
            </a>
    </li>
     <li>
        <div class="grid-list-content">
            <a href="#">
                <img class="grid-list-icon" src="https://www.wds-solutions.com/images/color_swatches.png" />
                <p class="grid-list-title">Title</p>
                <p class="grid-list-description">Some Description. Bla bla bla bla bla bla bla bla bla bla bla bla</p>
            </a>
        </div>
    </li>
</ul>

CSS Styling:

ul.grid-list li {
    display: inline-block;
    border: solid 1px black;
    width: 200px;
    vertical-align: top;
    padding: 5px;
    border-radius: 3px;
    overflow: hidden;
}
ul.grid-list li:hover {
    background-color: grey;
}
.grid-list-content {
    text-decoration: none;
    color: inherit;
}
.grid-list-icon {
    float: left;
    margin-right: 5px;
}
.grid-list-title {
    font-weight: bold;
    font-size: 14px;
    margin: 0px;
}
.grid-list-description {
    font-size: 10px;
    margin: 0px;
}

Answer №1

One approach is to utilize the li element to contain the a and then style the a as if it were the li by setting them both as block elements with display: block.

You can view a working example on this JSFiddle link.

It's worth noting that your current HTML structure is not valid. It's best practice to avoid placing block-level elements inside inline elements, such as having a p within an a tag.

I hope this explanation proves helpful :)

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

I must arrange each item in a column vertically, regardless of whether they could align horizontally

As the title suggests, I am looking for a way to stack one element under another, similar to a chat application. Currently, when the message is long, it displays correctly, but if the text fits next to each other, it aligns in that manner. I require a solu ...

Using JavaScript, create a set of buttons within a div element and implement

$(document).ready(function() { $('#b1').click(function() { $('#uch').toggle("slow"); }); $('#b2').click(function() { $('#uch2').toggle("slow"); }) }) Although I'm not a program ...

PHP processing and converting to a string output

I have a PHP page (content.php) that includes plain HTML and content accessed via PHP variables <html> <head> </head> <body> <h1><?php echo $title; ?></h1> </body> </html> ...

Nested jQuery UI Selectable causing propagation problems

My issue lies in the nested jQuery UI selectable functionality. When I click on Item 1, it is selected as expected. However, when clicking on Item 111 or 1111, it selects all the way up to Item 2. What I require is for only the element that is clicked on t ...

The issue I am facing is that my Contact Form is sending empty emails whenever someone visits the

I seem to be encountering an issue with my contact form. Every time I visit the page, it sends mysterious black emails. Moreover, whenever someone fills out the form and clicks send, another email is dispatched. I have been trying all day to figure out how ...

How can you properly line up three <div> elements?

My challenge involves arranging three <div> containers, positioned from left to right on the screen with equal spacing. However, I am seeking a method to align one container to the far left, another in the middle, and the third to the far right. Is ...

JQuery and CSS Techniques for Changing the Size of a Div

I'm currently experimenting with JQuery and CSS to create a user-friendly navigation experience for users as they browse through a grid of variously-sized images. Essentially, my goal is to have the images expand when hovered over (which is functioni ...

Tips for receiving input on one HTML page and displaying it on the next page using Angular 2

Just started learning Angular 2 and trying to work with data binding. I'm having trouble printing the value from one page to another through components. The code below prints the value on the same page instead of passing it to another page. Can anyone ...

What are some ways to bypass a closed Google form that is no longer accepting responses? I need to find a way to submit my form even after the deadline

Is there a way to trick a closed Google form that says it is "no longer accepting responses"? I'm looking to submit a form past the deadline. Is there a method to access and submit a form that has already been closed? The code for the closed form appe ...

What are some ways to ensure text stands out against a gradient backdrop?

Is there a way to ensure that text adjusts automatically to a background transition from one color to another using only CSS? I've tried using "mix-blend-mode:difference" from a forum, but it had no effect on the text. .container{ color: white; ...

Creating an automated HTML tag for a form input

https://i.sstatic.net/ZBDk2.png Is there a plugin to create form inputs like the one shown above? How can I add this feature to my own website? I would like for every user input to automatically add the < br > tag. ...

What is the best way to layer four images in a 2x2 grid over another image using CSS as the background

I am attempting to place 4 images of the same size on a 5th image defined as the background. Currently, it looks like this: It works perfectly when the height is fixed, but in my case, the height may vary causing this issue: This problem isn't surp ...

Transform the contents of a div tag into a function by removing the entire div tag

My goal is to find a clever solution for removing the contents between specific HTML classes using PHP. For example, I want to erase all the HTML within the "sometestclass" class. The function below is somewhat functional but not perfect. It eliminates so ...

Tips for avoiding the transmission of className and style attributes to React components

Hey there! I'm working on a custom button component that needs to accept all ButtonHTMLAttributes except for className and style to avoid any conflicts with styling. I'm using TypeScript with React, but I've run into some issues trying to ac ...

Using a link in React to open a subroute instead of navigating to a new page

item.link = "www.google.com" <a href={item.link} target="_blank" rel="noopener noreferrer">{item.about}</a> The code snippet above creates a link to an external website using the provided URL. ...

Tips for showing RTSP stream within Electron

I am facing a challenge with a video stream that is accessible using the UDP protocol through either rtp://ipadd:port or udp://@:port. Unfortunately, I have no control over the server hosting the stream, which means I cannot modify it to transmit the strea ...

I aim to break down a function into several functions using jQuery and AJAX for better organization and efficiency

I am working with a JavaScript file that includes an Ajax function to fetch data from a JSON file on a server. The goal is to interpret this data into a table, but I would like to break down the process into separate functions for generating links, dates, ...

Node.js: My webpage needs an image to complete its look

During my training with Node and TypeScript, I attempted to create a simple server with multiple request/response options. However, I encountered a problem that I am struggling to solve without using Express (at least for now). I have an HTML file that re ...

Customize background images for the ::after and ::before pseudo elements that span the full height of the webpage

I've successfully centered a <div class="page"> element on my page, and now I'm attempting to add two background images that run along the left and right edges of this container. So far, I've utilized the .page::before and .page::afte ...

What is the best way to create a border for the active class nav-item in Bootstrap 4?

I am facing an issue with changing styles in the nav-item. I have created a separate style sheet and added the necessary code to make the changes. Surprisingly, the changes are reflecting well in Internet Explorer but not in Firefox. Can anyone guide me on ...