/*General*/
@import url('https://fonts.googleapis.com/css?family=Oxygen');

.wrapper {
    max-width: 630px;
    margin: 0 auto;
}

/*Header*/
#header .navbar .navbar-header a {
    color: white;
    font-size: 25px;
    font-family: 'Oxygen', sans-serif;
}
#header .navbar-inverse {
    background-color: #2C3E50;
    border-color: #2C3E50;
}
#header .navbar {
    border-radius: 0;
}
#header .navbar-nav > li > a {
    color:white;
}
#header .navbar {
    margin-bottom: 0;
}
.nav.navbar-nav.navbar-right li a {
    color: white;
}

/*Content*/
#content .content-content .responsive-image {
    width: 100%;
    background-size: 100% 100%;
    z-index:0;
}
#content .content-content h1 {
    font-family: 'Open Sans', sans-serif;
    color: #2c3e50;
    font-size: 50px;
    font-weight: bold;
    z-index: 2;
    text-align: center;
}

/*Footer*/

/*Responsiveness*/

/*Desktop*/
@media screen and (min-width: 992px)
{
    #content .content-content .responsive-image {
        background-image: url('https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg');
    }
}

/*Tablet*/
@media screen and (min-width: 768px) and (max-width: 991px)
{
    #content .content-content .responsive-image {
        background-image: url('https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg');
    }
}

/*Mobile*/
@media screen and (max-width: 767px)
{
    #content .content-content .responsive-image {
        background-image: url('https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg');
    }
}

/*Custom*/
@media screen and (max-width: 574px)
{
    #content .content-content .responsive-image {
        background-image: url('https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg');height:250px;
    }
}
<!DOCTYPE html>
<html>
<head>
    <title>Magic Gate</title>
    <link rel="stylesheet" type="text/css" href="Custom.css">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
    <div id="header">
        <nav class="navbar navbar-inverse">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">Magic Gate</a>
                </div>
                <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="#">Play</a>
                        </li>
                        <li>
                            <a href="#">Log Out</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div id="content">
        <div class="content-content">
            <img src="https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg" class="responsive-image">
            <div class="wrapper">
                <h1>Welcome to Magic Gate</h1>
            </div>
        </div>
    </div>
    <div id="footer">
    </div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</html>

No quiero utilizar el posicionamiento absoluto porque interrumpe el centrado de los objetos / controles en el centro del banner. ¿Me pueden ayudar con esto sin cambiar también el img a un fondo div a menos que sea receptivo, ya que todo es receptivo? Mi objetivo es centrar el texto h1 en el medio del banner.

0
J.Doe 13 nov. 2017 a las 16:54

2 respuestas

La mejor respuesta

Puede usar display:flex en css. Solo estoy publicando un ejemplo de cómo obtenerlo.

Usar debajo de la parte css

.content-content {
  position:relative;
}

.wrapper {
    max-width: 630px;
    margin: 0 auto;
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    top: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
}

Violín de trabajo

0
LKG 13 nov. 2017 a las 14:34

Aquí, como preguntas, agrego position:relative; top:-250px; a h1. Pero es una práctica desagradable y un código realmente malo. position:absolute; y transform:transle() mucho más mejor

/*General*/
@import url('https://fonts.googleapis.com/css?family=Oxygen');
.wrapper {
    max-width: 630px;
    margin: 0 auto;
}


/*Header*/
#header .navbar .navbar-header a{color: white;font-size: 25px;font-family: 'Oxygen', sans-serif;}
#header .navbar-inverse {background-color: #2C3E50;border-color: #2C3E50;}
#header .navbar {border-radius: 0;}
#header .navbar-nav > li > a {color:white;}
#header .navbar {margin-bottom: 0;}
.nav.navbar-nav.navbar-right li a {color: white;}




/*Content*/

#content .content-content .responsive-image{width: 100%;background-size: 100% 100%;z-index:0;}
#content .content-content h1{font-family: 'Open Sans', sans-serif;color: #2c3e50;font-size: 50px;font-weight: bold;z-index: 2;text-align: center;position:relative;top:-250px;}


/*Footer*/

/*Responsiveness*/

/*Desktop*/
@media screen and (min-width: 992px)
{
#content .content-content .responsive-image{background-image: url('https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg');}
}

/*Tablet*/
@media screen and (min-width: 768px) and (max-width: 991px)
{
#content .content-content .responsive-image{background-image: url('https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg');}
}

/*Mobile*/
@media screen and (max-width: 767px) 
{
#content .content-content .responsive-image{background-image: url('https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg');}
}

/*Custom*/
@media screen and (max-width: 574px) 
{
#content .content-content .responsive-image{background-image: url('https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg');height:250px;}
}
<!DOCTYPE html>
<html>
<head>
	<title>Magic Gate</title>
	<link rel="stylesheet" type="text/css" href="Custom.css">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
	<div id="header">
		<nav class="navbar navbar-inverse">
			<div class="container-fluid">
			    <div class="navbar-header">
				    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
				       	<span class="icon-bar"></span>
				        <span class="icon-bar"></span>
				        <span class="icon-bar"></span>
				    </button>
				    <a class="navbar-brand" href="#">Magic Gate</a>
			    </div>
			    <div class="collapse navbar-collapse" id="myNavbar">
			    	<ul class="nav navbar-nav navbar-right">
				        <li><a href="#">Play</a></li>
				        <li><a href="#">Log Out</a></li>
			      	</ul>
			    </div>
			</div>
		</nav>
	</div>
	<div id="content">
		<div class="content-content">
			<img src="https://wallpaperscraft.com/image/board_black_line_texture_background_wood_55220_1920x1080.jpg" class="responsive-image">
			<div class="wrapper">
				<h1>Welcome to Magic Gate</h1>
			</div>
		</div>
	</div>
	<div id="footer">
	</div>
</body>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
 	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</html>
1
Andre Ramadhan 13 nov. 2017 a las 14:14