Clickable background, text remains non-clickable

How can I make the entire field clickable instead of just the text "Google" that opens the website?

.section {
    display: flex;
    justify-content: center;
}
.alignment {
    width: 500px;
}
#back-style {
    text-align: center;
    color: white;
    background-color: #e6e6e6;
    line-height: 2.5;
}
<section class="section">
    <div class="alignment">
        <div id="back-style">
            <a href=https://www.google.com">Google</a>
        </div>
    </div>
</section>

Answer №1

One suggestion is to make #back-style the link element. By applying display: block and removing color: white, it will appear identical to your original code.

.section {
    display: flex;
    justify-content: center;
}
.alignment {
    width: 500px;
}
#back-style {
    display: block;
    text-align: center;
    background-color: #e6e6e6;
    line-height: 2.5;
}
<section class="section">
    <div class="alignment">
        <a id="back-style" href="https://www.google.com">
            Google
        </a>
    </div>
</section>

Answer №2

The <a> tag is essential for creating clickable elements on a webpage. To ensure that the entire section is clickable, it is important to place the <a> tag outside of the surrounding div:

<section class="section">
    <div class="alignment">
        <a href="https://www.example.com">
            <div id="stylish-design">Example</div>
        </a>
    </div>
</section>

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

Selenium, launch a fresh browser window

I am currently working on a project using Selenium and Java. My goal is to click on either a link or a button (as shown in the HTML snippet below), then confirm that the number of tabs or windows has increased. Finally, I want to close only the newly opene ...

Utilizing Bootstrap 5 Grid to blend fixed and dynamic width elements within a single row

I am currently working on developing a grid system for my Blazor application that features small fixed-size columns with one large column. Instead of dividing the grid into 12 columns using col-xs-*, I have opted to set custom widths without using the col ...

Issue with Bootstrap 4 navbar z-index not functioning as expected

Hello, I am struggling to place my navbar on top of an image using bootstrap 4. I have set the CSS properties for both elements, but it doesn't seem to be working. Here is the code I am using: <header> <nav class="navbar navbar-toggl ...

Alignment of text in a stationary element's location

I'm working on implementing a feature for an online shop where new items are added to the cart, and I want to display the number of new items added. However, I am facing a challenge in centering the text that displays the number, especially when the n ...

The frozen first column in a CSS table does not have consistent height with the rest of the row

Having trouble with freezing the first column of a table and aligning the height of the first cell with the rest of the row? Check out the issue in the image below: https://i.sstatic.net/v5xHU.png For a live example, you can also visit this jsfiddle link ...

Splitting with Regex - One Time Operation

Here is some of my Jquery code along with Regex: $("[class^=ipsum-img],[class^=ipsum-img-]").each(function(){ var x = $(this).attr("class"); console.log(x.length); if (x.length>8) { var m = x.split(/(\d+)[^-]*$/g); cons ...

Prevent images from overlapping in Bootstrap 4 carousel

I am working on a project using bootstrap 4. In my carousel design, I want to add another image layer at the bottom of the main image, but the code I have written is not displaying the new image in the correct position. Do you have any suggestions on how t ...

Customize the appearance of each TreeItem in JavaFX using CSS to assign unique

I am looking for a way to color individual Tree Items in a treeView based on specific conditions. I found a promising answer, but unfortunately, I am struggling to implement it. You can check out the answer here. My main obstacle is understanding how to u ...

The XmlUtil.serialize(root) function is converting empty tags into self-closing tags

Check out this cool code snippet featuring an empty div tag (<div></div>): import groovy.xml.DOMBuilder import groovy.xml.XmlUtil def HTML_STRING = ''' <html> <div></div> <div>Some text</d ...

How can I create dynamic tabs using Tailwind CSS?

I am looking to create an animated tab using React and Tailwind CSS. Here is the code I have so far: import React from 'react' import clsx from 'clsx' export const Modal = () => { const [theme, setTheme] = React.useState<' ...

Creating an HTML form that resembles StackOverflow's form

I am having an issue with the behavior of my form when inserting multiple tags. I want it to function like the one on this particular website where a scroll bar appears and a new line is created. Is there a way to keep everything on the same row? Check ou ...

Obtaining text from HTML code

Currently, I am faced with a challenge. My task involves extracting HTML text and saving it as an Anchor object. Here is an example: <html> <head> <title>{dynamihead/}</title> </head> <body> {repeatinghtml} <p>{r ...

The scripts do not allow the image to be resized

Struggling to resize an image while implementing a hover effect with css and javascript. The code I have so far is: HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equ ...

Beginner in CSS wanting to set background image for input field

I am working on incorporating icons into my project. The image I have contains an array of 16x16 icons at this URL: "http://www.freepbx.org/v3/browser/trunk/assets/css/jquery/vader/images/ui-icons_cd0a0a_256x240.png?rev=1" Does anyone know how I can selec ...

What is the best way to style a Rails form field using CSS/Bootstrap?

I've been trying various methods and experimenting but I can't seem to figure out how to format my Rails view to display a form with Bootstrap or CSS. The issue might be related to the Bootstrap classes or the CSS. My goal is to create a two-col ...

Ensure that only one checkbox is checked at a time and that unchecking one does not remove the

https://i.sstatic.net/EEC2U.png I am facing an issue with two checkboxes in my code. When I click on the first checkbox in the featured playlist section, another popular genre checkbox should be unchecked. However, only the value changes and the checked m ...

A division of text is colliding with a division that holds a list with no particular

Hello everyone, I am new to HTML/CSS and I am facing an issue that I believe can be easily resolved. Currently, my code has four sections, with the last three displaying as expected in a consecutive manner. However, the second section is overlapping on t ...

Working with ASP.NET to toggle the visibility of several div elements

Is the current method I'm using the best practice, or could it be more resource-efficient? On my website, I show and hide divs based on user actions and permissions. Currently, I declare my divs as follows: <div id="NormalView" runat="server" vis ...

Cartify: Your Ultimate Bootstrap Shopping Companion

My goal is to create a shopping cart that looks similar to this: https://i.sstatic.net/McOdf.png However, I am struggling to achieve the design where "Local Delivery" is positioned on the left and the circle with a plus sign inside of it is on the right ...

Getting the ID name from a select tag with JavaScript - A quick guide!

Can you help me retrieve the id name using JavaScript when a selection is made in a select tag? I have tried running this code, but it only alerts undefined. For instance, if I select bbb in the select tag, I should be alerted with 2 Any suggestions on ...