0

I want to make my responsive tabs to drop down like this

Desktop/Large Screen View enter image description here

Mobile View enter image description here

This is what code i have and I don't know if this is can be done using CSS only or need Javascript/jQuery.

<div class="bottomRight">
    <input type="radio" id="popularUpload" name="upload" checked="checked">
    <label for="popularUpload" class="popularUpload">Popular Uploads</label>
    <input type="radio" id="recentUpload" name="upload">
    <label for="recentUpload" class="recentUpload">Recent Uploads</label>
    <input type="radio" id="gallery" name="upload">
    <label for="gallery" class="gallery">Gallery</label>
        <div class="popUploadContent">...</div>
        <div class="recUploadContent">...</div>
        <div class="galleryContent">...</div>
</div>

And here is my CSS code.

#popularUpload,
#recentUpload,
#gallery {
    display: none;
}

.popularUpload {
    font-size: 15px;
    font-weight: bold;
    color: #dddfe2;
    background: #111625;
    padding: 20px 4%;
    position: relative;
    cursor: pointer;
    z-index: 500;
    display: block;
    width: 120px;
    text-align: center;
    float: left;
}

.recentUpload {
    float: left;
    font-size: 15px;
    font-weight: bold;
    color: #dddfe2;
    background: #111625;
    padding: 20px 4%;
    position: relative;
    cursor: pointer;
    z-index: 500;
    display: block;
    width: 110px;
    text-align: center;
    border-right: 1px solid #0b0e18;
    border-left: 1px solid #0b0e18;
}

.gallery {
    float: left;
    font-size: 15px;
    font-weight: bold;
    color: #dddfe2;
    background: #111625;
    padding: 20px 4%;
    position: relative;
    cursor: pointer;
    z-index: 500;
    display: block;
    width: 60px;
    text-align: center;
}

.popularUpload:hover,
.recentUpload:hover,
.gallery:hover {
    color: #eeb10c;
    transition: all .5s ease;
}

#popularUpload:checked + label,
#recentUpload:checked + label,
#gallery:checked + label {
    background: #0b0f17;
    color: #eeb10c;
    transition: all .5s ease;
}

#popularUpload:checked ~ .popUploadContent,
#recentUpload:checked ~ .recUploadContent,
#gallery:checked ~ .galleryContent {
    visibility: visible;
    transition: all .3s ease;
}

.popUploadContent,
.recUploadContent,
.galleryContent {
    visibility: hidden;
    background: #0b0f17;
    position: absolute;
    margin-top: 54px;
    height: 299px;
}

.popUploadContentLeft,
.recUploadContentLeft,
.galleryContentLeft {
    float: left;
    width: 46.4%;
    margin-left: 2.5%;
    margin-top: 19px;
}

Or if you can suggest and edit my code, that will be better. Here is my JSFiddle https://jsfiddle.net/8druLycp/

nyjn24
  • 106
  • 1
  • 13

2 Answers2

2

You can use Bootstrap tabs : http://getbootstrap.com/javascript/#tabs. (Using javascript and jQuery), then personnalize it with CSS ?

EDIT 1

To make it responsive without using the solution above, still use Boostrap with its system of grid (e.g. col-md-3 col-sm-4 col-xs-12). So when it will be a small screen, each part of your tabs menu will take the full width. Check it out https://getbootstrap.com/examples/grid/

EDIT 2

An other solution and all I can suggest you for now and that works is to applicate this : http://tabcollapse.okendoken.com. See the demo : http://tabcollapse.okendoken.com/example/example.html

EDIT 3

Finally, here is a solution with the dropdown menu : https://jsfiddle.net/Alteyss/wypp0hz8/ :

div#tabsBlock > ul.nav-tabs > li.dropdown {
    display: none;
}

@media screen and (max-width: 500px) {
    div#tabsBlock > ul.nav-tabs > li.lg {
        display: none;
    }
    div#tabsBlock > ul.nav-tabs > li.dropdown {
        display: block;
    }
}

I've set a limit (500px that you can change) so when it's under 500px width, the dropdown appears and the other tabs disappear. Then, you can personnalize it as you want in css in your web site ;)

(With pills : https://jsfiddle.net/Alteyss/wypp0hz8/5/)

Alteyss
  • 513
  • 3
  • 17
0

I think a possible solution to you is to hide not selected tabs and give all of them a 100% width. Then you can add a class to control its display, this class can be toggled with very simple jQuery.

I show you an example on the snnipet. The only thing left is to control the active tab to show its label when is selected and use a caret to control the class toggle instead of the label.

To apply this to the mobile version only, just add it with a media-query.

$(function(){
 $('.popularUpload').on('click', function(){
  $('.recentUpload').toggleClass('shown');
  $('.gallery').toggleClass('shown');
 });
});
#popularUpload,
#recentUpload,
#gallery {
 display: none;
}

.popularUpload {
 font-size: 15px;
 font-weight: bold;
 color: #dddfe2;
 background: #111625;
 padding: 20px 4%;
 cursor: pointer;
 z-index: 500;
 display: none;
 width: 100%;
 text-align: center;
 float: left;
}

.popularUpload.shown{
    display: block;
}

.recentUpload {
    display: none;
 float: left;
 font-size: 15px;
 font-weight: bold;
 color: #dddfe2;
 background: #111625;
 padding: 20px 4%;
 cursor: pointer;
 z-index: 500;
 width: 100%;
 text-align: center;
 border-right: 1px solid #0b0e18;
 border-left: 1px solid #0b0e18;
}

.recentUpload.shown{
    display: block;
}

.gallery {
    display: none;
 float: left;
 font-size: 15px;
 font-weight: bold;
 color: #dddfe2;
 background: #111625;
 padding: 20px 4%;
 cursor: pointer;
 z-index: 500;
 width: 100%;
 text-align: center;
}

.gallery.shown {
    display: block;
}

.popularUpload:hover,
.recentUpload:hover,
.gallery:hover {
 color: #eeb10c;
 transition: all .5s ease;
}

#popularUpload:checked + label,
#recentUpload:checked + label,
#gallery:checked + label {
 background: #0b0f17;
 color: #eeb10c;
 transition: all .5s ease;
}

#popularUpload:checked ~ .popUploadContent,
#recentUpload:checked ~ .recUploadContent,
#gallery:checked ~ .galleryContent {
    display: block;
 transition: all .3s ease;
}

.popUploadContent,
.recUploadContent,
.galleryContent {
    display: none;
 background: #0b0f17;
 height: 299px;
    width: 100%;
    color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="bottomRight">
    <input type="radio" id="popularUpload" name="upload" checked="checked">
    <label for="popularUpload" class="popularUpload shown">Popular Uploads</label>
    <input type="radio" id="recentUpload" name="upload">
    <label for="recentUpload" class="recentUpload">Recent Uploads</label>
    <input type="radio" id="gallery" name="upload">
    <label for="gallery" class="gallery">Gallery</label>
        <div class="popUploadContent">popular content</div>
        <div class="recUploadContent">recent content</div>
        <div class="galleryContent">gallery content</div>
</div>
Adrian Menendez
  • 480
  • 4
  • 12
  • this is awesome sir! but i want that jQuery run only in less than 640px width, you think you can edit it? – nyjn24 Nov 23 '15 at 12:26
  • There are a lot of ways to do that. I'll give you some links that discuss that and a stackoverflow question that explore it too. [William.com](http://www.wiliam.com.au/wiliam-blog/jquery-and-css-media-queries), [FourFront](https://www.fourfront.us/blog/jquery-window-width-and-media-queries) and [StackOverflow](http://stackoverflow.com/questions/19291873/window-width-not-the-same-as-media-query) – Adrian Menendez Nov 23 '15 at 16:44