Position caption above div

7

I'm using the bootstrap carousel with caption. Between the slide image and the caption there is a div with the image of an orange triangle. I need the caption to stay above the triangle. I have already used z-index but I can not position this caption up front.

HTML:

<!DOCTYPEhtml><htmllang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@yield('title')</title>

<!-- Styles -->
<link href="{{ asset('assets/css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('assets/css/style.css') }}" rel="stylesheet">

</head>
<body>
<header>    
    <img class="triangulo" src="{{ asset('storage/triangulo.png') }}">
    <div class="container">
        <nav class="navbar navbar-default navbar-fixed-top">
            <div class="container">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <img class="img-responsive logo" src="{{ asset('storage/logo.png') }}">
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#">A Powerzone</a></li>
                        <li><a href="#">Crosszone</a></li>
                        <li><a href="#">Modalidades</a></li>
                        <li><a href="#">Horários</a></li>
                        <li><a href="#">Contato</a></li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
    </div>
</header>
<main>
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
        <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
        <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
        <div class="item active">
            <div class="carousel-caption">
                <div class="container-caption">
                    <h1>Crossfit 1</h1>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                    <button class="btn btn-primary">Saiba mais</button>
                </div>
            </div>
        </div>
        <div class="item">
            <div class="carousel-caption">
                <div class="container-caption">
                    <h1>Crossfit 2</h1>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                    <button class="btn btn-primary">Saiba mais</button>
                </div>
            </div>
        </div>
    </div>
    </div>
</main>
<footer>

</footer>
<script src="{{ asset('assets/js/jquery.min.js') }}"></script>
<script src="{{ asset('assets/js/bootstrap.min.js') }}"></script>
</body>
</html>

CSS:

.triangulo {
position: absolute;
top: 0;
left: 0;
z-index: 10;
width: 80%;
height: 90%;
opacity: 0.85;
}

.logo {
max-width: 75%;
}

@media (min-width: 768px) {
.triangulo {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    width: 95%;
    height: auto;
    opacity: 0.85;
}

.logo {
    max-width: 100%;
}
}

/*=============Menu=============*/

.navbar-default {
border: none;
background-color: transparent;
z-index: 20;
}

.navbar-default .navbar-nav>li>a {
color: #ffffff;
text-transform: uppercase;
}

.navbar-right {
margin-top: 2%;
}

.navbar-toggle {
border: none;
}

.navbar-default .navbar-toggle .icon-bar {
background-color: #D6521E;
width: 25px;
height: 3px;
}

.navbar-default .navbar-toggle:focus, .navbar-default .navbar-toggle:hover {
background-color: transparent;
}

.navbar-default .navbar-collapse, .navbar-default .navbar-form {
background-color: #000000;
}

@media (min-width: 768px) {
.navbar-default .navbar-collapse, .navbar-default .navbar-form {
    background-color: transparent;
}
}

/*=============Slide=============*/

.carousel-inner {
height: 500px;
}

@media (min-width: 768px) {
.carousel-inner {
    height: 780px;
}
}

.item {
width: 100%;
height: 100%;
}

.item:nth-child(1) {
background: url("../../storage/img1.jpg") no-repeat center center;  
background-size: cover;
}

.item:nth-child(2) {
background: url("../../storage/img1.jpg") no-repeat center center;  
background-size: cover;
}

@media (min-width: 768px) {
.item:nth-child(1) {
    background: url("../../storage/img1.jpg") no-repeat center center;  
    background-size: 1920px 780px;
}

.item:nth-child(2) {
    background: url("../../storage/img1.jpg") no-repeat center center;  
    background-size: 1920px 780px;
}
}

.carousel-caption {
    top: 30%;
    z-index: 20 !important;
}

@media (min-width: 768px) {
.container-caption {
    width: 30%; 
    height: 100%;
}

.carousel-caption h1 {
    text-align: left;
}

.carousel-caption p {
    text-align: left;
}

.carousel-caption button {
    margin-left: -74%;
}
}

