Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My span it won't stay contained in <a></a> that has a background image

So I saw this on another site and looked inside their css, I have a problem where I have a

<span></span> Inside <a></a> tags

and they put

.slikaPosla span
{
display: block;
position: absolute;
bottom: 0;
{

on the span and for them text is at the bottom of the image

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the full code:

<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">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
    <title>Document</title>
    <style>
        .slikaPosla {
            width: 300px;
            height: 200px;
            border-radius: 10px;
            background-size: cover;
            margin-left: 10px;
            text-decoration: none;
        }

        .slikaPosla span {
            display: block;
            position: absolute;
            bottom: 0;
            color: black;
            font-size: 25px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row mt-3">
            <a href="#" class="col-6 col-lg-3 slikaPosla" style="background-image: url('/ELEKTRICAR.jpg');">
                <span class="">Elektricar</span>
            </a>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
        crossorigin="anonymous"></script>
</body>
</html>

My SITE Theirs

I tried switching Positions to any that pops up when I write, but nothing works

P.S: I am using Bootstrap, the reason for all the classes that are not in
Style

>Solution :

Your .slikaPosla span is absolutely positioned, so its position is relative to closest non-static element. But your .slikaPosla is statically positioned (default position value).

Add position: relative; into .slikaPosla rules. In their site it works most likely because somewhere else this rule is set.

So in the end your CSS should be:

        .slikaPosla {
            position: relative;
            width: 300px;
            height: 200px;
            border-radius: 10px;
            background-size: cover;
            margin-left: 10px;
            text-decoration: none;
        }

        .slikaPosla span {
            display: block;
            position: absolute;
            bottom: 0;
            color: black;
            font-size: 25px;
            font-weight: bold;
        }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading