Creating responsive tabs that transition into a drop-down menu for mobile devices is a useful feature for

I am looking to create a responsive tab design that drops down like the example shown below:

Desktop/Large Screen View https://i.stack.imgur.com/hiCYz.png

Mobile View https://i.stack.imgur.com/gRxLv.png

I have written some code for this, but I am unsure if it can be achieved using just CSS or if it requires 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>

Below is my CSS code:

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

.popularUpload {
    /* Styles here */
}
/* More CSS styles */

.galleryContentLeft {
    /* Styles here */
}

If you have any suggestions on how to improve or edit my code, please feel free to provide them. You can view the complete code on JSFiddle here.

Answer №1

If you want to create a tabbed interface using Bootstrap, you can refer to this link: http://getbootstrap.com/javascript/#tabs. This involves using JavaScript and jQuery, which you can then customize with CSS.

UPDATE 1

To ensure that your tabs are responsive without relying on the previous solution, you can still utilize Bootstrap's grid system (e.g., col-md-3 col-sm-4 col-xs-12). This way, when viewed on smaller screens, each tab menu item will take up the entire width. You can learn more about this by checking out https://getbootstrap.com/examples/grid/.

UPDATE 2

Another effective solution I recommend is implementing this approach: . Feel free to explore the demo provided here:

UPDATE 3

Lastly, if you prefer a dropdown menu option, consider trying this solution: https://jsfiddle.net/Alteyss/wypp0hz8/. In this case, I've included some CSS code snippets to control how the tabs behave at different screen sizes.

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 specified a limit of 500px for the dropdown to appear and other tabs to hide. Feel free to further customize it according to your website's design preferences in CSS ;)

(You can also explore the "With pills" version here: https://jsfiddle.net/Alteyss/wypp0hz8/5/)

Answer №2

In my opinion, a potential solution for your issue could be to hide the tabs that are not selected and give all of them a width of 100%. You can then assign a class to control their display, which can be easily toggled using jQuery.

I have provided an example in the snippet below. The next step would be to manage the active tab to display its label when selected and use a caret to toggle the class instead of the label.

To apply this only to the mobile version, you can add it within 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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Comparing obj.hasOwnProperty(key) with directly accessing obj[key]

Consider the scenario where I need to determine if a property exists within an Object. A comparison between two methods caught my attention: if(object.hasOwnProperty(key)) { /* perform this action */ } OR if(object[key]) { /* perform this action */ ...

Having trouble with sending information to the PHP server, unable to determine the root cause

Can someone help me figure out why the data from a form being sent to a php script for sending an email isn't working correctly? It's part of a template code but I suspect there might be an error. Specifically, I believe the {'userName' ...

Continuously monitor the condition in my function

I'm encountering an issue with my jQuery function where it animates a progress bar from 0 to 100 when it's visible on the screen. The problem arises when the progress bar is not initially visible upon page load, as the animation will never trigge ...

Error with YouTube API in Internet Explorer 8: Video not found

While using the iframe youtube api to handle video, everything runs smoothly on Chrome and Firefox. However, when trying to implement it on Internet Explorer 8, an error saying 'video' is undefined pops up. Any suggestions on how to resolve this ...

Navigating the world of updating problems with Express.js

Currently, I am working on a MEAN stack project and facing challenges with the routing for updating. Saving operations are functioning correctly. In my Angular controller, I have defined the following scope method in which staff represents the object subm ...

The animation feature in AngularJS when integrated with the easy pie chart appears to be malfunctioning

Having trouble getting the animation to work, any suggestions on how to fix it? I attempted to troubleshoot on jsfiddle but couldn't get it to work for some unknown reason. Here is the HTML code snippet: <script> var app = ang ...

How to convert jQuery data into JSON format

I am dealing with data in the following format: ID=300573&CarNo=1&Account=AAAA&AccountingDate=3%2F21%2F2013&Description=NewCar&CheckAmount=666666&ClearedAmount=-3446.5&ClearedDate=4%2F9%2F2013&Sent=S&SentDate=4%2F4%2F20 ...

Tips on transforming a JSON file into a response for my personal server

After successfully converting an Excel file to JSON format using my code, I encountered a challenge when trying to convert this as a response. Despite attempting to use res.send in the JS code, it only displayed directory/inner codes instead of a response. ...

Trigger form submission with validation using jQuery

How can I redirect a user to another page named "free.php" from the index page without changing the URL, using jQuery? Below is an example I have created: http://jsfiddle.net/jKHQe/ The checkbox validation works in the example, but I am unable to redir ...

How can an array of file paths be transformed into a tree structure?

I am looking to transform a list of file and folder paths into a tree object structure (an array of objects where the children points to the array itself): type TreeItem<T> = { title: T key: T type: 'tree' | 'blob' childr ...

Choose all or none of the items from the list with a single click - v-list-item-group

I am interested in incorporating Vuetify's v-list-item-group component into my Vue application. This list is intended to represent nodes that are related to a graph, allowing users to select none, some, or all of them and delete the selected nodes. T ...

Azure experiencing issue with MUI Datepicker where selected date is shifted by one day

I have developed a unique custom date selection component that utilizes Material UI and Formik. This component passes the selected date value to a parent form component in the following manner: import React from 'react'; import { useField } from ...

What is the best way to use PHP in order to retrieve the element containing the visit ID from the specific row within an HTML table?

I am working on a project that involves populating an HTML table with data from a database. The table includes an approval button for administrators to approve visits and change their status to APPROVED. I am trying to figure out how to select the element ...

The loading of the module from was hindered due to an invalid MIME type restriction

Exploring a three.js example and encountering an issue when utilizing import within a JavaScript module. The error message displayed is: Loading module from “http://localhost:8000/build/three.module.js” was blocked because of a disallowed MIME type ( ...

Converting multi-dimensional array into a structured table format

Query about arrays: Here is the array structure I am working with: Array ( [0] => Array ( [0] => Project [1] => Time ) [1] => Array ( [0] => Google [1] => 2 ...

Strategies for improving the efficiency of HTML and styles in a generated document

Generating the invoice printing form layout using dynamically created Razor views through RazorEngine can result in messy and hard-to-read code. The repetitive use of words like top, left, width, and height makes it challenging for human inspection and deb ...

Incorporating the unshift method in JavaScript: A Step-by-

I'm looking to create a new function with the following requirements: Function add(arr,...newVal){ } array = [1,2,3]; add(array,0) console.log(array); //I want this to output [0,1,2,3] I tried creating the function similar to push like this: ...

Adjustable width (100%) and set height for SVG

I am attempting to insert an SVG object onto my HTML page with a width of 100% and a fixed height. Upon viewing my fiddle, you will notice that the height of the dark-grey object changes based on the window proportions, which is not the desired outcome. ...

Issue with material table not showing data

Problem I've been working on integrating a material design table into my project, but I'm running into an issue where the data isn't showing up. I followed the example provided here but all I see is a single vertical line on the page: Upon ...

In search of a new object value to update

Looking to update the value of a specific object key in an array? Here is the code snippet where I want to make this change. I only want to replace the value under Mon, not the entire array length. The key weekday will be provided dynamically. array = [ ...