Problem: my generated columns doesn't center align my mat-icon.
What am I missing?
On ngFor my datatable columns are generated dynamically, but no one's align correctly.
Inside my DIV there's a mat-icon that's (by default) apply for left alignment.
HTML Code:
<div *ngFor="let col of colunas">
<ngx-datatable-column [name]="col.ds_titulo_coluna" *ngIf="col.fl_exibe_coluna">
<ng-template let-row="row" ngx-datatable-cell-template>
<div *ngIf="row[col.id] === 'pend'">
<div class="v-align-middle">
<mat-icon class="warning">info</mat-icon>
</div>
</div>
<div *ngIf="row[col.id] === 'rep'">
<div class="v-align-middle">
<mat-icon class="red-fg">report_off</mat-icon>
</div>
</div>
<div *ngIf="row[col.id] === 'ok'">
<div class="v-align-middle">
<mat-icon class="green-fg">check_circle</mat-icon>
</div>
</div>
<div *ngIf="row[col.id] === 'ag'">
<div class="v-align-middle">
<mat-icon class="orange-fg">schedule</mat-icon>
</div>
</div>
</ng-template>
</ngx-datatable-column>
</div>
SCSS Code:
.ngx-datatable-column.text-center
{
display: flex !important;
align-items: center !important;
margin-left: 10px;
}
.warning{
color: #dec71b;
}
.v-align-middle {
vertical-align: middle;
}
Result of code:
Replace .v-align-middle CSS rules as per below. Hope this will be worked for you.
.v-align-middle {
display: flex;
justify-content: center;
align-items: center;
}
Related
I tried lots of methods to get the button below each image from ngFor loop in angular 10 but it populates the button next to the image not in each image it's showing as a list I attached the image output also. This is the code that I tried.
CSS
.container {
position: relative;
text-align: center;
}
.original {
width: 250px;
height: 250px;
float: left;
margin: 1.66%;
transition-duration: 0.3s;
border-radius: 15px;
}
Html
<ng-container *ngFor="let img of imageData">
<div class="container">
<img class="original" [alt]="img.Name"
src="https://localhost:44349/{{img.ImagePath}}"
width="350" height="350"/>
</div>
<button type="submit" (click)="deleteImage(img.Id)" class="btn btn-danger"><i
class="far fa-trash-alt"></i>
Remove
</button>
</ng-container>
Try this markup, move the closing div after the button element:
<ng-container *ngFor="let img of imageData">
<div class="container card">
<img class="original" [alt]="img.Name"
src="https://localhost:44349/{{img.ImagePath}}"
width="350" height="350"/>
<button type="submit" (click)="deleteImage(img.Id)" class="btn btn-danger"><i
class="far fa-trash-alt"></i>
Remove
</button>
</div>
</ng-container>
with new css class using flexbox:
.card {
display: flex;
flex-direction: column;
}
UPDATE
according to some css classes like btn, btn-danger I presume bootstrap used.
You can wrap the whole thing inside a div with these classes:
<div class="d-flex flex-wrap">
General info and docs
Stackblitz demo
I'm pretty new to the Angular framework and I'm making an app with a bunch of Angular components. Right now I'm trying to do a Search Page where I have an input for searching characters, and then after you've picked one of the lists it will show the character's stats card.
So what I want is to move both the search input and the card which appears after selecting a character in the middle of the screen, instead of having them both positioned at the left side of the screen.
Here is a picture that shows what I want to accomplish:
Here is my code right now (might be a bit messy but I just started like a month and a half ago learning JS, HTML, and CSS):
Search Component Template =>
<div fxLayot="column">
<div style="background: #4c4848" class="detailContainer">
<h1>Buscador de Personajes:</h1>
</div>
<br><br>
<div fxLayout="row">
<div fxLayot="column">
<form class="autocomplete-form">
<mat-form-field class="enable-full-width" style="background: #4c4848; border-radius: 5px; border: 4px solid black;">
<mat-label>Nombre</mat-label>
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="searchInput"
[matAutocomplete]="auto" (input)="search()">
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete" (optionSelected)="selectedOption($event)" [displayWith]="checkValue">
<mat-option *ngFor="let character of suggestions" [value]="character">
{{character.name}}
</mat-option>
<mat-option *ngIf="characters.length === 0 && searchInput.value.trim().length>0" value="">
ERROR 404 - No se encontró nada con el término "{{searchInput.value}}".
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
</div>
<span class="middler"></span>
<div *ngIf="selectedCharacter" fxLayout="column" style="width: 400px;">
<app-character-card [character]="selectedCharacter"></app-character-card>
</div>
(Don't know why they appear in distinct code blocks sorry for that)
Search Component CSS =>
.autocomplete-form {
min-width: 500px;
max-width: 500px;
width: 100%;
}
.enable-full-width {
width: 500px;
}
.detailContainer {
text-align: center;
justify-content: center;
align-items: center;
border: 5px solid black;
border-radius: 7px;
padding-top: 10px;
}
.centered {
text-align: center;
justify-content: center;
align-items: center;
}
Character Card Component Template =>
<mat-card>
<mat-card-header>
<div mat-card-avatar class="header-image"></div>
<mat-card-title class="charname">{{character.name}}</mat-card-title>
<mat-card-subtitle class="charage">{{character.age}}</mat-card-subtitle>
</mat-card-header>
<img mat-card-image [src]="character | image">
<mat-card-content>
<mat-card-title>{{character.race}}</mat-card-title>
<mat-card-subtitle>{{character.class}}</mat-card-subtitle>
<hr>
<div fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10px">
<div fxLayout="row" fxLayoutGap="30px">
<div fxFlex="50">
<strong>Fuerza: </strong>{{character.strength}}
</div>
<div fxFlex="50">
<strong>Inteligencia: </strong>{{character.intelligence}}
</div>
</div>
<div fxLayout="row" fxLayoutGap="30px">
<div fxFlex="50">
<strong>Destreza: </strong>{{character.dexterity}}
</div>
<div fxFlex="50">
<strong>Carisma: </strong>{{character.charisma}}
</div>
</div>
<div fxLayout="row" fxLayoutGap="30px">
<div fxFlex="50">
<strong>Constitución: </strong>{{character.constitution}}
</div>
<div fxFlex="50">
<strong>Sabiduría: </strong>{{character.wisdom}}
</div>
</div>
</div>
<hr>
</mat-card-content>
<mat-card-actions>
<button mat-button color="warn" [routerLink]="['..', character.characterId]">
Leer Más
</button>
<button mat-button color="info" [routerLink]="['../../editcharacter', character.characterId]">
Editar
</button>
<a mat-button color="info" [routerLink]="['../..', character.userId, character.characterId, 'inventory']">
Inventario
</a>
</mat-card-actions>
Character Card Component CSS =>
mat-card {
margin-top: 20px;
}
img {
height: 500px;
}
.charname, .charage {
margin-top: 5px;
}
.header-image {
background-image: url('././assets/d20.png');
background-size: cover;
}
I really just need them positioned in the center. I also have this problem in my ItemSearchComponent, but I suppose If I can't answer this, I could easily extrapolate to the other one. Thanks!
If you need any more code just ask.
To achieve that put the search and the results-of-the-search on the same DIV, in "row mode" one below the other, then center that DIV horizontally with many methods out there I usually go for display:flex
<div class="head">
buscador de personajes
</div>
<div class="searchContainer">
<div class="searchVertical">
<div class="border">your<br>SearchBox</div>
<div class="border">search<br>Resuts</div>
</div>
</div>
CSS
.searchContainer {
width: 100% ;
display: flex ;
justify-content: center;
}
.searchVertical {
display:flex ;
flex-direction: column;
}
.border {
border : 1px red solid ;
}
.head {
width: 100% ;
border: 1px green solid ;
}
This is how it looks
https://www.geeksforgeeks.org/how-to-center-a-div-using-flexbox-property-of-css/
I have created a div which shows an icon and text but I need to get the icon next to the text instead of above it. Currently looks like this:
And I need the icon to be next to the text like this (the icon needs to be displayed to the left of the text without moving the text so the header still aligns with the phone number):
Code:
<div fxLayout="row" fxLayoutAlign="space-around center">
<div>
<mat-icon svgIcon="phone-outline"> </mat-icon>
<h3>Customer Support</h3>
<label>123456</label>
</div>
<div>
<mat-icon svgIcon="email-outline"> </mat-icon>
<h3>Email</h3>
<label>test#email.com</label>
</div>
<div>
<mat-icon svgIcon="map-marker-outline"> </mat-icon>
<h3>Address</h3>
<label>address line 1</label>
</div>
</div>
I have three divs and using fxLayoutAlign aligns them next to each other accoss the page but if I put the icon into a seperate div the fxLayoutAlign moves it too far across the page. Is there a better way to align the divs?
Tried so far:
Tried putting the icon on the same line as the text but that puts the icon too close to the text:
<h3><mat-icon svgIcon="phone-outline"> </mat-icon> Customer Support</h3>
I need to have space between the icon and text and align it with the text.
Using CSS to try align still causes the icon to be too close to the text (and not aligned correctly):
.align-items { display: flex; justify-content: space-between; } .align-content { display: flex; align-items: center; }
Moving the icon in CSS using margins looks like its working but it has now moved the second line with the phone number:
The phone number should be directly under the header text (like in first screenshot above)
Here is another approach with pure css.
css
.align-items {
display: flex;
justify-content: space-between;
}
.align-content {
display: flex;
}
mat-icon {
margin-right: 10px;
}
.align-text-item {
display: flex;
flex-direction: column;
align-items: center;
}
h3 {
margin-top: 0px;
}
html
<div class="align-items ">
<div class="align-text-item">
<div class="align-content">
<mat-icon svgIcon="thumbs-up" aria-hidden="false" aria-label="Example thumbs up SVG icon"></mat-icon>
<div>
<h3>Customer Support</h3>
123456
</div>
</div>
</div>
<div class="align-text-item">
<div class="align-content">
<mat-icon svgIcon="thumbs-up" aria-hidden="false" aria-label="Example thumbs up SVG icon"></mat-icon>
<div>
<h3>Email</h3>
123456
</div>
</div>
</div>
<div class="align-text-item">
<div class="align-content">
<mat-icon svgIcon="thumbs-up" aria-hidden="false" aria-label="Example thumbs up SVG icon"></mat-icon>
<div>
<h3>Address</h3>
123456
</div>
</div>
</div>
</div>
Create a class for the divs wrapping the icon and heading. No fxLayout is needed
.align-icon{
display: flex;
align-items: flex-end;
}
You can use the matPrefix and matSuffix
<mat-form-field class="example-full-width">
<mat-icon matPrefix>mode_edit</mat-icon>
<mat-label>EXAMPLE</mat-label>
<mat-icon matSuffix>mode_edit</mat-icon>
</mat-form-field>
<div fxLayout="row" fxLayoutAlign="space-around center">
<div>
<h3>Customer Support<mat-icon svgIcon="phone-outline"> </mat-icon></h3>
</div>
<div>
<mat-icon svgIcon="email-outline"> </mat-icon>
<h3>Email</h3>
</div>enter code here
<div>
<mat-icon svgIcon="map-marker-outline"> </mat-icon>
<h3>Address</h3>
</div>
</div>
I have 4 columns in a row that become 1 column on mobile. The way this looks on mobile is fine, but I want to center the content in divs 2 and 4 in each row. What would be the best way to do this?
Apparently my edit was deleted or the site messed up, but I had said I want to do this vertical and horizontal. However, it was my fault I forgot to link to the page. Sorry, guys. - http://www.dismantledesign.com/testsite2/clients.html
Edit: I appreciate all the answers, but I don't think anyone understands that this div has no set height. I just want that text and icons to stay centered as the screen moves. The flex didn't seem to work because it required setting a height to the div.
I also simplified my HTML
Code
.clientsdetail {
text-align: center;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
.clientinfo h3 {
padding-top: 10px;;
}
.clientinfo p {
padding: 0px 30px;
font-size: 15px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-3 nopadding">
<img class="img-responsive" src="img/clients/ivey.jpg">
</div>
<div class="col-md-3 nopadding cinfo">
<div class="clientinfo text-center">
<h3>IVEY</h3>
<p>Clarksville, TN</p>
<div class="social-icons-clients">
<span class="icon-sprite sprite-ig"> </span>
<span class="icon-sprite sprite-fb"> </span>
<span class="icon-sprite sprite-gp"> </span>
<span class="icon-sprite sprite-sc"> </span>
<span class="icon-sprite sprite-tw"> </span>
</div>
</div>
</div>
<div class="col-md-3 nopadding cinfo">
<img class="img-responsive" src="img/clients/rufus.jpg">
</div>
<div class="col-md-3 nopadding">
<div class="clientinfo text-center">
<h3>RUFUS DAWKINS</h3>
<p>Clarksville, TN</p>
<div class="social-icons-clients">
<span class="icon-sprite sprite-ig"> </span>
<span class="icon-sprite sprite-fb"> </span>
<span class="icon-sprite sprite-gp"> </span>
<span class="icon-sprite sprite-sc"> </span>
<span class="icon-sprite sprite-tw"> </span>
</div>
</div>
</div>
</div>
You can use flex properties to make your content to center.
for more details, you can check
Flexbox: center horizontally and vertically
(UPDATED)
You can use the Pseudoclass to select the 2 and 4 div.
.row div:nth-child(2n) {
/* Your CSS Style */
}
If the content inside the 2 and 4 div are inline/inline-block, just use text-align: center;.
Demo
Here is the simple demo for the pseudoclass.
.row > div {
padding: 10px;
}
.row > div:nth-child(2n) {
color: #fff;
background: red;
text-align: center;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
}
<div class="row">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
</div>
Hope this is helpful for you.
Thanks.
Try a different approach. Bootstrap's floating grid system will not get you where you want.
First, remove row and col- classes so you have something like this:
<div class="my-row">
<div></div>
<div></div>
<div></div>
</div>
Then use CSS to achieve the same result as before, but with the content aligned center:
#media (min-width: 992px) {
.my-row {
display: flex;
align-items: stretch;
}
.my-row > div {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
}
If you are using SASS, then replace hardcoded 992px with the #screen-md-min variable.
Here's a JsFiddle of your simplified example:
https://jsfiddle.net/mpnz9b30/1/
<div class="col-md-6 nopadding cinfo">
<div class="clientinfo">
<h3>IVEY</h3>
<p>Clarksville, TN</p>
<div class="social-icons-clients">
<span class="icon-sprite sprite-ig"> </span>
<span class="icon-sprite sprite-fb"> </span>
<span class="icon-sprite sprite-gp"> </span>
<span class="icon-sprite sprite-sc"> </span>
<a href="https://twitter.com/contracoda" target="_blank">
<span class="icon-sprite sprite-tw"> </span>
</a>
</div>
</div>
</div>
i have code html using angular material library:
<div layout="row" layout-wrap style="background: yellow; ">
<div ng-repeat="pro in Products" >
<md-card class="cardProduct" >
<img ng-src={{pro.Image1}} class="md-card-image imageProduct">
</md-card>
</div>
</div>
it shows: enter image description here
I want it align center, and the fourth image is in the left, not center.
Thank you so much.
Since you are using angular material you can easily do this with flex-box
It will help if there are more images to come
Change your html code as
HTML:
<div layout="row" layout-wrap style="background: yellow; ">
<div class="prod-container" ng-repeat="pro in Products" >
<md-card class="cardProduct" flex="30" >
<img ng-src={{pro.Image1}} class="md-card-image imageProduct">
</md-card>
</div>
</div>
CSS:
.prod-container{
display: flex;
flex-wrap: wrap;
justify-contents: flex-start;
}
you can also give css for the cards by removing flex=30 from the html code
<md-card class="cardProduct">
and the CSS will be
.cardProduct{
min-width: 30%;
flex: 1;
}
Make the parent container (layout="row") have the css property:
text-align: center;
And the ng-repeated containers have the property:
display: inline-block;
and in case you have any text for those containers might want a:
text-align: left;
just make the text-align property of the parent of the images to center.
text-align:center;