Tips for creating a clickable full image within a href tag

Having an issue with making images clickable like links. The link is only staying in the middle instead of covering the full image. Any help would be appreciated.

<div>
<ul class="principaisCategorias">
    <li class="itemCategoria">
        <div class="imagesItemCategoria">
            <a data-bind="ccLink:{route: '/category/ar-condicionado-portatil'}">
                <img src="/file/general/imageItemCategoria.jpg" />
            </a>
        </div>
    </li>
 </ul>
</div>

CSS:

div{
    display: inline;
    font-weight: bold;
    text-align: center;
    ul{
        padding: 0;
        margin: 0;
        &.principaisCategorias{
            width: 102%;
            height: 450px;
            display: flex;
            justify-content: flex-start;
            flex-wrap: wrap;
            .itemCategoria{
                list-style-type: none;
                margin-top: 2px;
                margin-left: 2%;
                margin-bottom: 2px;
                margin-right: 2%;
                height: 140px;
                width: 45%;
                background-color: mediumturquoise;
                .imagesItemCategoria {
                    width: 100%;
                    height: 100%;
                    position: relative;
                    display: inline-block;
                    img, a{
                        display: block;
                        width: 100%;
                        height: 100%;
                        max-height:100%; 
                        max-width:100%;
                    }
                    a{
                        display: inline-block;
                    }
                }
            }
        }
    }
}

Answer №1

Initially, I encountered a problem where none of the inner styles were being applied when running the code. It turns out that the CSS was nested like SASS or SCSS, which caused issues. Once I refactored it to regular CSS syntax, everything started working fine.

Regarding the behavior of the a link, there was an issue with the lack of an href attribute on the element, making it behave more like a <span> tag. Additionally, some unnecessary styles were present. The following modification fixed the behavior:

.imagesItemCategoria a {
    display: block;
    cursor: pointer;
}

For the full code and a functional demo, refer to the snippet below:

.wrapper {
    display: inline;
    font-weight: bold;
    text-align: center;
}
ul.principaisCategorias{
    width: 102%;
    height: 450px;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    padding: 0;
    margin: 0;
}
.itemCategoria{
    list-style-type: none;
    margin-top: 2px;
    margin-left: 2%;
    margin-bottom: 2px;
    margin-right: 2%;
    height: 140px;
    width: 45%;
    background-color: mediumturquoise;
}
.imagesItemCategoria {
    width: 100%;
    height: 100%;
    position: relative;
    display: inline-block;
}
.imagesItemCategoria a {
    display: block;
    cursor: pointer;
}
.imagesItemCategoria img {
  width: 100%;
  height: auto;
  display: block;
}
<div class="wrapper">
<ul class="principaisCategorias">
    <li class="itemCategoria">
        <div class="imagesItemCategoria">
            <a data-bind="ccLink:{route: '/category/ar-condicionado-portatil'}">
                <img src="https://picsum.photos/300" />
            </a>
        </div>
    </li>
 </ul>
</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

The header is not displaying the background image as intended

I'm currently following Colt Steele's course, but I've run into an issue with my background image not showing up. Despite trying different methods like writing inline styles and inserting the background in HTML directly, nothing seems to wor ...

Convert SQL data into an HTML table using ASP

I have a database with an unknown number of rows containing columns for id and text. In my code, I am converting this data into a list of objects named news with parameters id and text. HTML <div class="middleDiv" id="mid" runat="server"> </div& ...

Issues with Bootstrap column rendering in IE11's Flex layout

I need assistance with the code below: .hero{ background:lightgrey; padding: 50px 0px; } <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E26 ...

Styling Radio Buttons and Links in Horizontal Layout Using Bootstrap

Encountering an issue in Bootstrap while attempting to incorporate custom radio buttons and a hyperlink in the same row. It seems that either the hyperlink functions OR the data-toggle feature for radio buttons works, but not both simultaneously, especiall ...

Navigating to and Revealing a Division by Clicking

Check out this code snippet: <a onclick="$('a[href=\'#tab-customtab\']').trigger('click');">Enquire Now</a> <div id="tab-customtab"></div> This piece of code triggers the opening of the #ta ...

