I can not get the title h1
element to be aligned to the right-side of page.
html,
body {
height: 100%;
margin: 0;
font-family: Arial, sans-serif;
}
body {
display: flex;
flex-direction: column;
}
.title {
margin: 20px;
margin-bottom: 50px;
/* Adds additional space at the bottom */
padding: 10px;
border: 6px solid black;
/* Add a rectangle (border) around the container */
display: inline-block;
/* Shrink to fit the content */
text-align: right;
width: fit-content;
}
.title h1 {
margin: 5px 0;
/* Margin between each h1 element */
white-space: nowrap;
/* Prevent line breaks, keep h1 on one line */
}
.content {
flex: 1;
margin: 20px;
text-align: left;
}
.bottom {
margin: 20px;
margin-bottom: 50px;
/* Adds additional space at the bottom */
padding: 10px;
border: 6px solid black;
/* Add a rectangle (border) around the container */
display: inline-block;
/* Shrink to fit the content */
text-align: left;
width: fit-content;
}
.bottom h1 {
margin: 5px 0;
/* Margin between each h1 element */
white-space: nowrap;
/* Prevent line breaks, keep h1 on one line */
}
<div class="title">
<a href="index.html">
<h1>AMIR TEYMURI</h1>
</a>
</div>
<div class="content">
<h2>List of compositions</h2>
<p>Content...</p>
</div>
<div class="bottom">
<a href="bio.html">
<h1>BIOGRAPHY</h1>
</a>
<a href="misc.html">
<h1>MISCELLANEOUS</h1>
</a>
<a href="contact.html">
<h1>CONTACT</h1>
</a>
</div>
4
Answers
There are many ways of doing it, one way would be to add the
width: 100%
to thetitle
class. If you need to make the border only to the link itself, you might need to change theborder
to thea
tag.Edit: as you are using
flex
for thebody
, I guess best approach would be to usealign-self: flex-end
."I can not get the title h1 element to be aligned to the right-side of page."
If you want to move the element to the right, just use the
align-self
properties from flex box. Use your flex box when you set it up.Another approach could be `grid-layout, but for that you need to alter your CSS and HTML a bit more.
Last possible option can be
position: absolute
. But I would not recommend it.Use
align-self: flex-end;
instead oftext-align: right
for.title
(which is a flex child and therefore accepts that setting.).use
align-self: flex-end;
instead oftext-align: right
for.title