Expand row size in grid for certain row and item

For my project, I am utilizing a Grid layout to display 5 items per row. https://i.sstatic.net/PW6Gu.png

Upon clicking on an item, my goal is to have the item detail enlarge by increasing the size of the HTML element. https://i.sstatic.net/nGj8l.png

Is there a CSS trick that allows me to instruct the Grid to expand a specific item while shrinking the others in the row, and also allocate more space to one row compared to the rest?

Answer №1

No secret formula to mastering this task, just dedication and perseverance. The approach you take depends on the specific outcome you're aiming for.

If responsiveness is not a top priority (what happens when the page is viewed on a mobile device?), one could experiment with utilizing CSS transforms like scale on hover, or strategic use of calc function in setting widths via CSS, or a combination of both techniques.

Attempting to achieve this functionality using the CSS grid property may prove challenging as it's not optimized for intricate interactions. A more feasible strategy would involve building from scratch using flexbox or manual positioning with JavaScript.

Answer №2

While not the most optimal solution, this method will help resolve your issue.

Using 'Margin 0 5rem;' configures a margin on the left and right sides of the hovered box.

.box:hover{
  transform: scale(1.3);
  margin: 0 5rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}


body {
  min-height: 100vh;
  background-color: bisque;
}



.container{
  padding:1rem;
  display: flex;
  flex-direction: row;
  gap:1rem;
  padding:10rem
}

.box{
  height:15rem;
  background-color: grey;
  display: flex;
  flex:1;
  margin-top: 2rem;
  transition: 0.5s;
  
}

.box:hover{
  transform: scale(1.3);
  margin: 0 5rem;
}
<div class="container">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></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

Exploring the depths of routing with React Router DOM Version 6

Hello everyone, I trust you are all doing well. Recently, I completed a project using React and created a demo here. The issue I'm facing is related to routing. My intention is to display the child route under its parent but unfortunately, I haven&apo ...

Ways to implement a custom scrollbar across an entire webpage:

I am trying to implement the Jquery custom content scroller on my webpage to replace the default scrollbar. However, I am facing difficulties in getting it to work properly. You can view my code on Codepen. Although the plugin works fine with smaller blo ...

The automatic selection process for IE document modes

It may seem simple, but I'm a little perplexed about how IE decides which browser mode to use. In IE9, there are options such as IE9 Compatibility Mode, IE9, IE8, and IE7. These modes are selected automatically depending on the webpage. Can someone e ...

Explore and target elements using browser inspection

Is it possible to create a new CSS class using browser inspection that contains new hover/focus styles? For example: .CanIDo { /*some css rules (ex.)*/ width: 100; } /*my question (USING BROWSER INSPECTOR, not directly typing in the CSS file)*/ .CanI ...

Issue with Material UI and React Autocomplete: Popover does not properly display when an item is selected, causing Autocomplete to

I'm currently working on a customized Autocomplete feature, where each item displays a more icon when hovered over with a mouse pointer. The issue I am facing is that instead of triggering a Popover when clicking the icon, it closes the Autocomplete ...

What causes variations in the output of getClientRects() for identical code snippets?

Here is the code snippet provided. If you click on "Run code snippet" button, you will see the output: 1 - p.getClientRects().length 2 - span.getClientRects().length However, if you expand the snippet first and then run it, you will notice a slight dif ...

Swagger is refusing to cooperate because my model's attributes are set to true

Currently delving into Swagger and its documentation functionality through a YAML file. Previously, I had used @swagger in the controller file and everything worked fine. However, when attempting to transition to a YAML file for better organization, issues ...

Resolving conflict between a user-defined class name and a built-in class name

I am creating a TypeScript Map class that utilizes the built-in Map class along with generics. The problem arises when both classes have the same name. Is there a way to import the built-in Map using explicit namespace, similar to how it's done in Jav ...

What is the best way to display multiple VR scenes on a single webpage?

Currently, I am attempting to display several 360 photos utilizing the a-frame library through implementing a-scene. However, I am encountering an issue where only one scene is being rendered on my page. Are there any alternative approaches to address this ...

Are there more effective methods for handling the scenario where a component returns null?

Any suggestions for a more efficient approach to this scenario (where a component returns null)? Within my Page component, I am required to update the pageTitle state which is then displayed in a component higher up in the component tree. layout.tsx: imp ...

Trouble ensues with integrating Magic CSS3 animations via jQuery due to malfunctioning

I've been experimenting with some magical CSS classes from a source I found online (http://www.minimamente.com/magic-css3-animations/) and trying to apply them using jQuery on mouseenter and mouseleave events. Unfortunately, it's just not working ...

The Bing map control fails to adhere to the div element

After visiting , I successfully generated a map using the following HTML code: <div class="fluid-row" style="height:300px;"> <div class="span12"> <div id="prdmap" class="map"> </div> </div> Here is the accompanying J ...

SolidJS directives utilizing use:___ result in TypeScript errors when used in JSX

As I work on converting the forms example from JS to TS, I came across a typescript error related to directives in HTML: https://i.sstatic.net/Hl8Pv.png It appears that validate and formSubmit are being recognized as unused variables by typescript, result ...

Looking for assistance navigating through a website's links using Selenium?

Trying to extract links from this webpage, specifically the ones listed in the footer. An example of what I'm dealing with: https://i.sstatic.net/PPvb0.png The goal is to scrape all links related to securities displayed in a table and then navigate ...

Develop a personalized mapping API with a unique image integration for website navigation

Currently, I am in the process of developing a website for my university that will allow users to easily locate all available free food options on campus. My goal is to create a platform where food providers can register their events, have them saved in a ...

Utilizing jquery for displaying and hiding notifications - Notyfy in action

Recently, I've started working with jQuery and have come across the useful Notyfy jQuery plugin. My goal is to display a notification bar with specific messages based on certain conditions such as success or error. I'm trying to achieve somethin ...

Looking to create a centered 'ul' using Bootstrap

I am looking to center the list with a specific width. body { background-color: rgb(26, 40, 114); } h1 { color: white; text-shadow: 7px 7px 10px black; } li { list-style: none; border-radius: 5px; border: 2px solid white; background-colo ...

Elimination of encapsulating div in React

After using this.setState to update the object, I encountered a problem. It appears that my object is initially updated with the new one after changing state. However, when it returns to a function called by render which maps the component's "view," ...

Having trouble running the npm script due to a multitude of errors popping up

I have encountered an issue while trying to run an npm script. I added the script in the `package.json` file multiple times, but it keeps showing errors. I am currently working on building a website and require npm sass for it. However, when I try to run t ...

Get rid of the TypeScript error in the specified function

I am currently working on implementing a "Clear" button for a select element that will reset the value to its default state. Here is a snippet of my code: const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => { onChange( ...