Hide the button with jQuery Ajax if the variable is deemed acceptable upon submission

I need to figure out how to hide the submit button if the email entered is the same as the one in the database from action.php. Can anyone help me with integrating this functionality into my existing code? <form onsubmit="return submitdata();"> ...

React: Issue with CSS heights in grid-container not updating when state changes

In a container div, I have three elements: headerContainer, diagramContainer, labelContainer. The container has a fixed height and I want all elements to fill it. The diagramContainer should adjust its height dynamically based on the labelContainer's ...

Guide to ensuring a jQuery modal box appears above other page elements

As I work on a jQuery popup modal box, I am faced with the issue of it pushing all other content aside when called. The toggleSlide() function is being used and works fine, but the layout problem remains. Attempts to rectify this by using position: relati ...

problem specifically occurring on tablets with fixed positioning

Have you checked out the site I'm referring to here? An unusual issue seems to be occurring specifically on tablets. We implemented the scroll to fixed jQuery plugin to fix the position of the sidebar after scrolling, which works perfectly on all de ...

I have managed to update the Immutable and Primitive Data-Types in JS. Now, the question arises - are these truly Primitives or are the concepts in

In JavaScript, there are 4 primitive data types that store values directly: String, Number, Boolean, and Symbol. I am excluding undefined and null from this list as they are special data types with unique characteristics. One key feature of primitives is ...

Exploring the Potential of Boostrap 4 SCSS as a Mixin Toolbox

I discovered a helpful guide on using bootstrap at , but since v4 removed LESS, I'm struggling to achieve the same results with SCSS. It's quite useful and I can't seem to figure out the correct way to import it. ...

Using CSS pseudo elements before and after on an input range

I am looking to create a slider that dynamically displays boundaries. After searching online, I came across some code that I modified to suit my needs. This code uses only HTML and CSS and looks great in Chrome, but not so good in Firefox (I also tried it ...

Retrieve the status of a CSS animation using JavaScript and display it within an element or log it to the console for future modifications

I am experimenting with CSS3 animations to create a marquee effect and want to trigger a function when the animation changes from running to paused or initial state. HTML: <div class='animationBackground'><p id="marqueeText">Scrolli ...

How to extract text from an HTML element using Selenium

In the following HTML snippet, I need to extract the text of elements 1 and 2 individually. <div class="sc-492bf320-0 sc-7d450bff-9 crIwBV juiSXn"> <div data-change-key="homeScore.display" class="sc-18688171-0 sc-7d450bf ...

Verifying the timestamp of file submission in a form

My goal is to create an HTML form that allows users to send a file to my server, while also recording the exact time they initiated the file transfer. However, I'm facing an issue where only the time the file is received is being logged, rather than w ...

Incorporating AJAX functionality into anchor interactions while preserving href links for search engine optimization benefits

Is it possible to create a link/button that triggers an AJAX/jQuery function to load new content, while still providing a link to the same content on a separate page? I am particularly concerned about SEO and how search engine crawlers will index my sitem ...

Is it common for the `col` class in Bootstrap 4 Grid System to have no padding?

This is my first time using Bootstrap version 4. Currently, I have a footer that utilizes the new flex col classes. It looks great on desktop, but on mobile, the columns are stacked so closely together that there is no vertical margin or padding. Is this ...

Every time I click the highlight button, my navbar link inexplicably shrinks

I am struggling with adjusting the list style in my bootstrap navbar. Whenever I click on the highlight button, it squeezes my navbar and I'm not sure how to fix it. <div id="links"> <a href="index.html">Home& ...

Ways to identify when the scroll bar reaches the end of the modal dialog box

I have been working on a modal that should display an alert when the scrollbar reaches the bottom. Despite my efforts to research a solution, I am struggling to detect this specific event within the modal. The desired outcome is for an alert to pop up once ...

Encountered a deployment issue when trying to deploy an HTML application on Heroku due

After uploading an html application on GitHub, I encountered an error while attempting to deploy it on Heroku: No default language could be detected for this app. HINT: This happens when Heroku is unable to automatically determine the buildpack to use f ...