HTML text after background image?

Hello,

I have to program a simple website as homework and am encountering some difficulties.

Currently I have 4 main problems:

  1. My navigation bar in the header is not centered despite text-align: center
  2. I have "2023," "Imprint," and "Alex" in the footer. "Imprint" is a relative link to a separate page, and the other two words are just words. I managed to position "2023" on the left and "Alex" on the right, but I can't move the word "Imprint" with the link. It's fairly centered, but it's too high up in the footer itself, and I can't move it down.
  3. I've set a background image in CSS (so the entire screen is covered). Now I want to make it so that the background image is visible at the beginning, and only when scrolling down should the text appear after the image, instead of on the image itself.
  4. My footer stays in one position, just before the end of the background image. This means that as soon as I scroll, my footer would be in the middle of the page instead of at the very end. I've tried all sorts of position tags, but somehow it doesn't seem to work.

Does anyone here know a lot about this and can help me?

Thank you very much in advance.

Greetings Alex

1 vote, average: 1.00 out of 1 (1 rating, 1 votes, rated)
You need to be a registered member to rate this.
Loading...
Subscribe
Notify of
60 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
DarkwingVampire
1 year ago

You can do this for the menu bar:

width: 100% and text-align: center for the wrapper. And then Max-width: 75rem and text-align: center for the actual menu.

In the footer-div you make a wrapper-div and write:

max-width: 65rem
display: flex; display: -webkit-flex
display: -moz-box
display: -ms-flexbox
flex-wrap: nowrap
flex-direction: row
justify-content: center
align-items: stretch

The three texts are then inserted into a div and then write in css for these divs:

text-align: center

I didn't understand that with the background picture. If you don't want the image to stretch over the whole page, you need to insert the image in html and not CSS. Then you can edit and move it more easily.

Just remove the background image and make it first that the page works.

DarkwingVampire
1 year ago
Reply to  VybsGF

A wrapper is just a div that ensures that your menu bar (or whatever) is correctly positioned and behaves properly and does not jump around anywhere. The actual menu then comes into its own div, which then takes over all other things. The rest doesn't matter.

I'm looking at the pictures you just put in.

DarkwingVampire
1 year ago

Do you mean "top refers to 3 things" that it appears in 3 html pages? If so, there's nothing to do with it. Because there are many elements in the 3 html pages, the menu, the footer, etc.
It is much more about the elements repeating themselves on the same page – they would then be called "class", and elements that only happen once on the respective side are "id".

But: IDs are more rarely used, nowadays almost everything is about classes. And sometimes you even have no name, such as your text on the landing page, because the text sections are only called

