What is the best way to position an element to the right of other elements within a div?

My goal is to style my button like this :

desired look

However, I'm unsure of the necessary steps to achieve this. Here is my HTML code :

<div  class="content" *ngIf="loading==false" >
      <div class="product" *ngFor="let product of products$ | async ; let i = index">
        <div class="header">
        <h1 class="product-name">Product name : {{product.Name}}</h1>
        <h2 class="product-id">Product id : {{product.Id}} </h2>
        <button (click)="addCanvasModel(product.Id)">Add new Canvas Model</button>
      </div>
      <div fxLayout="row wrap" fxLayoutGap="3px grid">
        <div *ngFor="let model of myObservables[i] | async"> 
          <app-bmc-card-preview [name]="model.Designation" [id]="model.Id" [behaviour_subject]="refreshModels$"></app-bmc-card-preview>
        </div>
      </div>
    </div>
  
</div>

Here is a snippet of my CSS code:

.product {
    background-color: white;
    border:1px solid black;
    font-family: roboto;
    text-align: left;
    margin:10px;
}

Answer №1

To implement a flexible layout, you can leverage the power of flex:

<div class="content" *ngIf="loading==false">
    <div class="product" *ngFor="let product of products$ | async ; let i = index">
        <div class="header" style="display:flex;">
            <div style="flex:1;">
                <h1 class="product-name">Product name : {{product.Name}}</h1>
                <h2 class="product-id">Product id : {{product.Id}} </h2>
            </div>
            <div>
                <button (click)="addCanvasModel(product.Id)">Add new Canvas Model</button>
            </div>
        </div>
        <div fxLayout="row wrap" fxLayoutGap="3px grid">
            <div *ngFor="let model of myObservables[i] | async">
                <app-bmc-card-preview [name]="model.Designation" [id]="model.Id" [behaviour_subject]="refreshModels$"></app-bmc-card-preview>
            </div>
        </div>
    </div>
</div>

Answer №2

<div  class="content" *ngIf="loading==false" >
    <div class="product" *ngFor="let item of items$ | async ; let i = index">
            <div class="header">
               <div class="container"> 
                   <h1 class="product-name">Item name : {{item.Name}}</h1>
                    <h2 class="product-id">Item id : {{item.Id}} </h2>
                </div>
            <button (click)="addCanvasModel(item.Id)">Add new Canvas Model</button>
          </div>
          <div fxLayout="row wrap" fxLayoutGap="3px grid">
            <div *ngFor="let model of myItems[i] | async"> 
              <app-bmc-card-preview [name]="model.Designation" [id]="model.Id" [behaviour_subject]="refreshModels$"></app-bmc-card-preview>
            </div>
          </div>
        </div>
      
    </div>
    
    .product {
        background-color: white;
        border:1px solid black;
        font-family: roboto;
        text-align: left;
        margin:10px;
        display:flex;
    }
    .container{
        display:block;
    }

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

What is the most effective method for determining the distance between two UK Postcodes?

Can you suggest a reliable method for calculating the distance between two UK postcodes in order to determine if they are within range? I do not intend to display a map, but instead provide a list of results for valid locations. For example, showing loca ...

Creating a scrollable table with CSS: A step-by-step guide

My table has too many columns causing it to exceed the width of the screen. I would like to make it scrollable horizontally for a neater and more organized appearance. I believe CSS with the overflow hidden property can achieve this, but I am unsure where ...

Browsing a container with JavaScript

I am attempting to display one div at a time and scroll through them repeatedly. I found and modified a Fiddle that works as intended, but when I try to implement it on my own test page, the divs do not scroll as expected. Here is the Fiddle example: http ...

CSS class for modifying color based on certain conditions

