Create an animation effect on HTML tab content to slide in and out smoothly, resembling a carousel, using

I am new to animation and looking for help with creating a carousel effect on my HTML tabs using CSS. I want the contents to slide like in this example: . Any guidance or tips on how to achieve this would be greatly appreciated.

<div class="service-tabs" >
        <ul class="nav nav-tabs">
            <li ng-class="{'active':tabSelected == 'one'}" ng-click="tabSelected = 'one'">TAB ONE</li>
            <li ng-class="{'active':tabSelected == 'two'}" ng-click="tabSelected = 'two'">TAB TWO</li>
            <li ng-class="{'active':tabSelected == 'three'}" ng-click="tabSelected = 'three'">TAB THREE</li>
        </ul>
        <div class="tab-contents">
            <div class="tab-content" ng-show="tabSelected == 'one'" ng-class=" tabSelected == 'one' ? 'active' : 'inactive'">
                <div class="flex-it risk-factors">
                   <h1>One</h1>
                   <p>Lorem dim sum Cha siu bao Lo mai gai baked barbecue pork bao Egg custard tarts Popular shumai cha siu bao A creamy mango pudding Chiu-chao</p>
                </div>
            </div>
            <div class="tab-content" ng-show="tabSelected == 'two'" ng-class=" tabSelected == 'two' ? 'active' : 'inactive' " style="width: 100%">
                 <h1>Two</h1>
                   <p>Bacon ipsum dolor amet beef ham hock salami cupim shankle kevin leberkas landjaeger ham. Prosciutto filet mignon bresaola rump. Tail ground round beef tri-tip turducken, meatloaf prosciutto short ribs filet mignon t-bone hamburger kevin pork chop. Meatball rump chicken hamburger drumstick, boudin pancetta short ribs ground round. Turkey cupim porchetta salami sausage t-bone pig. Bresaola t-bone tenderloin pork shoulder. Tongue pig corned beef...
            </div>
            <div class="tab-content" ng-show="tabSelected == 'three'" ng-class=" tabSelected == 'three' ? 'active' : 'inactive' ">
                 <h1>Three</h1>
                   <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recen...
            </div>
        </div>
    </div>

Here is the Plunker I have created so far: http://plnkr.co/edit/lImVRKBUcTH15xJm66q6?p=preview

Answer №1

Alright, here's a method to tackle this. The key is to establish the default transition-delay on the content components with an incredibly high value so they cannot revert to their original state unless prompted by user interaction through one of the tabs. Afterward, it's all about the fundamentals: sibling selectors, transitions, and positioning.

*{box-sizing:border-box;color:#000;font-family:sans-serif;font-size:14px;margin:0;outline:none;padding:0;}
body{
    margin:10px;
}
body>p{
    cursor:pointer;
    line-height:30px;
    padding:0 20px;
    display:inline-block;
}
body>p:focus{
    background:#ccc;
}
body>div{
    border:2px solid #ccc;
    overflow:hidden;
    white-space:nowrap;
    width:100%;
}
div>div{
    display:inline-block;
    left:0;
    padding:10px;
    position:relative;
    transition:left .5s linear 9999s;
    white-space:initial;
    width:calc(100% - 4px);
}
#tab1:focus~div>div{
    left:0%;
    transition-delay:0s;
}
#tab2:focus~div>div{
    left:-100%;
    transition-delay:0s;
}
#tab3:focus~div>div{
    left:-200%;
    transition-delay:0s;
}
h1{margin:0 0 10px;}
<p id="tab1" tabindex="-1">Tab 1</p>
<p id="tab2" tabindex="-1">Tab 2</p>
<p id="tab3" tabindex="-1">Tab 3</p>
<div>
    <div>
        <h1>Page One</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non libero libero. Etiam a dui scelerisque, cursus ex non, dapibus nibh. Donec ac venenatis ligula. Curabitur mollis libero a elit tempus pretium. Ut ultricies viverra mollis. In efficitur purus at cursus pulvinar. Ut condimentum metus at ante viverra porttitor. Nullam vel purus mi. Nunc vel suscipit sapien, id faucibus sem. Sed tristique laoreet purus commodo molestie. Nulla volutpat feugiat enim at volutpat. Fusce dictum augue felis, sit amet sodales ipsum ...
    </div>
    <div>
        <h1>Page Two</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non libero libero. Etiam a dui scelerisque, cursus ex non, dapibus nibh. Donec ac venenatis ligula. Curabitur mollis libero a elit tempus pretium. Ut ultricies viverra mollis. In efficitur purus at cursus pulvinar. Ut condimentum metus at ante viverra porttitor. Nullam vel purus mi. Nunc vel suscipit sapien, id faucibus sem. Sed tristique laoreet purus commodo molestie. Nulla volutpat feugiat enim at volutpat. Fusce dictum augue felis, sit amet sodales ipsum...
    </div>
    <div>
        <h1>Page Three</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut non libero libero. Etiam a dui scelerisque, cursus ex non, dapibus nibh. Donec ac venenatis ligula. Curabitur mollis libero a elit tempus pretium. Ut ultricies viverra mollis. In efficitur purus at cursus pulvinar. Ut condimentum metus at ante viverra porttitor. Nullam vel purus mi. Nunc vel suscipit sapien, id faucibus sem. Sed tristique laoreet purus commodo molestie. Nulla volutpat feugiat enim at volutpat. Fusce dictum augue felis, sit amet sodales ipsum...
    </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