Full project: link

    
asked by anonymous 22.06.2017 / 23:22

3 answers

4

I made an example that is working, I used jQuery to do a trick and meet the need since the conventional methods of z-index do not work, it is not the most elegant, but it works.

See the image below:

Followthelinktothesources:

link

See if you can!

Below is the CSS code:

#exibirCap {
    top: 30%;
    left: 15%;
    width: 550px;
    position: absolute;
    z-index: 100000;
}

.triangulo {
    position: absolute;
    top: 0;
    left: 0;
    width: 80%;
    z-index: 10;
    height: 90%;
    opacity: 0.85;
}

.logo {
    max-width: 75%;
}

@media (min-width: 768px) {
.triangulo {
    position: absolute;
    top: 0;
    left: 0;
    width: 95%;
    height: auto;
    opacity: 0.85;
}

.logo {
    max-width: 100%;
}
}

/*=============Menu=============*/

.navbar-default {
    border: none;
    background-color: transparent;
}

.navbar-default .navbar-nav>li>a {
    color: #ffffff;
    text-transform: uppercase;
}

.navbar-right {
    margin-top: 2%;
}

.navbar-toggle {
    border: none;
}

.navbar-default .navbar-toggle .icon-bar {
    background-color: #D6521E;
    width: 25px;
    height: 3px;
}

.navbar-default .navbar-toggle:focus, .navbar-default .navbar-toggle:hover {
    background-color: transparent;
}

.navbar-default .navbar-collapse, .navbar-default .navbar-form {
    background-color: #000000;
}

@media (min-width: 768px) {
.navbar-default .navbar-collapse, .navbar-default .navbar-form {
    background-color: transparent;
}
}

/*=============Slide=============*/

.carousel-inner {
    height: 500px;
}

@media (min-width: 768px) {
    .carousel-inner {
    height: 780px;
}
}

.item {
    width: 100%;
    height: 100%;
}

.item {
    /*background: url('../img/img1.jpg') no-repeat center center;  
    background-size: cover;*/
}

.item:nth-child(2) {
    /*background: url('../img/img1.jpg') no-repeat center center;  
    background-size: cover;*/
}

@media (min-width: 768px) {
    .item {
    /*background: url('../img/img1.jpg') no-repeat center center;  
    background-size: 1920px 780px;*/
}

.item:nth-child(2) {
   /* background: url('../img/img1.jpg') no-repeat center center;  
    background-size: 1920px 780px;*/
}
}

.carousel-caption {
    top: 30%;
}

@media (min-width: 768px) {
.container-caption {
    width: 30%; 
    height: 100%;
}

.carousel-caption h1 {
    text-align: left;
}

.carousel-caption p {
    text-align: left;
}

.carousel-caption button {
    margin-left: -74%;
}
}

And how did the HTML file

<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">

</head>
<body>
    <header>    
        <img class="triangulo" src="img/triangulo.png">
        <div class="container">
            <nav class="navbar navbar-default navbar-fixed-top">
                <div class="container">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <img class="img-responsive logo" src="img/logo.png">
                    </div>

                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav navbar-right">
                            <li><a href="#">A Powerzone</a></li>
                            <li><a href="#">Crosszone</a></li>
                            <li><a href="#">Modalidades</a></li>
                            <li><a href="#">Horários</a></li>
                            <li><a href="#">Contato</a></li>
                        </ul>
                    </div><!-- /.navbar-collapse -->
                </div><!-- /.container-fluid -->
            </nav>
        </div>
    </header>
    <main>
        <div id="exibirCap">
        </div>
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
            <ol class="carousel-indicators">
                <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
                <li data-target="#carousel-example-generic" data-slide-to="1"></li>
            </ol>
            <div class="carousel-inner" role="listbox">
                <div class="item active">
                    <div class="carousel-caption ocultar">
                        <div class="container-caption">
                            <h1>Crossfit 1</h1>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                            <button class="btn btn-primary">Saiba mais</button>
                        </div>
                    </div>
                    <img src="img/img1.jpg">
                </div>
                <div class="item">
                    <div class="carousel-caption ocultar">
                        <div class="container-caption">
                            <h1>Crossfit 2</h1>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                            <button class="btn btn-primary">Saiba mais</button>
                        </div>
                    </div>
                    <img src="img/img1.jpg" >
                </div>
            </div>
        </div>
    </main>
    <footer>
    </footer>

    <script>
        setInterval(
            function(){
             $(".ocultar").hide();
             $('#exibirCap').html('');
             $('.active .carousel-caption .container-caption').clone().appendTo('#exibirCap');
             $('#exibirCap').show();
            }, 100);
    </script>

    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
</body>
</html>
    
26.06.2017 / 22:16
3

Try to put HTML:

<!DOCTYPE html>
    <html lang="{{ config('app.locale') }}">
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>@yield('title')</title>

    <!-- Styles -->
    <link href="{{ asset('assets/css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ asset('assets/css/style.css') }}" rel="stylesheet">

    </head>
    <body>
    <header>    
        <img class="triangulo" src="{{ asset('storage/triangulo.png') }}">
        <div class="container">
            <nav class="navbar navbar-default navbar-fixed-top">
                <div class="container">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <img class="img-responsive logo" src="{{ asset('storage/logo.png') }}">
                    </div>

                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav navbar-right">
                            <li><a href="#">A Powerzone</a></li>
                            <li><a href="#">Crosszone</a></li>
                            <li><a href="#">Modalidades</a></li>
                            <li><a href="#">Horários</a></li>
                            <li><a href="#">Contato</a></li>
                        </ul>
                    </div><!-- /.navbar-collapse -->
                </div><!-- /.container-fluid -->
            </nav>
        </div>
    </header>
<!-- Indicators -->
    <ol class="carousel-indicators">
        <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
        <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    </ol>
    <main>
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
            <li data-target="#carousel-example-generic" data-slide-to="1"></li>
        </ol>

        <!-- Wrapper for slides -->
        <div class="carousel-inner" role="listbox">
            <div class="item active">
                <div class="carousel-caption">
                    <div class="container-caption">
                        <h1>Crossfit 1</h1>
                        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                        <button class="btn btn-primary">Saiba mais</button>
                    </div>
                </div>
            </div>
            <div class="item">
                <div class="carousel-caption">
                    <div class="container-caption">
                        <h1>Crossfit 2</h1>
                        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                        <button class="btn btn-primary">Saiba mais</button>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </main>
    <footer>

    </footer>
    <script src="{{ asset('assets/js/jquery.min.js') }}"></script>
    <script src="{{ asset('assets/js/bootstrap.min.js') }}"></script>
    </body>
    </html>

I think this will work!

    
25.06.2017 / 01:26
1

I do not know if it's already been solved, but I managed to do this with some changes.

The Result:

Followthechanges:

HTML

RemovethislinefromyourHTML:

<imgclass="triangulo" src="img/triangulo.png">

CSS

Remove the following parts of your CSS:

#carousel-example-generic{
    z-index: 10000;
}

.triangulo {
    position: absolute;
    top: 0;
    left: 0;
    width: 80%;
    z-index: 9000;
    height: 90%;
    opacity: 0.85;
}

Include the following parts in your CSS:

header {
    position: relative;
    z-index: 100000;
}

.item::before {
    content: "";
    background-image: url('../img/triangulo.png');
    background-size: contain;
    background-repeat: no-repeat;
    position: absolute;
    top: 0;
    left: 0;
    width: 80%;
    z-index: 9000;
    height: 90%;
    opacity: 0.85;
}

.carousel-caption {
    z-index: 10000;
}
    
28.06.2017 / 15:41