Having text aligned within a div element (which is also a link) can decrease its effectiveness in being clicked

I've run into an issue that seems simple to fix, but I haven't been able to find a solution yet.

What I'm trying to achieve is to make the divs (with classes left-side, middle, and right-side) clickable links with the text positioned in the center. Currently, my code works fine when the text isn't vertically centered, but as soon as I center it, the hover effect still works but clicking on the div stops functioning.

Here's what my DIV looks like:

p {
    font-family: 'Nunito', sans-serif;
    font-size: 22px;
    color: #fff;
    text-decoration: none;
}
.center {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}
.left-side {
    width: 394px;
    text-align: center;
    background-color: #f2830c;
    color: #fff;
    box-shadow: 10px 10px 20px 0px hsla(0, 0%, 0%, 0.1)
}
.left-side:hover{
    background-color: #ff921d;
}
.left-side:hover p {
    color:#2a2a2a;
}
a.div-link {
    display: block;
    height: 100%;
    width: 100%;
    text-decoration: none; 
    z-index: 1;
}
<div class="left-side">
    <section>
        <p class="center">SALON</p>    
        <a href="http://google.com" class="div-link"></a> 
    </section>
</div>

Answer №1

If you want to make all the content within a <div> tag clickable, you can nest the <div> inside an <a> tag. This way, you can apply any style you desire to the <div>:

<a href="http://google.com">
      <div class="left-side" style="height: 100px;">
          <section>
              <p class="center">SALON</p>
          </section>
    </div>
</a>

Answer №2

h1 {
    font-family: 'Montserrat', sans-serif;
    font-size: 28px;
    color: #333;
    text-decoration: underline;
}
.container {
    display: grid;
    justify-content: center;
    align-items: center;
    height: 100%;
}
.right-side {
    width: 450px;
    text-align: center;
    background-color: #27ae60;
    color: #fff;
    box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.1);
}
.right-side:hover{
    background-color: #2ecc71;
}
.right-side:hover h1 {
    color:#e67e22;
}
a.link-box {
    display: block;
    height: 100%;
    width: 100%;
    text-decoration: none; 
    z-index: 1;
}
<div class="right-side">
  <section>
    <a href="http://example.com" class="link-box">
      <h1 class="container">WELCOME</h1>
  </section>
  </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

Retrieve list of friend names along with their corresponding friend IDs from MongoDB

Creating a MEAN app for the first time and successfully inserting users into MongoDB. Each user entry includes: { "name":"My Name", "country":"Italy", "friends":"5922c66b4e708e27a02b7937" } First query: How can I manually add multiple friends (separate t ...

Displaying Images with Bootstrap

/* STYLING THE GLOBAL ELEMENTS */ body { background-color: #a6a6a6; padding-bottom: 40px; color: #5a5a5a; } .navbar-wrapper { position: absolute; top: 0; right: 0; left: 0; z-index: 20; } .navbar-wrapper > .container { padding-right: 1 ...

Steps for inserting an item into a div container

I've been attempting to create a website that randomly selects elements from input fields. Since I don't have a set number of inputs, I wanted to include a button that could generate inputs automatically. However, I am encountering an issue where ...

unable to properly display application.html.erb

I am encountering difficulties in rendering my application.html.erb template as I am receiving the following error message: ActionView::SyntaxErrorInTemplate within ApplicationController#home app/views/layouts/application.HTML.erb:10: syntax error, unexpec ...

Automatic Clicks in the Chrome Console

I've come across a website that requires me to click on multiple elements scattered throughout the page Here is the code for one of the elements: <span class="icon icon-arrow-2"></span> Is there a way to provide me with the console comm ...

The child component's template content fails to display properly within the parent component hosting it

Currently, I am utilizing Vue3 with options api in the code snippet below. Within my parent component, I have embedded a child component as demonstrated. The issue arises during runtime where even though showNotificationsWindowsContainer is set to true, t ...

I've encountered an issue with adjusting certain property values for an SVG component within my React project

I'm experiencing an issue where the pointer property is working, but the fill property isn't having any effect. When I inspect the elements in the browser console, I can manually change the element.style to affect the styling of the SVG component ...

Replacing the yellow autofill background

After much effort, I have finally discovered the ultimate method to remove autofill styling across all browsers: $('input').each(function() { var $this = $(this); $this.after($this.clone()).remove(); }); However, executing t ...

Changing the hover background color and text color of Material UI Button

I recently developed a custom Appbar component using React.js that includes 3 buttons. I'm looking to enhance the user experience by changing the color scheme when users hover over these buttons. Currently, the background color is set to #3c52b2 and t ...

Avoiding overlapping in setTimeOut when using jQuery.hover()

Looking to trigger an effect one second after the page loads, and then every 3 seconds in a loop. When the user hovers over a specific element with the ID #hover, the effect should pause momentarily. It should then resume 2 seconds after the user stops hov ...

Embed a webpage into a PowerPoint presentation

This question may be unconventional, but I am in search of a PowerPoint add-in that allows me to insert webpages for free. I have previously used LiveWeb, however, the browser does not support CSS3 and HTML5, so I need one that does. Can you suggest any a ...

Navigating Liferay Portlet in reverse order

I am facing an issue with right to left alignment in my portlet. It displays correctly when tested on a regular HTML page, but switches to left to right alignment when integrated into a Liferay portlet. Below is the code snippet causing this problem: < ...

Prevent click event listener from activating if the click results in a new tab or window being opened

Occasionally, when using my web app, I need to prevent click event listeners from activating if the click is meant to open a new window or tab. For instance, in my single page application, there are links to other content. While they function well, there i ...

The dropdown menu is extending beyond the edge of the screen

I'm having trouble with my navbar dropdown menu extending off the page to the right. Take a look at the code below: <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-c ...

Overflowing CSS grid issue

I've been working on this for a couple of hours, but I haven't been able to get it right. I want to add labels in a grid layout with a maximum of 3 columns. If the items don't fit, they should wrap to the next row. It would be great if the i ...

Learn how to dynamically update a user's profile picture in the navbar when clicked using Angular

When I have a navbar (see code below) and set *ngIf = "user", I attempt to display the user's avatar in the navbar but only see a placeholder. However, after refreshing the page, the user avatar appears. Therefore, I am curious about how I can refresh ...

The margin-bottom property does not cause the element to shift or re

Need help with creating a 3-line effect using div and before/after selectors. When applying margin-top in the after selector, the line moves down properly. However, when trying to move the line up using margin-bottom in the before selector, it's not w ...

Guide on developing a CSS countdown timer

I recently came across an article discussing the creation of a CSS countdown timer. Intrigued by the concept, I decided to give it a try myself. However, my implementation seems flawed and the live demo link provided in the article is not working. Can some ...

AngularJS allows you to dynamically update a list by adding elements to the end as

I have a specific requirement to showcase a lineup of elements in a single row, granting users the ability to scroll through them. Upon reaching the end of the scroll, a function should be triggered to add more elements to this lineup. I've successfu ...

Please instruct me on how to properly show a comprehensive explanation

Discovering this forum has completely changed my life! Can someone please guide me on where I might have made a mistake? I created a behavior model in the views, set up a URL, but clicking on the title doesn't lead to a detailed description of the eve ...