, which is not wrong, because you can easily address them in css with "#content p {}" – then you can also see where they come from (namely from #content).

But, of course, do as your teacher wants.

Yeah, I think you're gonna get a good note now. The others certainly didn't go so much into detail.
I'm glad I could help.

If there's anything else, please register.

DarkwingVampire
1 year ago

1. The

Unfortunately has not worked with the javascript code. The button for scrolling up has always been over the footer, as you can see now on the Orga side.
Maybe it's because the javascript requires an id. Perhaps you could make
But it works anyway.

Two. You have to write the js code in this function: "document.addEventListener("DOMContentLoaded", function(event { YOUR CODE HERE});"
You see that in the js file I created.

3. I have the code from stackoverflow. Two users posted codes. The one you have right now and the other is this: ( https://stackoverflow.com/questions/70240526/how-to-prevent-scroll-to-top-button-from-going-over-the-footer )

//Get the button
var mybutton = document.getElementById("backtotop");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {
scrollFunction()
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else
mybutton.style.display = "none";
}
// check that button is not lower than footer.
let footerElement = document.getElementById('footer');
let footerElementRect = footerElement.getBoundingClientRect();
let mybuttonPositionBottom = mybutton.offsetTop + mybutton.offsetHeight;
if (footerElementRect.y < mybuttonPositionBottom) {
// if button is lower than footer.
// modify css bottom.
let diffheight = mybuttonPositionBottom – footerElementRect.y;
let style = window.getComputedStyle(mybutton);
addBottom = parseInt(style.getPropertyValue('bottom')) + diffheight;
mybutton.style.bottom = addBottom + 'px'; // maybe add more 10 px for bottom space of a button.
} else
// if button is higher than footer. this including scroll up.
// remove custom css bottom.
mybutton.style.bottom = ''
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}

And the button sticks directly to the footer. You can try it out and play it a little bit.

4. That's because the code for the footer looks a little different. With margin you cannot really move the button. Otherwise I would have liked to see it, then I would have taken the second js code without the glitch, and then the button would have moved itself.

Five. In @media you only write the code that changes. All that remains the same is not coming in.

6. For this, there should be a function in every good code editor that automatically cleanses the code. Google after "align html code in …" and then with your editor, eg Visual Studio.

https://we.tl/t-gCAEAFa66B

DarkwingVampire
1 year ago

Very simple solution. I added the same imprint text in html before the footer and then in css @media ( MIN -width: 1600px) and set the entire text to "display: none;". So if the page is 1600 px wide, then you do not see the new text below and if the page becomes smaller, then the "display:none;" if away and the text appears. You just have to issue the old text when the new one appears.

I would still consider whether I might not make the old imprint text white because the black font behind the gray background is hard to read.

I don't have so much time tomorrow, but I'm sure I can check in again today.

https://we.tl/t-xBcT06dct1

DarkwingVampire
1 year ago

1. For the backtotop button, I took a little javascript code from the internet. Sometimes it glitches unfortunately and the button jumps to the end of the page, but usually it works.
I had found another code, so that this error does not occur, but at which the button always sticks right up on the footer and I didn't get on the quick that between Footer and Button is a distance.

Two. It is always only scrolled to the target object and you can move it. Maybe you can try to move the target object in CSS down or up. You can also use "outline: solid 1px red;" or write in html for a short time to see where #target is located.

3. You can use the "z-index" in the #imprint text, then the footer will be above the text and the background image. You can still scroll because the text now slides under the footer. The other option would only be that you push the logo on the background image upwards and then the copyright text.
With the fixed footer, however, you generally have to be very careful. On the organization side you see that there are some problems when you make the page narrower or wide. The content then goes over either the footer or if you make it smaller, then a very large white space is created between the pictures and the footer (just like on the imprint page).

4.1 I wrote you an @media code in CSS and removed the sd button there. Once you see it, you immediately know how it works. The button is simply set to "display: none;" for smaller sizes. So just fade out.

4.2.2. You can also move the backtotop button with @media if it is still not right.

4.3. Yes, you can also move it with @media. There are no limits on what to do.

Five. The problem here goes a little deeper. Since Edge has a strip on the right and above but is slightly narrower than Chrome, the background image is shifted.
The easiest thing would be if you just pushed the copyright text down – for all browsers. Then he looks normal again in Edge.
But you have often seen that there are many problems with the alignment of your text (relative to the logo). For the next time, you could just try to make the background in CSS gray and then place the logo in the middle as an image. Then you just have to worry about the div in the middle instead of the browser trying to work with the complete picture.

I hope you could take a lot of knowledge here – you're sure! For a first website this is already very good and you have got a lot of things you would learn a lot later.

https://we.tl/t-8f1d0OvJU

DarkwingVampire
1 year ago

To your new message:

(1) If the background image is removed, then only #orga remains and this has a position "absolute" and a "top" value in css. That's why all your content disappears. As already said, position: absolute; not a nice solution, because there are often problems later. But without the background picture we do not need a position: absolute; more.
The footer can be brought down if you simply do "position: fixed;" and then "top" and "bottom" on 0.

If you don't want the footer to be constantly visible, you need to give the #orga up a little more space and up and down (padding) to close this gap to the footer. (Background color is just set on green so you can see that.)

2) So that you don't scroll down so far, you have to give the "#target object" to an empty div that you place in CSS a little further up. Look where I placed him in html and what code he got in CSS. That's all self-explanatory.

The whole responsive line can settle later when the rest fits. As said, the elements ALWAYS are displayed smaller when the page is called on on a smaller device. But only if the x AND y axis is reduced. If the side is only horizontally dipped, then of course nothing should happen. I don't think your teacher really wants you to, but just think that the elements shouldn't get out of the side if you make the window smaller.
Everything else would be a complete disaster and you should never learn or get used to it.
If you want to do this, you can always use "position: absolute;" then the elements will stick in their place.
But as said: "position: absolute;" one will almost never use in reality and one should rather learn to position the elements differently.

