Displaying jQuery Slide Elements in a row instead of stacking them on top of each other

I created a tutorial box with 4 slides (2 for this (demo)).

My goal is to make the slides slide from right to left when the user clicks next. I have been able to achieve this, however, the elements are displaying on top of each other instead of side by side.

To accomplish this, I used jQuery UI:

function guide() {
    // Controls for the welcome guide
    //guideCurrentItem = guideCurrentItem + 1;
    $("#1").hide('slide', { direction: 'left' }, 2000);
    $("#2").show('slide', { direction: 'right' }, 2000);
}

HTML:

<div class="welcome">
    <div class="holder">
        <div class="item" id="1">
            <div class="hero">

            </div>
            <div class="content">
                <h1>Read online, quickly and easily.</h1>
                <p>Get started now with our user guide, or <a href="/Home/Read">jump ahead</a> if you know you're setup.</p>
                <p class="align-center"><span class="button" onclick="guide()">Next</span></p>
                <div class="dots">

                </div>
            </div>
        </div>
            <div class="item offscreen" id="2">
                <div class="hero">

                </div>
                <div class="content">
                    <h1>Connect.</h1>
                    <p></p>
                    <p>Get started now with our user guide, or <a href="/Home/Read">jump ahead</a> if you know you're setup.</p>
                    <p class="align-center"><span class="button">Next</span></p>
                    <div class="dots">

                    </div>
                </div>
            </div>
        <div class="spacing"></div>
        <p class="align-center"><input type="checkbox" id="chkShowHelp" checked /> Hide this welcome screen the next time I visit</p>
    </div>
</div>

How can I effectively display them side by side? I've tried various combinations like display:inline-block but haven't been successful.

JS Fiddle

Ps. Yes, I am aware of plugins that can do this, but I prefer understanding the process myself.

Answer №1

Apply the CSS property position: absolute; to the element with class .item. Check out this example here.

Once you've done that, you can further customize the styling to enhance its appearance.

    .welcome .holder .item {
        position: absolute;
}

Answer №2

When it comes to sliders, a common approach is to use an items wrapper with a width equal to the number of items multiplied by the item's width. You can then move this wrapper around to navigate to the selected item.


    <div class="holder">
       <div class="items-wrapper" style='width:900px'>
         <div class="item" id="1"></div>
         <div class="item" id="2"></div>
       </div>
    </div>

With this method, there's no need to show or hide elements. Instead, you just have to adjust the marginLeft value of the items-wrapper. Calculations can be done using jQuery, and animations can be handled with CSS.

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

Discover the optimal approach for merging two jQuery functions effortlessly

The initial function (which can be accessed at ) is as follows: $('#confirm').confirm( { msg: 'Before deleting a gallery and all associated images, are you sure?<br>', buttons: { separator: ' - ' } } ); ...

import jQuery into a JavaScript file

I'm currently working on a Chrome extension that relies on background.js to perform basic tasks. I need to include jquery.js in my background.js file so that I can utilize its ajax function, but I'm unsure of how to achieve this. Is it even possi ...

Can a linked checkbox be created?

Is it possible to create a switch type button that automatically redirects to a webpage when turned on by clicking a checkbox? I'm working on implementing this feature and would like to know if it's feasible. ...

What is the reason behind the change in style hierarchy when using ':last-child'?

I found myself in a confusing situation where using :last-child is affecting how parent classes are being applied. The task at hand is to style the last element in a list of elements. However, upon using :last-child, the priority of styles shifts and one ...

Is it possible to turn off the shadow on just one side?

Is there a way to remove the shadow in the red area below? I have come across similar questions but unsure how to implement those solutions here. Live Demo: http://jsfiddle.net/xFa9M/ CSS:- #list li{ border: 2px solid black; border-top-width: 1px; borde ...

Achieving consistent image column heights that decrease evenly

I am trying to create a grid-like layout where each column in a row has the same height and contains an image while maintaining its proportions. Currently, I am using the flex-grow property to adjust the ratio of the images. Although this works, it often ...

How can you prevent an element from overflowing when employing window.pageYOffset and using a switch case to alter the background color at specified pixel thresholds?

I want the <body> element's background-color to change every 500px as I scroll down. I've scoured the web for answers, but still can't figure out what's going wrong. Please review the code. However, Firefox Browser indicates that ...

Enhance form validation by utilizing jquery.validate to display appropriate icons indicating correct and incorrect input, with the option to

Trying to replicate the functionality of the jQuery validate plugin demo seen here, I am facing an issue on my own website. Upon clicking submit after the page loads, the plugin displays validation messages with a cross symbol. However, upon entering text, ...

jQuery qTip: Pre-Creation Trigger

In my attempt to call the function someFunction() before the qtip is created, $('.selector').qtip({ content: { text: someFunction(this.id) } }); The code above manages to achieve this, but I feel like it's a messy solution. Is the ...

Is the accuracy of Chrome's inspect device not up to par?

I'm currently testing how the page appears on a 1366x768 laptop. When inspected in the device, it looks perfect: https://i.sstatic.net/OECnx.png However, on the actual laptop screen, it's completely off: https://i.sstatic.net/chaeY.png It&ap ...

How can I customize image dimensions by specifying a width parameter in the request?

I am looking for a solution to have compressed images on my website, without needing to compress them during upload or resize them using CSS. I would like to be able to call an image like this: <img src="/images/example.png?width=200"> By doing so, ...

Use jQuery to place tags around the content of existing <li> elements

Using jquery, I have been able to successfully create a list by using the following code: $(list).append(item); (where list is the list reference and item consists of the $('<li>') elements being added). var item = $('<li>' ...

The challenge of extending in SCSS

Within my SCSS code, I am attempting to create a placeholder with the following structure: %input__label { color: red; &_content { color: blue; } } Subsequently, I try to extend it like so: .input__label { @extend %input__lab ...

Identify the exact element to update information within a lengthy series of repeating elements

I'm currently developing a webpage that showcases a collection of dynamic content while featuring flag and like buttons for each individual piece of content. My goal is to allow users to click the "Like" button and have the corresponding "Dislike" but ...

Troublesome tab key function in FireFox causing navigation issues

I'm facing an issue with the tab key focus on links in FireFox. Strangely, it's working fine in Chrome but in FireFox, it keeps looping within one element. For better understanding, I have created a demo showcasing this behavior specifically in ...

How can the color of glyphicons be adjusted within an AngularJS ng-class that is constantly changing?

I am currently facing an issue with my function called lessThan(a,b) that checks if "a" is less than "b" and returns a boolean value. I have added a glyphicon to a form to display a check mark when true and an X when false, but I can't get the colors ...

Utilize CSS while emphasizing its unique class

Can someone help me figure out how to apply CSS styles using the focus selector on a specific class? I want to hide the class itself when it is in focus. Below is the code snippet I have been working with: body { display: block; } .span3:focus ~ .aler ...

Impact on adjacent div

Within my code, I have two sibling divs that contain additional nested divs as shown below: <div class="btn_lists"> <div class="btn green_btn"> <img src="<?= asset_url() ?>images/escolar_07__1.png" /> </div> & ...

Instructions for implementing a Back button that takes you directly to the text or link you clicked on to view an image

My goal is to have multiple anchor links within text, each linking to a specific image on the same page. Once the user views the image, I want them to be able to click a 'Back' button that will take them back to where they left off in the text. ...

Displaying user input data in a separate component post form submission within Angular

I recently developed an employee center app with both form and details views. After submitting the form, the data entered should be displayed in the details view. To facilitate this data transfer, I created an EmployeeService to connect the form and detail ...