My goal is to place the text (in the example below – "Publisher’s Name") at the bottom of the page, while aligning it at the center.
Problem is, for some reason, the block with this text is being moved outside of the boundaries of the <body>
. Therefore, when I try to set the margin
for the whole page (<body>
), it is calculated incorrectly, i.e. not includes this bottom text.
Question: what should be the correct CSS code that achieves my goal?
Code I’m currently trying:
<body style="text-align: center; border: 5px solid black; margin: 50px;">
<h1 style="text-transform: uppercase; font-size: 300%;">Book<br/> Title</h1>
<p style="position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);">
<img alt="Logo" src="https://via.placeholder.com/150" style="height: 2.5em; width: auto;" />
<br/> Publisher's
<br/> Name
<br/> 2018
</p>
</body>
3
Answers
try this:
This could be done like this, no transform needed.
Also: Think about putting your CSS into a .css file, inline css isn’t really a good way 😉
As you well observed: the
margin
is 2x50px
, and with theborder
2x5px
they together add up110px
. So, I used thecalc()
CSS function for the centering not to slip to the right, since the margin starts from the left. This is because themargin
on thebody
offsets the content from the browser’s viewport.