https://we.tl/t-yGTeh3lEdM

DarkwingVampire
1 year ago

To your old message:

2) The sd button now works again. I just took the code from earlier, because I had already programmed it so that it works properly.
By the way, you should always create backups with date, then you can always go back and see how it looked earlier than it still worked.

3) Here it is enough to give the pictures simply a width with a percentage. h1 and h3 have a "vw" function as font-size. That's similar to percent.
But this is only to enjoy with caution – on a real website one would not work with such relative values. Because the images are displayed so or so smaller on a smaller screen. You'll see that you'll get a large white area under your website if you make the window smaller. Therefore, the elements should not be smaller if the window is only horizontally compressed. But I'm doing this for the job.

4)
can be used quietly. It would be best if you tried to bypass them, but this is not so important.

5) In the #kontakt-wrapper you can simply put "justify-content" on "center", then the contact details come together, and then you can "gap: 15rem" the way you want.
Place elements in the middle (as you want with the author text) you can always use "margin: 0 auto;". The "display: flex;" I used to get rid of it because you don't really need it.
However, consider that "margin: 0 car;" no longer works when your element has a "position: absolute;".
If you want a block set, you can do it with "text-align: justify;".

6) In Edge, the page is so far left because the browser has a bar on the right side. Each page is automatically moved to the left. So it's all right.

DarkwingVampire
1 year ago

1. The gap on the imprint page is the background (so body). Such small mistakes can always be checked quickly when you change the background color at body. I always leave my background color on red, then I immediately see if a gap is created somewhere.
Since all pages have the same CSS, it must be something in html. And in this case it is the

"Imprint". I just placed it downstairs in the code, so after the background picture. And then in css the height still adjusted.

2. Yep. This is all with a flexbox. You should get that. It's hard for me to imagine where you want to have what text, but it's only technically possible.

3. I changed the code for the text again, html and CSS. Before that, the text ran out of the picture and you couldn't see if the page was made smaller. Now at least the text remains above the picture. Of course, however, the text still needs to be adjusted with @media so that it is not over the logo at some point and you can't read anything.

4. The -webkit should be directly under the flexbox code. As I said, you can actually leave it because everything works anyway. And at some point, you have to try out the page on multiple browsers and grudges anyway. Then you'll see possible mistakes.

Five. The problem has now been solved with the new html code for the background image. I believe this was due to that

, because it automatically comes with certain properties such as line height, font size, etc.
The only distance that's still here comes from padding-top and bottom.

6. The linking in html thus looks like ""

The button to scroll down does not work properly. Make a "* {outline: solid 1px red;}", then you see that a box appears again above the button. It wasn't like that in the old version.

The more code we write now, the more can also get broken and the more difficult it becomes to find a solution because everything builds on one another. But you only learn this with the time you write it so that everything works well.

https://we.tl/t-jWuDvc69mh

DarkwingVampire
1 year ago

1. The btt button is out of the footer now. Is quiet in the

day, but now moves on the page. With the "top: 85%;" you can move it as you like and set it with "filter: opacity(…);" and the hover as you want. In addition, it only appears when you scroll down. For this I found a simple javascript code that is under the
in HTML.

Two. Making the header asymmetrical is easy. Now it is 4rm to the right, because the gap is also exactly 4rm large between them, and now this size is exactly right. The code is for #header with "padding-left: 5rem; padding-right: 1rem;". If you want to have it centered again, instead of padding-left/right you do "padding: 0 2.5rem;" as before.

3. You can see the code to place "Imprint" above the picture. Hope that's what you wanted. I don't know how you wanted to place the text. Maybe also on the picture like imprint, just below. As it goes, you can see the other elements that are above the picture. So with "position: relative."
"position: absolute;" you should try to avoid if possible. In general, I would always try to arrange things with one another instead of one another, because it is quickly complicated and can break a lot, and quite strangely shifts when the page is to become responsive.
After all, this comes to you anyway, because most websites call on mobile devices.

