Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
152 views
in Technique[技术] by (71.8m points)

css - Inserting component on click between grid rows

I have a grid of items and when I click on one of them I want to show another component that takes all the width on the row under the clicked item.

Here is a picture of what I want to achieve enter image description here

I have a button-list-component which contain a button-component that display my items with an ngFor. When I click on an item the size-selection-component is shown with a ngIf.

My problem is that if I have the size-selection-component in the button-list-component, it append at the end of the grid, and if I have this new component in the button-component then it only takes the width of the column containing the clicked item.

If I put it in position absolute I can make it the width of the container but then the following items won't go down.

Here is a piece of my code

button-list

<div class="wrapper">
  <div class="container">
    <app-button *ngFor="let button of buttons;" [button]="button" (buttonClicked)="onButtonClicked($event)">
    </app-button>
  </div>
</div>
.container {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(250rem, 1fr));
  grid-gap: 10rem;
  place-items: start center;
  overflow-x: hidden;
  overflow-y: auto;
  margin: 10rem;
}

button

<div class="product">
    <div class="product-col">
        <h2 class="product_title" (click)="onButtonClicked()">{{button.Caption}}</h2>
        <img class="product_img" [src]="picture" alt="" (click)="onButtonClicked()">
        <span class="product_price" *ngIf="button.Price && button.Price != '0'">{{button.Price / 100 | currency}}</span>
    </div>
</div>

<app-size-selection-button-list *ngIf="isSizeSelectionOpen"></app-size-selection-button-list>

How would it be possible to achieve that ? Maybe there is a solution in CSS or maybe another way to insert my component in the grid of items that would work.

Thanks

question from:https://stackoverflow.com/questions/65837550/inserting-component-on-click-between-grid-rows

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't have to append the div, you can create it and hide it, when user hover over the item div, you show it and set its child tag's innerHTML to whatever you need, like this

<body>
    <p onmouseover="show();"></p>AA</p>
    <div style="width:100%">
        <div style="width:33%">
            <p>Name</p>
        </div>
        <div style="width:33%">
            <p>Name</p>
        </div>
        <div style="width:33%">
            <p>Name</p>
        </div>
    </div>
    <div id="blah" style="display:none">
        <!-- whatever here -->
    </div>
<script>
    function show() {
        var b=document.getElementById("blah");
        b.style.display="block";
        // Change some innerHTML of elements inside the blah div here
    }
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...