1

I have some tabs on site and they get wide and move out of the media scren when using display flex, or inline-block, I want, the first one stay as its and the rest of them toggle in a dropdown on media screen.

@media screen and (max-width: 500px) {
}

I searched a lot, most examples are with third party libraries like bootstrap etc. Tried this one with no luck to make it work how to make responsive tabs to drop down in mobile view

I use jquery and pure css, But no clue where and how to start. any help will be good Thanks.

My codes :

$(document).ready(function(){
    
    $('ul.tabs li').click(function(){
        var tab_id = $(this).attr('data-tab');

        $('ul.tabs li').removeClass('current');
        $('.tab-content').removeClass('current');

        $(this).addClass('current');
        $("#"+tab_id).addClass('current');
    })

})
body{
            margin-top: 100px;
            font-family: 'Trebuchet MS', serif;
            line-height: 1.6
        }
        .container{
            width: 800px;
            margin: 0 auto;
        }



        ul.tabs{
            margin: 0px;
            padding: 0px;
            list-style: none;
            border-bottom: 2px solid #e44e4e;
        }
        ul.tabs li{
            color: #222;
            display: inline-block;
            padding: 10px 15px;
            cursor: pointer;
        }

        ul.tabs li.current{
            background-color: #e44e4e;
            color: #fff;
        }

        ul.tabs li:last-child{
            float: right;
        }

        .tab-content{
            display: none;
            background: #fff;
            padding: 15px;
        }

        .tab-content.current{
            display: inherit;
        }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">

    <ul class="tabs">
        <li class="tab-link current" data-tab="tab-1">Tab One</li>
        <li class="tab-link" data-tab="tab-2">Tab Two</li>
        <li class="tab-link" data-tab="tab-3">Tab Three</li>
        <li class="tab-link" data-tab="tab-4">Tab Four</li>
    <li class="tab-link"><a href="test">View All</a></li>
    </ul>

    <div id="tab-1" class="tab-content current">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    </div>
    <div id="tab-2" class="tab-content">
         Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div>
    <div id="tab-3" class="tab-content">
        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
    </div>
    <div id="tab-4" class="tab-content">
        Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    </div>

</div><!-- container -->
DLK
  • 161
  • 8
  • You specified a fixed `width` of 800px, so the content will eventually overflow once the screen is too small to fit the container. Use `max-width: 800px` instead. As for the dropdown menu, I suggest you make a nested `
      ` with the same `
    • `-elements that has matching classnames inside the first `
    – Sigurd Mazanti Jun 14 '22 at 16:05

1 Answers1

0

You can use bootstrap navbar Bootstrap dropdown navbar for mobile view

Mitul
  • 42
  • 6