Expand the object by clicking on it, causing the surrounding objects to move outside the viewport instead of appearing below

I'm facing a challenge with 3 squares inside one container, each occupying 33.33% of the viewport and placed next to each other. When I click on one square, it should expand to full viewport width and reveal hidden content, while the other two remain adjacent but partially outside the viewport. The container needs to be horizontally scrollable for accessing the remaining squares.

Currently, when I expand one square, the other two automatically move below it instead of staying beside it. How can I fix this issue?

Demo: http://jsfiddle.net/7pg0buL8/

<div class="container">
    <div class="tile"></div>
    <div class="tile"></div>
    <div class="tile"></div>
</div>
.container {
    width:450px;
    height:150px;
    border: 1px solid blue;
    overflow-x: scroll;
    overflow-y: hidden;
}

.tile {
    width:150px;
    height:150px;
    border:1px solid red;
    box-sizing: border-box;
    transition: width .5s;
    float:left;
    background-color:green;
}

.tile.expanded {
    width:100%;
}
$(function () {
    $('.tile').click(function () {
        $('.tile.expanded').removeClass('expanded');
        $(this).addClass('expanded');
    });
});

Answer №1

Give this code a try by setting the nowrap rule

CSS

.container {
    width:450px;
    height:150px;
    border: 1px solid blue;
    overflow-x: scroll;
    overflow-y: hidden;
    white-space:nowrap;

}

.tile {
    width:150px;
    height:150px;
    border:1px solid red;
    box-sizing: border-box;
    transition: width .5s;
    background-color:green;
    position: relative;
    display: inline-block;
}

.tile.expanded {
    width:100%;
}

Check out the DEMO HERE

Answer №2

Test out the following CSS:

.wrapper {
   width:700px;
    height:200px;

    overflow-y: hidden;
}

.box {
    width:180px;
    height:180px;
    border:1px solid blue;
    box-sizing: border-box;
    transition: width .7s;
    float:left;
    background-color:yellow;
}

.box.expanded {
    width:280px;
}

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

"Stylish hover effect for list items using CSS arrows

I'm struggling with creating a list menu that has a 1px border and spans the entire width. Here is what I have so far (image 1): https://i.stack.imgur.com/y3EDP.png The tricky part is making it so that when the mouse hovers over a menu item, someth ...

How can I personalize the preview feature in a Bootstrap rich text editor?

Currently, I am utilizing Bootstrap's rich text editor by this method $('#editor').wysiwyg();. Utilizing AJAX, I am passing the HTML content created by .wysiwyg to save it in the database. Later on, I plan to retrieve the saved HTML data to ...

Most effective method for utilizing Ajax to upload files and ensuring they are uploaded before submission

I am currently working on a form that contains various fields, including file upload functionality for multiple files. I have also explored the option of using AJAX to upload files. My goal is to seamlessly upload files via AJAX while simultaneously fillin ...

Double submission with JQuery .post

I am struggling to prevent this JQuery POST call from being submitted twice. I have attempted various versions of unbind but do not fully comprehend how it works. While I have come across similar queries, they only mention using unbind without delving int ...

I am encountering an issue while trying to connect data to jquery datatable

Troubleshooting Issues with Binding Database Data to jQuery Datatable in ASP.NET Having written the necessary code, the challenge arises when attempting to link database data to a jQuery datatable. The JSON formatted data received on the aspx page present ...

The Jquery .change() function refreshes the results just once

I am working on a form with 3 input fields named #first, #second, and #third, along with a fourth field labeled as #theResult. <div id="addFields"> <span id="addFieldsHeader">Add The Fields</span> <table style="margin:0 auto;"> ...

The jQuery .html() function is only functional in Internet Explorer when the Developer Tools are visible on the screen

On a particular page, users have the ability to add, edit, and delete items. This functionality is made possible through a series of Ajax calls that communicate with server-side code to update data on the backend. Once the data is successfully updated, the ...

Within jQuery lies the power to perform multiplication operations effortlessly

I'd like to accomplish this using jQuery: var menuItems = document.getElementsByTagName("li"); for (var k = 0; k < menuItems.length; k++) { if (menuItems[k].className == "menu") { var child = menuItems[k].firstChild; if ...

Arranging unrelated divs in alignment

http://codepen.io/anon/pen/Gxbfu <-- Here is the specific portion of the website that needs alignment. My goal is to have Onyx Design perfectly aligned with the right side of the navbar, or to have the navbar extend up to the end of "Onyx Design". The ...

Trouble with linkage in jQuery for AJAX requests in an external .js document

My asp.net application has a master file that includes the jquery.js file. On another page that uses this master page, I have my own jquery code. I attempted to move this code to an external file and then include it in my .aspx file. While most functions ...

assigning attributes to web addresses

Is there a way to set a style property for webpages by targeting addresses that contain /index.php/projecten/ instead of specifying each complete address in the code? Currently, I am using the following code: <ul class="subnavlist" style="display: &l ...

Extract Data from JSON Array using Jquery

I am working with a JSON array retrieved from a web API, and I need to extract specific values from it. For instance, how can I retrieve all the rides in the first place and access rides[1]. UserID or Images? { "Status":1, "Rides& ...

Developing a cascading dropdown feature for ASP.NET MVC using JSON

I am currently working on implementing a cascading drop-down list in ASP.NET MVC by following a tutorial. However, I'm encountering an issue where the first drop-down box is not loading with manufacturer data. I suspect there may be an error with the ...

Creating a reusable anonymous self-invoking function

Here is a function that I am working with: (function(e, t) { var n = function() { //code, code, code }; //code, code, code e.fn.unslider = function(t) { //code, code, code }; })(jQuery, false) To execute this function, I have impleme ...

Adjusting the z-index of the tinyMCE toolbar

I have been utilizing the tinyMCE editor plugin, which transforms textareas into iframes and displays a toolbar at the top of the content. It has been functioning flawlessly. However, there are times when there are videos placed above the content. In such ...

Demonstration of Concurrent Page Processing in Flask

Currently, I am working on an application that heavily utilizes graphics using libraries such as Raphael and graphdracula. The main functionality of the application involves drawing various graphs across different pages named graph1, graph2, and graph3. L ...

Unlimited scrolling functionality in CodeIgniter utilizing the power of jQuery

Hey everyone, I have a little issue that I hope you can help me with: I've set up a blog using code igniter and here is my code snippet: This is from my home_page controller: public function index() { $data['posts'] = $this-&g ...

Automated form with built-in calculations

Whenever a product is selected from the dropdown menu, the price value should be automatically filled in the input field with ID #price. Then, the user can enter the quantity in the input field with ID #quantity, and the total sum of price multiplied by qu ...

Having trouble accessing the property 'top' of an undefined object in your Ruby on Rails project?

After thoroughly reviewing all the similar threads on SO regarding this error, none of them provided a solution that worked for me. Here is the flow of events: Go to the new Customer page, fill out the required fields, and click save Invoke a method in ...

Show the page information directly on the current page instead of redirecting it to a different page

On my website (For example, Link1: http://localhost:8086/MyStrutsApp/login.do), there are multiple links available. Whenever a user clicks on one of these links, they are directed to another page (For instance, link2: http://localhost:8086/MyStrutsApp/AddB ...