The url is https://sputnick.fr/
The HTML is:
body {
background-color: #15141A;
background-image: url("https://sputnick.fr/header.jpg");
color: white;
font-family: "Arial";
font-size: 16px;
}
<h1>foobar</h1>
<p>lorem ipsum doloris</p>
<p>lorem ipsum doloris</p>
<p>lorem ipsum doloris</p>
<p>lorem ipsum doloris</p>
I searched MDN and other ressources, but I don’t get how to do this.
I want all <p>xxxx</p>
after the background image.
Is it possible?
4
Answers
It’s not clear whether or not you want the repeating background images, but the foolproof way to say "I want X after Y" is to make them different, consecutive elements in the DOM order. Something like
If you DO want the background-image to repeat throughout your entire webpage, you have lots of options, but I would probably do something like this
This does rely on a hard-coded margin-top that matches the height of your background-image – if this height ever changes, then this code will break. If that is a likely scenario, then you could also consider doing kind of a tandem of both approaches
This has the disadvantage of relying on
position: absolute
, but will behave better if you ever change your background image’s dimensions.Hopefully this gives you some ideas to work with!
You can do it by adding padding or margin at the bottom of the h1 tag.
Check this code pen: codepen.io/gd17/pen/LYJyoeM
.heading { margin-bottom: 18%; }
I have added a custom class "heading" to h1 and added % based CSS padding.
You have set a background image on the
<body>
element which means the whole page. If you want to have content appear after an image, apply the background image to an element like<main>
instead.I suppose you want that background-image only behind the
h1
header? Well, then assign it only to theh1
. Addpadding
to make it higher and setmargin-top
to0
to make it start right at the top.