2014-10-23 3 views
2

У меня есть текстовый блок по центру, но по какой-то причине он держится влево! Я думаю, что это может иметь какое-то отношение к моей максимальной ширине и максимальной высоте, но я не совсем уверен.Как центрировать выравнивание элементов на моей странице?

@charset"utf-8"; 
 

 
/* CSS */ 
 

 
body {} 
 
.top-content { 
 
    text-align: center; 
 
} 
 
header { 
 
    font-family: "Ostrich Sans Rounded", sans-serif; 
 
    font-size: 72px; 
 
} 
 
#quote { 
 
    font-style: italic; 
 
    font-size: 20px; 
 
    color: rgba(0, 0, 0, 0.5); 
 
} 
 
nav li { 
 
    display: inline-block; 
 
    font-size: 25px; 
 
    font-family: "Ostrich Sans Rounded", sans-serif; 
 
    color: #ffffff; 
 
    margin: 0px 48px 0px 48px; 
 
} 
 
nav { 
 
    position: static; 
 
    text-align: center; 
 
    background-color: #000000; 
 
    padding: 1px; 
 
} 
 
a:link { 
 
    text-decoration: none; 
 
} 
 
a:visited { 
 
    text-decoration: none; 
 
} 
 
a:hover { 
 
    text-decoration: none; 
 
} 
 
a:active { 
 
    text-decoration: none; 
 
} 
 
.main-content { 
 
    text-align: center; 
 
    max-height: 100%; 
 
    max-width: 75%; 
 
} 
 
#table { 
 
    table-layout: fixed; 
 
} 
 
.pic-box { 
 
    width: 150px; 
 
    height: 150px; 
 
    margin: 5px; 
 
} 
 
span { 
 
    display: inline-block; 
 
}
<body> 
 
    <div class="top-content"> 
 
    <header>John Simons</header> 
 
    <p id="quote">"Life Is Graphics"</p> 
 
    <article> 
 
     <p>I am a work-o-holic. There will never be a day that I am sitting around and not designing. 
 
     <br>In my spare time I enjoy taking walks, messing around with random design pieces, and hanging out with my flawless girlfriend(she told me to put that).</p> 
 
    </article> 
 
    </div> 
 
    <nav> 
 
    <ul> 
 
     <a href=""> 
 
     <li>Home</li> 
 
     </a> 
 
     <a href=""> 
 
     <li>About</li> 
 
     </a> 
 
     <a href=""> 
 
     <li>Work</li> 
 
     </a> 
 
     <a href=""> 
 
     <li>Projects</li> 
 
     </a> 
 
     <a href=""> 
 
     <li>Contact</li> 
 
     </a> 
 

 
    </ul> 
 
    </nav> 
 
    <div class="main-content"> 
 
    <article> 
 
     <p>I started designing when I was 13. Inspired by youtube videos, I began designing youtube channel layouts and from there my passion sparked. I couldn't stop. Everyday I was grinding to get my work out there. Even at a young age I was motivated to 
 
     become the world's best designer. 
 
     <br> 
 
     <br>My goal is to ignite that same spark that was ignited in me. I want to have a team of designers that share the same passion for graphic design. 
 
     <br> 
 
     <br>It would be a treat to work alongside fellow designers, making a difference, and showing people that "life is graphics."</p> 
 
    </article> 
 
    <div id="table"> 
 
     <h3>My Work</h3> 
 
     <span class="section-1"> 
 
      \t <figure> 
 
       \t <img src="../../Pictures/Portfolio/Faded Fridays.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Reach.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Growing Life.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Le's Do It.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Mountain Dew Design.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
      </span> 
 
     <span class="section-2"> 
 
      \t <figure> 
 
       \t <img src="../../Pictures/Portfolio/Faded Fridays.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Reach.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Growing Life.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Le's Do It.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Mountain Dew Design.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
      </span><span class="section-2"> 
 
      \t <figure> 
 
       \t <img src="../../Pictures/Portfolio/Faded Fridays.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Reach.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Growing Life.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Le's Do It.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Mountain Dew Design.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
      </span> 
 
     <span class="section-2"> 
 
      \t <figure> 
 
       \t <img src="../../Pictures/Portfolio/Faded Fridays.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Reach.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Growing Life.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Le's Do It.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Mountain Dew Design.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
      </span> 
 

 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>

fiddle

+0

