1

I have been trying to make a footer for a website I made to help teach me about HTML and CSS. The problem is that I cannot make the background of the footer big enough to make it fit in the footer text.

And here is the code.

<!DOCTYPE html>
<html>
<head>
<title>code</title>
   
</head>
<STYLE>


a{
    color: rgb(28, 152, 253);
}

[![enter image description here][1]][1]

header {
    top: -10px;
    background-color: rgb(25, 25, 50);
    
}


body {
    background-image: linear-gradient(to top, #111111 0%, #000000 100%);

    text-align: center;
    color: rgb(255, 255, 255);
    margin: 0;
    padding: 0;
    font-size: 200%;
    background-color: rgb(255, 255, 255);
}


html, body {
    margin: 0;
    top: 100px;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    margin-left: 0;
    margin-right: 0;

}

footer {
    line-height: 0;
    text-align: center;

    background-color: rgb(255, 173, 20);

}


</STYLE>
<header>

    </header>
<body>
    <h1>H1 element</h1>

</body>
<footer>
    <H6>Example footer</H6>
    <h6><a>stackoverflow.com</a></h6>
</footer>
</html>

I believe my problem has to do with the CSS footer code itself rather than the surrounding elements, but I am not 100% sure about it.

  • 1
    No need to line-height:0 in the .footer, if you wish to give height line to the h6 in the footer, give it a class/id and tweak it in your css, no important here but dont forget to give your footer at least a minimum height and a max width and padding and also set its position so it would be steaky down there – BlackSheep Jan 28 '21 at 04:24

3 Answers3

1

you can remove 'line-height' in footer, try it.

1

Do a line-height: auto in the footer

and that's it!

Unnat
  • 398
  • 2
  • 12
1

Approach 1 : Using Flex Property

You can use display:flex property in footer and arrange child elements as per your need.

footer { display: flex; }

and no need to use of line-height.

Approach 2 : without Flex Property

footer { float: left; background: rgb(255, 173, 20); width: 100%; }

footer h6 { text-align: center; width: 100%; float: left; margin: 10px 0; }

Ambuj Khanna
  • 1,131
  • 3
  • 12
  • 32