Suppose I have this CSS code: label { color: #AAAAAA; } Can I modify it to include a condition that changes the color to red if the label has the "error" class? I am aware that I can dynamically add the class to the label in HTML, but I am curious if ...

What methods can I employ to utilize CSS on a table row that contains a specific class in an HTML

Is there a way to make the CSS affect <tr class="header"> with the class of header? CSS table.table-bordered tr:hover{ background-color: #C0C0A9; } table.table-bordered tr { background-color: #C0C0D9; } Any suggestions on what I ...

What are some ways to design scrollbars with a Google Wave-like style?

Is there a way to design scrollbars similar to the ones found in Google Wave? They seem to save space and have an appealing look. I am interested in implementing these customized scrollbars on a div element, just like how Google Wave utilizes them. https: ...

Is there a way to adjust the dimensions of individual pictures?

Dealing with a variety of images within a resizing container can be tricky. I have a solution for adjusting each image to a specific size without affecting the others. Currently, the container's CSS is set to resize images based on browser size: .con ...

Utilizing JSON for HTML conversion in Codeigniter

public function getCrew(){ $search = $this->input->post('name'); if($this->input->post('ajax') && (!empty($search))){ $result = $this->model->getNames($search); foreach($result as $r){ ...

Troubleshooting a glitch with passing a variable to a PHP script using AJAX

Explanation of the page functionality: When the quiz php page loads, a user can create a score using a function in quiz.js. This score is then stored in a variable score within quiz.js Once the score is generated, the user must click a button to move on ...

Is it possible that CSS files are not being excluded from content scripts in manifest.json?

I am looking to create a chrome extension that enforces a specific CSS style on all websites except for Gmail. However, I am facing an issue where the code in the content scripts section of the manifest.json file is not working as expected. Even though I h ...

Enhancing the SVG font size through custom CSS styling

Working with an SVG element and utilizing CSS to adjust the font-size of the text within the SVG. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 720"> <rect class="vBoxRect" width="1280" height="720" fill="none" stroke="red"& ...

The intricate scripting nestled within the jQuery function

When using jQuery, I am looking to include more codes within the .html() function. However, I also want to incorporate PHP codes, which can make the writing style quite complex and difficult to read. Is it possible to load an external PHP/HTML script? fu ...

A guide to customizing the list-style-image for unordered lists in Weebly

I encountered an issue while trying to create a page on Weebly. Whenever I attempt to customize my 'ul' tag in the following way: #top-home-wrap #main #content ul { color: yellow; list-style-image: url('fa-check.png') !important; } T ...

Internet Explorer having trouble with onload function

Here is a snippet of code that I am working with: <html> <head> <style> #visibilitycontent{ visibility:hidden; } </style> </head> <body onload="visibilitychange()"> <div id="header"> This is the h ...

refusing to display the pop-up in a separate window

Hi there, I'm having an issue with a link that's supposed to open in a pop-up but is instead opening in a new tab. I'd like it to open in a proper pop-up window. <button class="button button1" onclick=" window.open('te ...

PHP Address Bar URL Rewriting: Enhancing Website Navigation with Clean URLs

Does anyone know how to rewrite the URL in the address bar from https://www.tinycent.com/web/single_post.php?slug=samsung-sprint to https://www.tinycent.com/web/single_post/samsung-sprint I've looked at over 10 different demos on StackOverflow an ...

Tips for displaying two dynamic variables that are interdependent

For instance: Controller: AllBooks[{ book1:{ hardcover{price:25.99},e-book{price:1.99} } }, book2:{ hardcover{price:60.00},e-book{price:2.99} }]; $scope.bookchoice = function(selectedBook) { $rootScope.choice = selectedBook;} $scope.booktype = functio ...

Border Effect Resembling Windows Tiles

When you hover your mouse over a tile in Windows, a cool effect happens: Hovering outside the tile, but within the container area: https://i.sstatic.net/yZk9f.png Hovering inside a tile: https://i.sstatic.net/LoSmk.png Hovering outside a tile at its m ...

In order to toggle a div property on and off with each click, you will need to use an onclick JavaScript function

I have an HTML button that triggers a JavaScript function when clicked, revealing a hidden div by changing its display property. The current setup is functional and achieves the desired outcome. However, I now wish to modify the functionality so that subs ...

Compressed search bar when in mobile mode

My search bar is getting squashed on mobile devices. Any suggestions for fixing this issue? <div id="menu" class="py-4 d-flex justify-content-center"> <div class="row "> <div class="col-sm-auto "> ...