I have written some code which can also be found on JSFiddle:
* {
box-sizing: border-box;
}
body {
font-family: 'Roboto Slab', serif;
font-size: 18px;
line-height: 1.6;
}
.wrapper {
width: 100%;
max-width: 1000px;
margin: 0 auto;
/* No spacing to top and bottom, auto spacing to left and right */
padding: 0 20px;
}
div {
margin: 10px;
padding: 10px;
}
h1 {
font-size: 36px;
text-align: center;
}
h3,
p {
max-width: 80ch;
margin-left: auto;
margin-right: auto;
}
h3 {
font-weight: 400;
font-size: 24px;
}
p {
font-weight: 300;
text-align: justify;
text-justify: auto;
}
<div class="wrapper">
<div>
<h1>Welcome! <span>I'm glad you're here.</span></h1>
<h3>My name is Andrés-J. Cremades, and I'm an Interaction/UI Designer.</h3>
<p>Usability obsessed interaction designer. Building a UX Designer career founded on strong technological knowledge. Creative and perfectionist by nature with a particular interest in graphic design and HCI with proven working team skills.
</p>
</div>
</div>
However, my issue is that the <p>
and <h3>
elements are not aligning vertically when the browser window is fully expanded.
I initially set a maximum text width of 80 characters and centered it for the <p>
element with success:
p {
font-weight: 300;
max-width: 80ch;
text-align: justify;
text-justify: auto;
margin-left: auto;
margin-right: auto;
}
Subsequently, I wanted the <h3>
element to align vertically with the new position of <p>
, so I made adjustments to the code like this:
h3, p {
max-width: 80ch;
margin-left: auto;
margin-right: auto;
}
h3 {
font-weight: 400;
font-size: 24px;
}
p {
font-weight: 300;
text-align: justify;
text-justify: auto;
}
When attempting to set a margin-left
value for <h3>
, it worked as expected. However, why do the margin-left
and margin-right
values set to auto
not work as seamlessly on <h3>
as they do on <p>
? Can someone help me understand what I might be doing wrong?