Sometimes you see this -webkit or -moz, this is just for the code also working on other browsers. Meanwhile, this is not necessarily necessary because almost everything works everywhere, but does not bother when it is there.

You should also try to see if the page is running on different browsers, because it can be that a specific CSS code does not work because it joined later, like flexbox.

The two heights at the header are a mistake, I deleted the upper one. The CSS code is always read from top to bottom, so I removed the top because it wasn't active.
Sometimes you really need to think about what's up and what's down there, because sometimes you need to write a code that depends on what was before.
That's why it's always like sizes and positions to the top.

https://we.tl/t-DtS2vJv1SL

DarkwingVampire
1 year ago

Your project with the imprint text that shrinks with the image will not work. Here you can see what it looks like when the window shrinks to 480 pixels (so a quarter of a 1,920 pixel monitor): comment image. You can't read anything. It's just too much vertical text. Better if the text was horizontal.

1. The code from the imprint could have just been downloaded and then exchanged. I did this almost. But "Impress" is still right in the middle. Your circle to scroll down is just too far right.

Two. The menu bar should now work perfectly. See the CSS code of .header-wrapper, .header, .header nav and .header nav a. Maybe you don't understand it right now, but in any case it works and you can also use it for later projects.

3. The scroll down button is now coupled to the image. You can also copy the code for the imprint page.

4. Button to scroll up now also works. Of course, he has to be much smaller because he's disturbing and standing above the name.

From now on, I would not program such little things and focus on the big and whole. Such buttons for scrolling up and down are only necessary for very large websites.

https://we.tl/t-1NI4MLfw1a

DarkwingVampire
1 year ago

At the footer I removed the "text-align: center;" the year. Now the distance left and right is the same. "Imprint" remains in the middle, but if the page becomes smaller, then the year and name comes closer to the middle and then you realize that the distance from year to imprint is greater than from name to imprint.
But you can't prevent it, otherwise you should change the distance left and right again.

The Flexbox on the "Organization" page works now. See how the divs are created and what you need in html. This is often always the same scheme: only in general a div with ".org" where everything comes in and then a "wrapper" which sets the functions, eg "margin: 0 car;" so that it is centered (blue box), and so on…

The images you used should have the same size in the best case, either all square or at least the same width.

The fact that the images are to be smaller when the screen shrinks already works automatically. But before that, the elements are first drawn together, so they come closer together, which is also correct. So it all works as it should.

To optimize the page for mobile devices, you will need to add an @media query later. A new CSS code is then written when the page becomes, for example, smaller than 750px. Then, for example, elements that are displayed next to one another are displayed, because there is often no space on mobile devices to position things next to one another. But you don't have to.

You can easily change the backtotop image in CSS with these commands (just select what you need)

.backtotop:hover {
filter: saturate(3);
filter: grayscale(100%);
filter: contrast(160%);
filter: brightness(0.25);
filter: blur(3px);
filter: invert(100%);
filter: sepia(100%);
filter: hue-rotate(180deg);
filter: opacity(50%);
}

The one with scrolling and that the button should only be displayed afterwards and disappear again with javascript. I don't know if it was possible with CSS. If, then it's probably very complicated. I also doubt that you need this for the task. But these are also more things you need when the page is really extremely long. I would first make sure that the page works well from scratch and has no mistakes before I make such "games" and animations. Because as you can see, you're already busy with the simple things.

https://we.tl/t-eLXH2HBgX

DarkwingVampire
1 year ago

#imprint is now in the middle. For this I simply gave the three elements a width (width: 10rem) so that they all have their own box and then centered them in their box with "text-align:center".

To use the width "rem" is very important here because with px or % the boxes are oriented to the entire document and with rem they are dependent on the text – so if the page becomes smaller (responsive), then the text does not go beyond the box because the box is always larger than the text. With width: 10% the box would become smaller and "Imprint" would no longer be centered from a certain point and flow out of the box.

Here's the code:

#year, #imprint, #name {
outline: solid 2px red;
width: 10rem;
text-align: center;
}

For the back-to-top button, I lack the HTML code, but actually you don't have to make it that it only appears after scrolling, because a scroll button isn't visible anyway if you haven't arrived down. And if you see it from the beginning, it's unnecessary because you don't need to scroll so much.

Otherwise you can look at something like this: " https://stackoverflow.com/questions/61246614/make-element-visible-only-if-scrolled-down-or-page-higher-than-only-video-css- " or with javascript: " https://css-tricks.com/how-to-make-an-unobtrusive-scroll-to-topbutton/ "

For the scroll button with which you scroll down, I wrote a few code lines. It's a bit more difficult. The idea is that the scroll button is simply a link ( ), but with "href" there is no website, but an ID or class that appears below in the document. Thus, with the link " " you jump to the code at the bottom"

Here is the target object

". So at href stands "#target object", and that is exactly the ID of the DIV at the bottom to which you should jump.

In CSS you have to write "html {scroll-behavior: smooth;}" so that the jumping is liquid -> so a normal scrolling.

But in order for the link to be on the picture, you have to write a little something in CSS. You can see this at "#background" and ".scroll-down". And the nav at the top has a "z-index: 999;" otherwise it would disappear through the new code from the background image.

You can then move and format the text at the "Springs down" base. And the whole

, you can of course also delete everything and also various.

On the other hand, where the text is to be on the picture, it works just as with "Springs down".

DarkwingVampire
1 year ago

"Imprint" is right in the middle of my base. I remeasured with Photoshop and it fits perfectly.

comment image

DarkwingVampire
1 year ago

(In CSS, the code is "outline: solid 1px blue;" so that you can see how the elements stand and what changes exactly when you write something about the code. If you don't need it anymore, you can delete it.)

In html I removed the ULs and ILs for the footer and made DIVs. A flexbox was then created in CSS. This solves a lot of problems at once.

With "display:flex" it becomes a flexbox. "flex-flow:nowrap" prevents the elements from jumping into a second line. With "justify-content: space-between" it is said that the elements are to be distributed across the entire width of the page. And the distance left and right comes from "width: 95%".
Then there was added "padding-top" and "padding-bottom" so that there is little space on top and bottom.

I didn't change the menu bar. You can do it yourself with the flexbox. This will be a little exercise for you. I've changed HTML, you just have to do CSS and follow the footer code. At "justfy-content" you can choose either "space-between", "space-around" or "space-evenly". Just try.
And from nav you can change the width if you want. She's 50% right now.

I didn't look at the pages "Further Organization" and "Imprint". Look that everything is important for the landing page, then you can easily copy the code. If the codes are exactly the same, everything will work there.

DarkwingVampire
1 year ago

Give me your code. Put the html and css up somewhere and copy everything in here.

DarkwingVampire
1 year ago

Here is the html and css file: https://we.tl/t-X2i57fwbah

DarkwingVampire
1 year ago

I moved the background image to html. It was in the day, now it is between

and

. The elements should be in html as they will be on the website later. That's the right order.

How did I remove the white frame around the background picture? A always automatically has a space around itself. To get rid of it, the must be converted into a kind of div element. This goes with "display:block". Then it behaves like a div. Now you can write a new code in CSS:


margin:0;
border: 1px solid blue;
}

This code means that ALL elements in the document, ie every img, every div, everything… no longer has a margin. So a margin of 0. This removes all spaces and gaps.

And another little tip if you have problems. Write in CSS in the "*" simply "border: 1px solid blue;" then EVERY element is marked blue and you can better see where the gaps come from, then you don't have to look for long.

You can actually remove the "id" from the (landing page) because body occurs only once; that doesn't need an ID. You can write "body" in CSS. Like "html"

Your menu bar is already centered; I didn't do that.

I pushed the text in the footer apart with "margin-left:20rem;". But the 20 rem from the first text (2023) removed again with "#ul-landingpage li:first-child: margin-left:0rem;". This is not a nice solution, but normally would not necessarily work with ul and li. There are better alternatives.

Look at flexbox https://css-tricks.com/snippets/css/a-guide-to-flexbox/. You can easily arrange elements. Of course, you have to understand it first, but if you can, it makes everything so much easier.

DarkwingVampire
1 year ago

Okay, I'll try to write something on the code either today or tomorrow. If no one else answers here.