I have created a webpage, screenshot of which is attached below.
Here the Footer is shifted to right. There is a clear gap in left and in right it goes beyond the page hiding the letter ‘t’ and partially hiding ‘h’.
The code I wrote is below,
.FullBody {
background-image: url('BackgroundImage.jpg');
background-size: 100%;
}
.Heading {
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
font-size: xx-large;
align-content: center;
text-align: center;
color: azure;
height: 100px;
}
.Footer {
height: 40px;
background-color: black;
color: white;
align-content: center;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
font-size: medium;
width: 100%;
position: fixed;
bottom: 0px;
}
.FooterLeft {
float: left;
float: right;
}
<!DOCTYPE html>
<html>
<head style="color: antiquewhite;">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="image_gallery.css">
<title style="color: blue;">Image Gallery</title>
</head>
<body class="FullBody">
<div class="Heading">
Responsive Image Gallery
</div>
<footer class="Footer">
<span class="FooterLeft">Copyright</span>
<span class="FooterRight">Created - 03/07/2024</span>
</footer>
</body>
</html>
I am unable to find any mistake or any kind of correction.
Just one more question –
When inside the class .FullBody
I did background-size: 50%
, the image changed but I don’t think it’s 50% (Just have a look). Suggest if I am missing something. Here it looks to me like 70-80%.
I tried to align things but it won’t work.
I searched and found results related to height but none related to width.
Here is a StackOverflow question on how to fit the webpage exactly the screen size without scrolling?. It also contains links to others (all related to height).
2
Answers
In your case, you have used the position:fixed CSS property, so the footer is set as the bottom only. Use the left:0 property because the in-body tag by default sets margin:8px, so you show the white space on the left side. Remove the body margin or use the left:0 property in the footer.
Also, you have used the float property to set the right side this is a bad way to use it instead of trying to use the flexbox property to align. I added some code that is helpful to you.
There are a few ways to achieve this, one of which is the simplest: use a CSS reset, even a very basic one, to remove default margins and padding. Further, don’t use
width: 100%
on block elements, such as<div>
, or<footer>
elements; these take up all available space by default, and are constrained by their parents’ padding, but if you explicitly setwidth:
100%then the elements will take that width, and the parent's
padding` will push them "outside," creating either obscured content or creating a scrollbar for a few pixels.Explanatory comments have been added to the snippets below, and references are at the end:
While the above addresses the fundamental problem, by removing the default browser styles, it doesn’t address the… "issue" of using
float
for layout. Floating used to be necessary, due to the lack of coherent layout options, but now there’s both CSS grid and flex layout, either of which could be used.So, to demonstrate:
Flex:
Grid:
References:
align-content
.align-items
.backdrop-filter
.background-color
.background-image
.background-size
.bottom
.box-sizing
.color
.display
.flex-basis
.flex-direction
.flex-flow
.flex-wrap
.float
.font-family
.font-size
.grid-area
.grid-auto-flow
.grid-template-rows
.height
.justify-content
.margin
.min-block-size
.padding
.place-items
.position
.text-align
.width
.Bibliography: