When an anchor tag is used to wrap a column in Bootstrap 4, the justify content feature is automatically removed

When I wrap columns in an anchor tag, the justify-content-center class stops working. I even tried wrapping a separate div inside the column and then put that div in an anchor tag, but still no luck with the justify-content-center class that worked fine before without the anchor tag.

You can observe this issue in the rightmost column: https://i.sstatic.net/OPicH.jpg

HTLM

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
        integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="HomePage.css">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
        integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
        integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
        crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
        integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
        crossorigin="anonymous"></script>
</head>;

...

CSS:

@import url('https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap');
body{
   margin: 0;
   padding: 0s;
}

...

Answer №1

Your original code didn't produce the desired result because of the way you structured the row containing your card. The use of justify-content-around centered the content, while setting the column to col-lg-11 made it 91.67% wide relative to the parent (the row). Due to this, the column in the other cards appeared centered as their width was less than that of the row. However, when you wrapped the column inside an anchor tag, the anchor tag became the element centered by justify-content-around, which without additional styling was the same width as the row. This behavior is due to children of a flex container being automatically set to flex: 0 1 auto, leading to a scenario where the anchor tag would shrink to fit the full width of the row but lacked centering.

To resolve this issue and center the column content, you can place the anchor tag within the column or style the anchor tag with classes such as

col-lg-11 main-card-content shadow
while adjusting the existing column to just col. Another approach is to center the column within the anchor tag itself using mx-auto like so:
<div class="col-lg-11 main-card-content shadow mx-auto">
.

If your revised requirement involves making the entire card act as a link, simply wrap the content in an anchor tag and customize the styling accordingly, including text, hover effects, and linking functionality.

I've also updated the styling for the row in the cards section by switching from absolute positioning to utilizing negative margins to partially cover the carousel. Additionally, I tweaked the styling for the sign-in card hover effect.

To enhance the presentation of your code and illustrate its functionalities clearly, consider using the Stack Overflow snippet feature rather than directly copying and pasting code into the question.

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

When adjusting the window size with the <ion-split-pane>, both the menu and router outlet disappear

When I have two ion menus and one main content (router outlet) and resize the page or switch to mobile view, the page appears blank as if the content is missing. Here is the code: <ion-app> <ion-split-pane> <ion-menu side="start" me ...

JavaScript functions smoothly on Google Chrome but is restricted on Internet Explorer

Experimenting with the code found on this website to conduct some testing. The javascript functions smoothly in Google Chrome and Firefox, but encounters issues in IE. Interestingly, when I run the html file in IE locally, it does work, but a warning pops ...

Take the attention away from the canvas

Is there a way to shift focus away from the canvas and onto input fields in my HTML code? Right now, the canvas is holding onto focus even when I'm clicking on text inputs. This prevents me from typing anything into them. Ideally, I'd like for t ...

HTML5 elements expand to fit the dimensions of the window

While creating an HTML5 page, I observed that div elements without specified widths within sections like "header" and "footer" only occupy the width of the window. For instance: <header> <div id="header-background" style="background: #ddd"> ...

Unable to generate file with Compass

In my attempts to compile a project using compass, I have experimented with both the gui app and the command line. However, I consistently encounter the same error message in both cases: "Nothing to compile. If you're trying to start a new project, yo ...

Steps to access a Windows folder after clicking on a link within an HTML page using Asp.net

I attempted to use the following code : <a href="file:///C:\Programs\sort.mw">Link 1</a> <a href="file:///C:\Videos\lecture.mp4">Link 2</a> Unfortunately, this code does not work in Google Chrome or Firefox bro ...

The jQuery Show Hide feature is experiencing issues specifically on Internet Explorer

Everything looks good in Firefox and Chrome, but unfortunately it's malfunctioning in IE. Does anyone have a suggestion for hiding select Dropdown options? I attempted using CSS with display: none but it didn't work. $j("#id option[value=&apos ...

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 ...

Contrasting the impact of opening your HTML files from the desktop versus running a development local server for your files

As I delve into web design, I've noticed a trend on YouTube where creators utilize virtual servers to upload and preview their code. This got me thinking - what advantage does using a local server offer compared to simply opening the HTML file in my b ...

Struggling to confirm the validity of a number using React and Bootstrap

Seeking assistance with validating an HTML-Input field in React to only allow numbers. Here is my current attempt: How can I configure the Input field to accept only numerical values? phone: { elementLabel: 'Phone Number', elementType: ...

Is Popper.js malfunctioning when bootstrap CSS is included?

Encountered a rather peculiar issue where Popper.js and Tooltip.js refuse to function properly when Bootstrap CSS is being utilized. Here is the code snippet used for testing: <script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></sc ...

Clearing the content div and making it reappear using javascript

I am currently utilizing jQuery's CustomBox modal feature. While it is functioning properly, I am seeking a way to hide the div behind the modal (excluding the background image) when the modal is activated. I have successfully achieved this, but I am ...

Looking to trigger a PHP page by clicking on a div?

Is there a way to trigger a PHP page call when a user clicks on a <DIV> with AJAX? Additionally, can the text of the DIV be changed to display "LOADING....." simultaneously? I lack knowledge about AJAX. Could you please provide me with more details ...

Can you explain how to utilize theme values in CSS within Mui?

Working on my React app with mui themes, I have the following in index.js: let theme = createTheme({ palette: { primary: { main: "#00aaa0", contrastText: '#fcf4d9', }, secondary: { main: "#D55B3E&quo ...

If the image is not found, deactivate the anchor or hyperlink

I am encountering an issue where I have an image tag within an anchor element setup as shown below: <a href='$image'><img alt='No Image' src='$image'></a> When the image is not available, I can still intera ...

Beautifully collapsing inline-blocks using only CSS

My header features three inline-blocks within a container that is text-aligned center. The left block floats to the left, and the right block floats to the right, creating a visually appealing effect where the middle block's text remains centered on s ...

The search bar extends beyond the dropdown in a boostrap collapse scenario

Currently, I'm facing two issues that I need assistance with: On smaller screens, the search bar drops out of the navbar collapse inexplicably, and I'm struggling to identify the cause. The width of the search bar seems to be overriden by A ...

What about a sliding element feature?

Is there a popular slider component that many startups are using, or are these types of sliders typically built from scratch? It seems like they are everywhere on startup websites. I would appreciate it if someone could point me in the right direction with ...

What causes the parent and grandparent elements to shift when adjusting the margin of a header tag?

I'm facing an issue with the h1 tag where changing its margin-top property also affects the parent and grandparent elements. Can someone shed light on why this is happening and provide a solution? If you observe, setting the h1 margin to 0 auto creat ...

What is the best way to ensure the image is centered on smaller screens for responsive design?

Greetings from a budding web developer seeking guidance... I've been grappling with positioning the image of a dog inside an iPhone frame at the center when the screen size is reduced (small to medium sizes) to enhance its appearance. Despite my effo ...