The header on my page has a image background. I’d like help positioning the “bottom-box” so that it appears along the bottom of the image no matter what size screen is used for viewing.
What code can I add to have the “bottom-box” appear along the bottom of the image(header.jpg), no matter what size screen is used for viewing?
Are you talking about a “sticky” footer? If so, Paul has several examples (you can search for them here). If not, a screen shot mockup of what you’re looking for might help.
I very much doubt that the above code will work reliably as vertical margins are based on the width of the element so the 45% will vary depending on the width of the containing block.
45% also smells of magic numbers and magic numbers should be avoided in CSS. The min height 720px is also another magic number and doesn’t belong in a responsive design as it bears no relation to anything.
You may find that it works for your one use case but this is not the correct way to approach this problem
I was wondering how is % margin considered magic numbers?
because what I understand using auto can only be applied to content that sit alone for example adding content next to a div with margin auto doesn;t divide the remaining space but gets ignored?
so I am wondering how can it be considered as magic numbers when its kind of like absolute postioning but being able to flow with content for example moves closer to the edge when xcreen size shrinks naturally that the flow of responsive design.
maybe I am wrong but I am just curious I don;t mean any harm or anything as this was just a curious question since I use it alot?
Percent margin is not a magic number but the number 45 is a magic number
45% of what and why does 45% work. What about 44% or 46% or 32%? What happens when content in the footer changes?
vertical margins refer to the width of the containing block so 45% on 2000px screen is going to move the footer down by 900 pixels. On a 1000px width screen the footer is only pushed down 450px yet the min-height magic number is 750px so there is no matching of anything. All are magic numbers and unusable in a responsive situation.
Lets take the actual code the OP has posted and I show a screenshot below of a 2000px screen and a 1000px screen approx.
As you can see the footer is never in the right place. I actually couldn’t find a screen width where it worked for me?
On the other hand if you look at the code I provided (which I took time to construct) the footer is at the bottom of the screen no matter the height or width of the monitor and does not rely on magic numbers at all.
You can of course lead a horse to water but you can’t make him drink
Thanks for all the replies.
I don’t know if I’m reading this thread incorrectly,
but it seems like I was originally asking for a box to appear along the bottom of an image,
and the replies were about a footer at the bottom of a page.
So, after messing around, it semed like the 45% work fairly well for my purpose.
If I’m reading this wrong, or there’s a better solution, I look forward to any reply.
Thanks again.
Did you look at my screenshot that shows how 45% behaves?
Did you understand that the 45% is based on the width of the containing block and not the height? That means it will vary considerably on the width of the viewport.
I’m only trying to help as I know the code you are using is not a viable approach.
If you just want text at the bottom of an image then you don’t have to make guesses with things like 45%.
Maybe we misunderstood what you are trying to do but I can tell you that 45% is not the answer. You need to use a method that doesn’t rely on magic numbers like 45% and 720px.
Hi,
At first I was under the impression that you were wanting an image caption, but the only image I see is a background-image on your header.
So if you don’t have enough content to hold it open to the bg-image height it would need a min-height to hold it open.
Assuming the bg-image is what were talking about here, you can use flexbox with a min-height. Then set the .bot-box as margin-top:auto to push it to the bottom of the header.
I also pushed the .top-box down with margin-top:98px; since I saw that you had padding-top:98px; on your header. Using a margin will keep you from having to calculate padding in to the min-height.
Still not sure I understand what your after but see if this works and make adjustments as you need.
I still think you would be better off with the approach in my original post as any method that relies on a min height in px is going to leave your message below the fold on some screens.
The technique I used is similar to the sticky footer technique and gives you a full page image which is a common design pattern. The caption message will always be visible no matter the screen size.
If you don’t want the image at full screen you can reduce the percentage height of course.
Hi Paul,
I’m still unsure what Chrisj’s intention is, what I understand from the comments though, is that the bottom box message is to be at the bottom of the image.
Whether or not the box stays above the fold on smaller screens didn’t seem to be a concern, or I see no mention of that from Chrisj.
I’m sure a media query may be needed to control the background-size for smaller screens, that’s yet to be determined as the aspect ratio is unknown.
Seems like 45% is an attempt to get the box at the bottom of the image, obviously this would only work on their monitor/browser settings and more than likely for desktops only.
I don’t think keeping the bottom box above the fold was ever the intention, I could be wrong though.
It would be best if we could see the actual image and confirm the intentions.
Yes I was trying to offer something more usable that didn’t need magic numbers and worked for most screen sizes without media queries but may have not been what Chris was after.
Chris’s original request of course needs no extra code because the text would always be at the bottom of an image simply by following it in the html.
I assumed the text was to be overlaid on the image itself but at the bottom part of the image and the current design pattern for that is the full page effect I offered. Chris’s min- height of 750px lead me to believe that this was a full page effect that was attempting to fit the viewport.
However you may be right but I still don’t think it’s a good design pattern to let the text go below the fold if all you have on the first page is just an image.
Either way I think we’ve both covered all bases now
Yes but 720px tall!! That’s a full page not a header But I know what you mean - I’m just being awkward :). I’m also just trying to lead the witness in the right direction
If its just a header than really it should be an intrinsic ratio and not a fixed height so that it can scale up or down within reason. A blanket height of 720px is not really usable in a responsive site although of course you could control with multiple media queries depending on screen size but I often find that an awkward maintenance issue.
However if the image is half way down the page to start with then most of my assumptions will be wrong and the fold is not an issue as such and your methods would be correct
I added the Position:relative to #head and than simply added position:absolute; bottom:0px; left:0px; to .bottom-box
and the results work obviously content that push at the bottom of the container would be overlapped by the footer of the image so what I did was repeated the .bottom-box and named it .invisi-box than gave it visibility:hidden; so if the content ever reached the bottom the invisi container will take up space to keep pushing the .bottom-box from taking over the content.
Yes you could place an absolute element at the bottom of a container or background image and in some circumstances that would be fine.
As usual with CSS it depends on the context and what comes next. If you had lots of text then it may not fit within its relative container and overflow the page. If it’s just a couple of words on one line then you can probably accommodate it easily enough.
Adding duplicate content to hold the page open is of course a bad practice and bad for seo and could get you marked down especially as you have hidden the text. I would have just padded out the container to preserve the absolute element.
Absolute positioning is fine in small doses but when you have unknown amounts of text then its best to find a more robust solution that won’t break if someone resizes the text or your cms outputs too many lines.
In the end it all depends on context so sometimes absolute positioning is a good answer and sometimes its not.
One of the key things I’ve learned is always to say “What IF?”
What if there are ten lines of text.
What if the image is smaller
What if the user uses text zoom only.
What if an unbroken word is longer that the space I allocated.