0

Estou tentando centralizar tanto na horizontal quanto na vertical esse h3 porém ele está maior que a imagem, então quando muda o tamanho do dispositivo que ele esta sendo visto acaba saindo do centro:

inserir a descrição da imagem aqui

As imagens tem um min-width: 285px; e um max-width: 368px; e gostaria que o width do h3 acompanhasse isso para ficar centralizado tanto na horizontal quanto na vertical,como eu posso fazer isso? já tentei colocar isso no h3 mas não funcionou como eu esperava

@import url('https://fonts.googleapis.com/css2?family=Raleway:ital,wght@1,500&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Raleway:ital,wght@1,500&family=Work+Sans&display=swap');

* {
    padding: 0;
    margin: 0;
}

header {
    background-image: linear-gradient(rgba(0,0,0,0.45),rgba(13, 224, 207, 0.15)),url(1.jpg);
    width: 100%;
    height: 95vh;
    background-size: cover;
    background-position: center;
}

html, body {
    overflow-x:hidden 
} 

body {
    overflow-x: hidden;
    width: 100%;
    height: 100%;
}

.logo {
    font-size: 25px;
    margin-top: 25px;
    cursor: pointer;
    font-family: 'Work Sans', sans-serif;
}

nav {
    display: flex;
    justify-content: space-around;
    align-items: center;   
}

ul li a {
    text-decoration: none;
    color: #fff;
    font-family: 'Raleway', sans-serif;
    transition: 0.3s;
}

a{
    text-decoration: none;
}

ul li a:hover {
    opacity: 0.7;
}

.nav-list ul li {
    list-style: none;
    display: inline-block;
    margin: 25px 32px 0 0;
    letter-spacing: 2px;
}

.info-1 {
    width: 100%;
    position: absolute;
    top: 35%;
    color: #fff;
    margin-left: 5%;
    

}

.info-btn {
    border-radius: 5px;
    background-color: white;
    border: none;
    margin-top: 25px;
    padding: 10px 10px;
    font-family: 'Raleway', sans-serif;
}

.info-2 {
    width: 100%;
    position: absolute;
    top: 15%;
    left: 50%;
}

.info-img {
    width: 1100px;
}

.info-1 h1 {
    font-size: 3em;
}

.info-1 p {
    font-family: 'Raleway', sans-serif;
    letter-spacing: 1px;
    margin-top: 17px;
}

.imgs-travel {
    width: 60%;
    min-width: 1292px;
    margin: 55px auto 55px;
    display: flex;
    justify-content: space-between;
}

.imgs-travel h3 {
    text-align: center;
    font-family: 'Work Sans', sans-serif;
    font-size: 25px;
    text-shadow: 1px 2px black;
    color: #fff;
    position: relative;
    top: -50%;
}

.img1 .la {
    width: 95%;
    min-width: 285px;
    max-width: 368px;
    height: 205px;
    border-radius: 4px;

}

.img2 .paris {
    width: 95%;
    min-width: 285px;
    max-width: 368px;
    height: 205px;
    border-radius: 4px;
    padding: 0 ;
}
.img3 .rj {
    width: 95%;
    min-width: 285px;
    max-width: 368px;
    height: 205px;
    border-radius: 4px;
}
.img4 .miami {
    width: 95%;
    min-width: 285px;
    max-width: 368px;
    height: 205px;
    border-radius: 4px;
}

div .img1 {
    width: 95%;
    min-width: 285px;
    max-width: 368px;
    width: 349px;
    height: 205px;
}

div .img2 {
    width: 95%;
    min-width: 285px;
    max-width: 368px;
    width: 349px;
    height: 205px;
}

div .img3 {
    width: 95%;
    min-width: 285px;
    max-width: 368px;
    width: 349px;
    height: 205px;
}

div .img4 {
    width: 95%;
    min-width: 285px;
    max-width: 368px;
    width: 349px;
    height: 205px;
}

.search-div {
    background: linear-gradient(rgba(108, 190, 180, 0.349),rgba(0,0,0,0.50)),url(search.jpg);
    width: 100%;
    height: 45vh;
    background-position: center;
    background-size: cover;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    display: flex;
}


.search-div h1 {
    color: #fff;
    text-align: center;
    padding-top: auto;
    font-family: 'Work Sans', sans-serif;
}

.search-div input {
    margin: 25px 0 0 0;
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 400px;
    height: 30px;
    border-radius: 7px;
    border: none;
    outline: none;
}
.search-div a button {
    display: block;
    margin-left: auto;
    margin-right: auto;
    margin-top: 35px;
    width: 100px;
    height: 35px;
    border-radius: 5px;
    border: none;
    outline: none;
    transition: 0.4s;
    background-color: rgb(43, 187, 223);
    color: #fff;
}

.search-div a button:hover {
    background-color: rgb(0, 208, 255);
}

@media (max-width: 1105px) {
    .info-img {
        display: none;
    }
}
<!DOCTYPE html>
<html lang="pt-BR">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SITE VIAGEM</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <header>
        <nav class="nav-list">
            <a class="logo">TravelWorld</a>
            <ul>
                <li><a href="#">Início</a></li>
                <li><a href="#">Sobre nós</a></li>
                <li><a href="#">Pacotes</a></li>
                <li><a href="#">Contato</a></li>
            </ul>
        </nav>

    </header>
    <div class="info-2">
        <img src="2.png" class="info-img">
    </div>
    <div class="info-1">
        <h1>As melhores viagens estão aqui</h1>
        <p>O melhor preço e os melhores pacotes, TravelWorld sempre fazendo o melhor para você!</p>
        <a href="#"><button class="info-btn">Saiba Mais</button></a>
    </div>

    <div class="imgs-travel">
        <div class="img1">
            <img src="losangeles.jpg" class="la">
            <h3>Los Angeles</h3>
        </div>
        <div class="img2">
            <img src="paris.jpg" class="paris">
            <h3>Paris</h3>
        </div>
        <div class="img3">
            <img src="rj.jpg" class="rj">
            <h3>Rio de Janeiro</h3>
        </div>
        <div class="img4">
            <img src="miami.jpg" class="miami">
            <h3>Miami</h3>
        </div>
    </div>

    <div class="search-div">
            <h1 class="search-h1">Escolha seu destino e planeje sua viagem!</h1>
            <input type="text" placeholder=" Digite o país, estado ou cidade..." class="search">
            <a href="#"><button>Buscar</button></a>
        
    </div>

    <br>
    <br>
    <br>
    <br>
    <br>
    <br>




</body>

</html>

1 Resposta 1

0

Coloquei text-align nos divs das imagens para alinhar horizontalmente.

.imgs-travel div { text-align: center; }

Para a parte vertical, eu mudei o css dos h3 de:

 .imgs-travel h3 { top: -50%; }

Para:

.imgs-travel h3 { top: -60%; }
2
  • Deu certinho, muito obrigado! Você poderia só me explicar por que fui usado o top -60% ao invés do -50% por favor?
    – pedrolgr
    11/05/2021 às 19:50
  • @pedrolgr Eu tentei várias porcentagens e essa foi a que achei mais centralizada... Deve ter outras formas de alinhar verticalmente, mas pelo seu código mudei o que eu achei mais fácil, e que eu sei, então falei.
    – Jocowski
    12/05/2021 às 22:04

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 .