LoginSignup
jankenpon0205
@jankenpon0205 (002 ruru)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

メインビジュアルの画像を横幅いっぱいに表示したい。(スライドショーあり)

解決したいこと

3枚の画像をスライドショーを実装したのですが、横幅いっぱいにならず、左に寄ってしまいました。positionの設定をしてみたのですが、absoluteだとが画面いっぱいに広がるのですが、ヘッダーに被ってしまいます。ヘッダーに被らず、メインビジュアルが画面いっぱいになるようにするにはどうすれば良いでしょうか?

HTML

<body>
    <header>
        <div class="navigation">
        <div class="header-logo"><img src="./images/logo/icon.png" class="logo"></div>
        <nav class="g-navi">
            <div class="container nav-wrapper">
                <ul>
                    <li class="nav-item"><a href="#concept">コンセプト</a></li>
                    <li class="nav-item"><a href="#specialty">こだわり</a></li>
                    <li class="nav-item"><a href="#menu">お品書き</a></li>
                    <li class="nav-item"><a href="#store">店舗情報</a></li>
                </ul>
            </div>
        </nav>
        </div>

        <div class="g-navi-sp">
            <div class="menu-trigger">
                <span></span>
                <span></span>
                <span></span>
            </div>
        </div>
    </header>

    <section id="main-visual">
        <div class="container slider">
            <ul class="items">
            <li class="item current">
                <img class="item-img" src="images/mv/mv1.jpg">
            </li>
            <li class="item">
                <img class="item-img" src="images/mv/mv2.jpg">
            </li>
            <li class="item">
                <img class="item-img" src="images/mv/mv3.jpg">
            </li>
            </ul>
        </div>
    </section>
</body>

CSS

body{
    font-family: 'Yu Mincho';
    font-size: 20px;
}

header{
    height: 100px;
    background: #e1f3e8;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
    line-height: 1;
}

.navigation{
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    flex-wrap: nowrap;
    padding-left: 170px;
    padding-right: 170px;
}

header .header-logo{
    display: inline-block;
    left: 0;
    padding-top: 10px;
    padding-bottom: 10px;
}



header .g-navi ul{
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-around;
}

.g-navi ul li{
    text-align: center;
}

.g-navi ul li:nth-child(1){
    padding-right: 60px;
}

.g-navi ul li:nth-child(2){
    padding-right: 60px;
}

.g-navi ul li:nth-child(3){
    padding-right: 60px;
}

.g-navi ul li a{
    display: block;
    color: #000;
}
.logo{
    width:47%;
    /* padding-top: 10px;
    padding-bottom: 10px; */
}

#main-visual{
    height: 100vh;
    /* height: calc(var(--vh, 1vh) * 100); */
    width: 100%;
    background-repeat: no-repeat;
}

.slider{
    width: 100%;
    position: relative;
}

.items{
    /* position: relative; */
    overflow: hidden;
    width: 100%;
    height: 100vh;
}

.item{
position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  opacity: 0;
  transition: opacity .6s ease-in-out;
  
}

.item-img{
    width: 100%;
    height: 100vh;
    object-fit: cover;
  }

.current{
    opacity: 1;
}

@media screen and (max-width:600px){
.container{
        overflow: hidden;
    }
    header{
        display: flex;
        justify-content: space-between;
        height: 70px;
        position: sticky;
    }
    .navigation{
        /* justify-content: space-between; */
        /* display: flex; */
        align-items: center;
        padding-left: 15px;
        padding-right: initial;
        display: block;
    }
    .g-navi{
        display: flex;
        position: fixed;
        z-index: 2;
        /* padding-top: 60px; */
        transform: translateY(-100%);
        transition: .5s ease-in-out;
        height: 100vh;
        width: 100%;
        /* padding-left: 15px; */
    }
    .g-navi ul{
        display: block;
        flex-flow: column;
    }
    .g-navi.active{
        transform: translate(-3.2%, 0.1%);
        transition: .5s ease-in-out;
        background: rgba(56,56, 56,0.6);
    }
    header .g-navi ul li a{
        font-size: 20px;
        color: #fff;
        padding-top: 40px;
    }
    .g-navi ul li{
        display: block;
        width: 100%;
    }
    .g-navi ul li:nth-child(1){
        padding-right: initial;
    }
    .g-navi ul li:nth-child(2){
        padding-right: initial;
    }
    .g-navi ul li:nth-child(3){
        padding-right: initial;
    }
    .g-navi-sp{
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 70px;
        z-index: 3;
        padding-right: 15px;
    }
    header .header-logo{
        align-items: center;
        padding-top: 5px;
        padding-bottom: 5px;
        width: 68%;
    }
    .menu-trigger{
        position: relative;
        width: 50px;
        height: 50px;
        cursor: pointer;
        background-color: #628f6d;
        border-radius: 5px;
        overflow: scroll;
    }
    .menu-trigger span{
        display: block;
        position: absolute;
        width: 30px;
        border-bottom: solid 1px #fff;
        border-radius: 5px;
        transition: .35s ease-in-out;
    }
    .menu-trigger span:nth-child(1){
        top: 10px;
        left:10px
    }
    .menu-trigger span:nth-child(2){
        top: 22px;
        left: 10px;
    }
    .menu-trigger span:nth-child(3){
        top: 34px;
        left: 10px;
    }
    .menu-trigger.active span:nth-child(1){
        top: 22px;
        transform: rotate(-45deg);
    }
    .menu-trigger.active span:nth-child(2),
    .menu-trigger.active span:nth-child(3){
        top: 22px;
        transform: rotate(45deg);
    }
#main-visual{
        height: 35vh;
        max-height: inherit;
    }
    .item-img{
        height: 35vh;
        /* padding-left: 15px;
        padding-right: 15px; */
        overflow: hidden;
    }
}

JS

function slider(){
    var current = $('.item.current'),
        next = current.is(':last-child') ? $('.item').first() : current.next();
    next.addClass('current');
    current.removeClass('current');
  }
  var setSlider = setInterval( slider, 3000);

例)

def greet
  puts Hello World
end

自分で試したこと

https://codeisle.info/blog/57/
上記のURLをもとに構築したのですが、余白が生まれてしまいました。また、画像のスライドショーを3秒間隔にしたいのですが、JSの記載で問題ないでしょうか?
よろしくお願いいたします。

0

1Answer

JSの回答をさせていただきます。
画像のスライドショーを3秒間隔にするコードは合っております。
ミリ秒で指定をしているため、1000ミリ秒=1秒となります。

画像の位置などについては、仕事の片手間にやってみますが、期待しないでください。

追記)
Chromeの検証ツールを使用した結果、余計なMarginなどが入っていそうです。
何が原因なのかなど、調査するのも経験となりますので、ここまでの回答とさせていただきます。

0Like

Comments

  1. @jankenpon0205

    Questioner

    お忙しい時間回答して頂き誠にありがとうございます。
    解決しました!

Your answer might help someone💌