возможно дубликат [Установить ширину Div, выровнять Див центр и выравнивание текста влево] (http://stackoverflow.com/questions/6952233/set-a-div-width -align-div-center-and-text-align-left) –

ответ

4

Использование margin: 0 auto для main-content:

@charset"utf-8"; 
 

 
/* CSS */ 
 

 
body {} .top-content { 
 
    text-align: center; 
 
} 
 
header { 
 
    font-family: "Ostrich Sans Rounded", sans-serif; 
 
    font-size: 72px; 
 
} 
 
#quote { 
 
    font-style: italic; 
 
    font-size: 20px; 
 
    color: rgba(0, 0, 0, 0.5); 
 
} 
 
nav li { 
 
    display: inline-block; 
 
    font-size: 25px; 
 
    font-family: "Ostrich Sans Rounded", sans-serif; 
 
    color: #ffffff; 
 
    margin: 0px 48px 0px 48px; 
 
} 
 
nav { 
 
    position: static; 
 
    text-align: center; 
 
    background-color: #000000; 
 
    padding: 1px; 
 
} 
 
a:link { 
 
    text-decoration: none; 
 
} 
 
a:visited { 
 
    text-decoration: none; 
 
} 
 
a:hover { 
 
    text-decoration: none; 
 
} 
 
a:active { 
 
    text-decoration: none; 
 
} 
 
.main-content { 
 
    text-align: center; 
 
    max-height: 100%; 
 
    max-width: 75%; 
 
    margin: 0 auto;/*add margin 0 auto*/ 
 
} 
 
#table { 
 
    table-layout: fixed; 
 
} 
 
.pic-box { 
 
    width: 150px; 
 
    height: 150px; 
 
    margin: 5px; 
 
} 
 
span { 
 
    display: inline-block; 
 
}
<body> 
 
    <div class="top-content"> 
 
    <header>John Simons</header> 
 
    <p id="quote">"Life Is Graphics"</p> 
 
    <article> 
 
     <p>I am a work-o-holic. There will never be a day that I am sitting around and not designing. 
 
     <br>In my spare time I enjoy taking walks, messing around with random design pieces, and hanging out with my flawless girlfriend(she told me to put that).</p> 
 
    </article> 
 
    </div> 
 
    <nav> 
 
    <ul> 
 
     <a href=""> 
 
     <li>Home</li> 
 
     </a> 
 
     <a href=""> 
 
     <li>About</li> 
 
     </a> 
 
     <a href=""> 
 
     <li>Work</li> 
 
     </a> 
 
     <a href=""> 
 
     <li>Projects</li> 
 
     </a> 
 
     <a href=""> 
 
     <li>Contact</li> 
 
     </a> 
 

 
    </ul> 
 
    </nav> 
 
    <div class="main-content"> 
 
    <article> 
 
     <p>I started designing when I was 13. Inspired by youtube videos, I began designing youtube channel layouts and from there my passion sparked. I couldn't stop. Everyday I was grinding to get my work out there. Even at a young age I was motivated to 
 
     become the world's best designer. 
 
     <br> 
 
     <br>My goal is to ignite that same spark that was ignited in me. I want to have a team of designers that share the same passion for graphic design. 
 
     <br> 
 
     <br>It would be a treat to work alongside fellow designers, making a difference, and showing people that "life is graphics."</p> 
 
    </article> 
 
    <div id="table"> 
 
     <h3>My Work</h3> 
 
     <span class="section-1"> 
 
      \t <figure> 
 
       \t <img src="../../Pictures/Portfolio/Faded Fridays.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Reach.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Growing Life.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Le's Do It.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Mountain Dew Design.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
      </span> 
 
     <span class="section-2"> 
 
      \t <figure> 
 
       \t <img src="../../Pictures/Portfolio/Faded Fridays.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Reach.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Growing Life.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Le's Do It.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Mountain Dew Design.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
      </span><span class="section-2"> 
 
      \t <figure> 
 
       \t <img src="../../Pictures/Portfolio/Faded Fridays.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Reach.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Growing Life.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Le's Do It.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Mountain Dew Design.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
      </span> 
 
     <span class="section-2"> 
 
      \t <figure> 
 
       \t <img src="../../Pictures/Portfolio/Faded Fridays.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Reach.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Growing Life.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Le's Do It.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
       <figure> 
 
       \t <img src="../../Pictures/Portfolio/Mountain Dew Design.jpg" alt="Faded Friday's EP Cover" class="pic-box" /> 
 
       </figure> 
 
      </span> 
 

 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>

0
  1. Удалить max-width: 75%;
  2. ИЛИ добавить margin: 0 auto;, это, вероятно, то, что вы хотели.
0

Добавить margin: 0 auto; в .main-content

+0

Достаточно «margin: auto». –

Смежные вопросы