1

Eu estou precisando centralizar um texto, mas com justify-content: center e align-items: center não estou conseguindo.

Nem mesmo se eu colocar por exemplo, top: 50% e left: 50%, os itens não ficam exatamente no meio. Talvez esteja faltando alguma div ou algo assim, o preciso fazer para centralizar?

Segue o código:

@font-face {
  font-family: 'Gotham';
  src: url('Gotham-Medium.otf');
  src: url('Gotham-Medium?#iefix') format('embedded-opentype'), url('fonts/Gotham-Medium.otf') format('otf'), url('Gotham-Medium.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'Gotham-Light';
  src: url('Gotham-Light.otf');
  src: url('Gotham-Light?#iefix') format('embedded-opentype'), url('fonts/Gotham-Light.otf') format('otf'), url('fonts/Gotham-Light.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

.gotham {
  font-family: 'Gotham', sans-serif;
}

.gotham-light {
  font-family: 'Gotham-Light', sans-serif;
}

body {
  margin: 0;
}

header {
  overflow: hidden;
}

.background {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 100%;
  min-height: 100%;
  width: auto;
  height: auto;
  z-index: -1;
}

.conteudo {
  display: inline;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-weight: 275;
  width: 40%;
}

.conteudo ul {
  list-style: none;
}

.conteudo ul li {
  display: inline;
}

.conteudo ul a {
  color: black;
  font-size: 22px;
  padding-right: 8px;
  text-decoration: none;
  padding: 0.67rem 1.25rem;
  margin-right: 50px;
  border: 1px solid;
  border-color: #fff;
  background-color: #fff;
}

.conteudo ul a:hover {
  background-color: transparent;
  color: #fff;
}

.conteudo h1 {
  font-size: 92px;
}

@media only screen and (max-width: 1277px) {
  .conteudo ul a {
    margin-bottom: 5%;
    display: flex;
    font-size: 20px;
  }
}

@media only screen and (max-width: 375px) {
  .conteudo {
    width: auto;
  }
}

@media only screen and (max-width: 1277px) {
  .conteudo h1 {
    font-size: 70px;
    text-align: center;
  }
}
<!DOCTYPE html>
<html lang="pt-br">

<head>
  <!-- Mobile Specific Meta -->
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- Favicon-->
  <link rel="shortcut icon" href=".png">
  <!-- Author Meta -->
  <!-- meta character set -->
  <meta charset="UTF-8">
  <!-- Site Title -->
  <title>Farol Filmes</title>

  <script src="js/main.js"></script>
  <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  <!--CSS============================================= -->
  <link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet" />
  <link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.theme.default.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="css/linearicons.css">
  <link rel="stylesheet" href="css/bootstrap.css">
  <link rel="stylesheet" href="css/magnific-popup.css">
  <link rel="stylesheet" href="css/animate.min.css">
  <link rel="stylesheet" href="css/teste.css">
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
  <link rel="icon" href="favicon.ico" type="image/x-icon">
</head>

<body>
  <header>
    <video loop muted autoplay class="background">
   				 	<source src="video\background.mp4" type="video/mp4">	
  				</video>

  </header>
  <nav class="conteudo">
    <h1><span class="gotham-light">GUI</span> <span class="gotham">LUCCA</span></h1>
    <br>
    <ul class="gotham">
      <li><a href="#">Filme</a></li>
      <li><a href="#">Fotos</a></li>
      <li><a href="#">Contato</a></li>
    </ul>
  </nav>

  <script src="js/vendor/jquery-2.2.4.min.js"></script>
  <script src="js/vendor/bootstrap.min.js"></script>
  <script src="js/main.js"></script>
</body>

</html>

http://prntscr.com/kyjfjy

3
  • Qual versão do Bootstrap vc está usando?
    – hugocsl
    25/09/2018 às 14:37
  • Bootstrap v4.0.0-beta 25/09/2018 às 14:49
  • Legal jovem, mas pelo que vi vc praticamente não está usando classes do Bootstrap né... de qq forma editei a minha resposta e inclui o CDN do BS 4, porém não mudou em nada o resultado do código
    – hugocsl
    25/09/2018 às 14:52

1 Resposta 1

0

Cara o seu problema é que vc definiu o display na NAV como display:inline deveria ser diplay:flex para vc poder usar as propriedades justify-content: center e align-items: center. Além disso vc tem que declarar a altura e largura do documento para ficar alinhado no centro da tela.

Veja como ficou o exemplo. Não mexi em nada no HTML, apenas com o CSS. Mas vc precisa fazer o @media para tratar seu layout em telas menores. Exiba em "Página toda" para ver melhor esse resultado.

html, body {
        height: 100%;
        width: 100%;
        padding: 0;
        margin: 0;
    }
    @font-face {
    font-family: 'Gotham';
    src: url('Gotham-Medium.otf');
    src: url('Gotham-Medium?#iefix') format('embedded-opentype'), url('fonts/Gotham-Medium.otf') format('otf'), url('Gotham-Medium.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
  }
  
  @font-face {
    font-family: 'Gotham-Light';
    src: url('Gotham-Light.otf');
    src: url('Gotham-Light?#iefix') format('embedded-opentype'), url('fonts/Gotham-Light.otf') format('otf'), url('fonts/Gotham-Light.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
  }
  
  .gotham {
    font-family: 'Gotham', sans-serif;
  }
  
  .gotham-light {
    font-family: 'Gotham-Light', sans-serif;
  }
  
  body {
    margin: 0;
  }
  
  header {
    overflow: hidden;
  }
  
  .background {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -1;
  }
  
  .conteudo {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    color: #fff;
    font-weight: 275;
    width: 100%;
    height: 100%;
  }
  
  .conteudo ul {
    list-style: none;
  }
  
  .conteudo ul li {
    display: inline;
  }
  
  .conteudo ul a {
    color: black;
    font-size: 22px;
    padding-right: 8px;
    text-decoration: none;
    padding: 0.67rem 1.25rem;
    margin-right: 50px;
    border: 1px solid;
    border-color: #fff;
    background-color: #fff;
  }
  
  .conteudo ul a:hover {
    background-color: transparent;
    color: #fff;
  }
  
  .conteudo h1 {
    font-size: 92px;
  }
  
  @media only screen and (max-width: 1277px) {
    .conteudo ul a {
      margin-bottom: 5%;
      display: flex;
      font-size: 20px;
    }
  }
  
  @media only screen and (max-width: 375px) {
    .conteudo {
      width: auto;
    }
  }
  
  @media only screen and (max-width: 1277px) {
    .conteudo h1 {
      font-size: 70px;
      text-align: center;
    }
  }
  <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />

<header>
  <video loop muted autoplay class="background">
      <source src="https://www.w3schools.com/tags/movie.mp4" type="video/mp4">	
  </video>
</header>

<nav class="conteudo">
  <h1><span class="gotham-light">GUI</span> <span class="gotham">LUCCA</span></h1>
  <br>
  <ul class="gotham">
    <li><a href="#">Filme</a></li>
    <li><a href="#">Fotos</a></li>
    <li><a href="#">Contato</a></li>
  </ul>
</nav>

2
  • Deu certo aqui, muito obrigado. Para o align funcionar sempre é preciso declarar o tamanho do html e body no começo ? 25/09/2018 às 15:11
  • @LucasCorrêa sempre é bom declarar a altura do documento, pois sem uma altura no pai vc não consegue alinha o filho entende. Mas que bom que deu certo! Se a minha resposta te ajudou de alguma forma considere marca-la como Aceita, nesse ícone abaixo das setinhas no lado esquerdo da minha resposta :) assim o site não fica com a pergunta aberta sendo que já tem a resposta. E qq outra dúvida é só dar o toque que te dou uma força.
    – hugocsl
    25/09/2018 às 15:19

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .