Как установить одинаковое расстояние между элементами заголовка? - PullRequest
0 голосов
/ 31 августа 2018

Я использую justify-content: space -ween для горизонтального распределения всех элементов по всему заголовку. Это работает нормально, пока я не добавлю padding-right: 20px к моим ссылкам навигации. Он сдвигает мой заголовочный элемент h2 вправо, делая его неровным. Как сохранить отступы, но выровнять ли мои элементы одинаково? Помощь оценена, спасибо.

https://jsfiddle.net/2fr3L8zh/14/

HTML

<header>
 <div id="header-wrapper">
  <nav>
   <a>Projects</a>
   <a>About</a>
   <a>Contact</a>
  </nav>

 <h2>EMMANUEL OJIJI</h2>
 <p>SOCIAL MEDIA HERE</p>
 </div>
</header>

<section id="intro">
<div id="intro-wrapper">
<h1>I'm Lorem Ipsum — a Birmingham -based Visual Designer with a passion and 
a firm belief in considered and meaningful design.</h1>
</div>
</section>

CSS

html {
margin: 0;
padding: 0;
height: 100%;
}

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

header {
height: 100px;
background-color: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
display: flex;
justify-content: center;
align-items: center;
padding-left: 50px;
padding-right: 50px;
}

#header-wrapper {
width: 90%;
display: flex;
justify-content: space-between;
align-items: center;
}

nav a {
padding-right: 20px;
}

#intro {
height: 90vh;
display: flex;
justify-content: center;
align-items: center;
}

#intro-wrapper {
display: flex;
text-align: center;
width: 50%;
}

#intro-wrapper h1 {
font-weight: 700;
font-family: 'Raleway', sans-serif;
font-size: 2.2em;
line-height: 60px;
color: #333;
}

1 Ответ

0 голосов
/ 31 августа 2018

Избегайте отступов для последнего элемента навигации:

nav a:not(:last-child)

html {
  margin: 0;
  padding: 0;
  height: 100%;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

header {
  height: 100px;
  background-color: white;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: center;
  ;
  align-items: center;
  padding-left: 50px;
  padding-right: 50px;
}

#header-wrapper {
  width: 90%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

nav a:not(:last-child) {
  padding-right: 20px;
}

#intro {
  height: 90vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

#intro-wrapper {
  display: flex;
  text-align: center;
  width: 50%;
}

#intro-wrapper h1 {
  font-weight: 700;
  font-family: 'Raleway', sans-serif;
  font-size: 2.2em;
  line-height: 60px;
  color: #333;
}
<header>
  <div id="header-wrapper">
    <nav>
      <a>Projects</a>
      <a>About</a>
      <a>Contact</a>
    </nav>

    <h2>EMMANUEL OJIJI</h2>
    <p>SOCIAL MEDIA HERE</p>
  </div>
</header>

<section id="intro">
  <div id="intro-wrapper">
    <h1>I'm Lorem Ipsum — a Birmingham -based Visual Designer with a passion and a firm belief in considered and meaningful design.</h1>
  </div>
</section>
...