Tips for using "scoped" styles effectively in VueJS single file components

The documentation for VueJS states that the scoped attribute should restrict styles to a specific component. However, I noticed that if I create two components with the same baz style, it leaks from one component into the other: foo.vue <template> ...

Show outcomes in a single div with 2 columns

I am having an issue with the arrangement of child elements in a parent div. Here is the code that I am working with: JSBin These items are collapsible panels. When all of them are collapsed, everything looks fine. However, when you expand the first or ...

Exploring the connection between an image and its bounding box

Imagine we have an image that is originally sized at 300px by 300px. In this case, the image's content box matches those dimensions as well. However, if we adjust the image size using CSS to be, for example, 300px by 200px, the image will end up looki ...

Mysterious gap found between image and table

Hey there! I've been struggling with an unusual gap between a top image and a table on my website (www.tradecaptaincoaching.com). The table was created using . Despite spending hours on it, I can't seem to get rid of the huge 200 pixel gap that& ...

Passing a div's ID value using AngularJS AJAX to store it in a PHP variable

I have a collection of div elements, each with a unique id. My goal is to trigger a JavaScript function when a specific div is clicked. This function should send the id value of the clicked div to PHP, assign it to a PHP variable, and then receive a respon ...

What methods can be used to modify the appearance of the cursor depending on its position?

Is there a way to change the cursor to a left arrow when on the left half of the screen and switch it to a right arrow when on the right half, using JavaScript? I am trying to achieve something similar to what is shown on this website. I attempted to acco ...

Is there a way to have a content's columns adjust to the size of an image?

I'm currently struggling with a layout issue. I have an image on the left and want the content columns on the right (title, lorem...) to adjust their height to match the image. How can I achieve this? I'm using Bootstrap v5.1.1 Current image: ...

Using the <video /> tag on a Next.JS page generated on the server side leads to hydration issues

My Next.js app's index page is rendered on the server side by default. During development, I encountered an error that stated: Unhandled Runtime Error Error: Hydration failed because the initial UI does not match what was rendered on the server. Wa ...

Issue with Angular failing to fetch information from an external JSON file

Could use some assistance with my current setup for displaying books in JSON format. I suspect there might be an issue with either the view or the controller, but I'm not entirely certain. Any guidance would be greatly appreciated. <div class="boo ...

Implementing PHP code in HTML file

Is there a way to utilize PHP in order to make changes to an HTML file on a website? To clarify, I am looking to create a PHP file with input boxes that can append to a list in an HTML file. For example, the admin.php file will update the index.html file ...

css label not behaving properly when clicked

Is it possible to reduce the label size when focused for text input and restore it when no text is entered or clicking elsewhere? Here is the code snippet I have been experimenting with: div { height: 50px; width: 200px; border-bottom: 1px solid b ...

Displaying arrays in tabular and grid formats using PHP

I am working with an array containing item code, item name, and price details. $arr = array( "101: orange juice - 5.2", "504: hot roll - 6.2", "106: lime juice - 3", "210: mineral water (s) - 2.6", "107: PEACH JUICE - 6.99", "211: ...

Building a hyperlink from a textbox input: A step-by-step guide

I am attempting to modify the href of my link based on the content of the textbox with id="serie". However, Firefox is indicating that el is null. Can you help me identify where the issue lies? (The top section is the Page, the middle part shows the debug ...

IE encounters an absolute z-index problem when expanding concealed content

I'm having trouble with the positioning of a block (div). I am new to CSS, so any help would be greatly appreciated. Here is the code snippet: http://jsfiddle.net/9rEmt/ (please check it out) for viewing online in IE. When I use absolute for positio ...

Exploring ways to traverse through Map values

My app initially displays a grid of cells that I would like to fill in with data. Here is the initial view: https://i.sstatic.net/AgI16.png -> As the app runs, each rider's score will be updated dynamically like this: https://i.sstatic.net/HOPoN ...

A step-by-step guide on showcasing freshly submitted input data through Ajax

I'm having trouble with this issue! Once I submit the new input, it doesn't show up in the div. Below is my JavaScript code: $('#addVariable').validate({ rules: { variable: {required:true}} , submitHandler: functio ...

Ensure the calling object is retained during the resolution of an Angular promise

Identifying the Issue One issue arises when resolving promises in Javascript: the context switches to Window #. This means that referring back to the object resolving the promise becomes tricky because I can't access or modify its variables. The com ...

How can we prevent the text from shifting when the border width is adjusted

I've run into an irritating issue. My left menu text keeps shifting when I expand the border using jQuery. I've tried various solutions to prevent the text from moving, but nothing seems to work. Any suggestions? Could it be a CSS problem with t ...

Ribbon design in LESS/CSS does not maintain its structure when resized in Google

My CSS/LESS ribbon is displaying perfectly in Firefox, but encountering issues in Chrome when resizing the window. At 100% zoom, everything looks good, but adjusting the zoom causes elements to become misaligned. To make it easier to troubleshoot, I' ...

Changing various $scope object properties using ng-model

Can you help me figure out why the $scope.data variable is not updating when I input valid values in the form fields? How can I solve this issue? Check out the code example on Codepen: http://codepen.io/uloco/pen/jboorN HTML <div ng-app="app" ng-contr ...