Circle in between 2 div - css

how do I achieve this in CSS.
Currently I have tried everything I know but failed. My basic structure was like this.
<div>
<div class='pink-div'></div>
<div class='blue-cirle-div'>
<div> Some Text </div>
</div>
<div class='yellow-div'></div>
</div>
Thanks.

Here you go.
The HTML:
<div class="main">
<div class='pink-div'> </div>
<div class='blue-cirle-div'>
<div class="forsomeText">Some Text</div>
</div>
<div class='yellow-div'> </div>
</div>
The CSS:
.main{position:relative;}
.pink-div {
background: none repeat scroll 0 0 #feaec9;
height: 110px;
}
.yellow-div {
background: none repeat scroll 0 0 #b5e51d;
height: 110px;
}
.blue-cirle-div {
background: none repeat scroll 0 0 #3f47cc;
border-radius: 110px;
display: block;
height: 140px;
left: 50%;
margin: 0 auto;
position: absolute;
text-align: center;
top: 18%;
vertical-align: middle;
}
.forsomeText {
display: block;
margin: 0 auto;
padding: 60px 37px 37px;
text-align: center;
vertical-align: middle;
}
The live fiddle link:
WORKING DEMO
I hope this helps.

According to your tastes and needs, you may choose one of the 4 following templates:
#1 Center circle using position, top, bottom, left, right and margin properties
.main {
/* prepare .main to center .blue-circle */
position: relative;
}
.pink-div {
background-color: pink;
height: 100px;
}
.yellow-div {
background-color: yellow;
height: 100px;
}
.blue-circle {
background-color: blue;
border-radius: 50%;
height: 140px;
width: 140px;
/* center .blue-circle inside .main */
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
/* center .text-div inside .blue-circle using flexbox */
display: flex;
align-items: center;
justify-content: center;
}
<div class="main">
<div class="pink-div"></div>
<div class="blue-circle">
<div class="text-div">Some Text</div>
</div>
<div class="yellow-div"></div>
</div>
#2 Center circle using position, top, left, margin-top and margin-left properties
.main {
height: 200px;
/* prepare .main to center .blue-circle */
position: relative;
}
.pink-div {
background-color: pink;
height: 50%;
}
.yellow-div {
background-color: yellow;
height: 50%;
}
.blue-circle {
background-color: blue;
border-radius: 50%;
height: 140px;
width: 140px;
/* center .blue-circle inside .main */
position: absolute;
top: 50%;
left: 50%;
margin-top: -70px;
margin-left: -70px;
/* center .text-div inside .blue-circle using display: table */
display: table;
}
.text-div {
display: table-cell;
text-align: center;
vertical-align: middle;
}
<div class="main">
<div class="pink-div"></div>
<div class="blue-circle">
<div class="text-div">Some Text</div>
</div>
<div class="yellow-div"></div>
</div>
#3 Center circle using position, top, left and transform properties
.main {
height: 200px;
/* prepare .main to center .blue-circle */
position: relative;
}
.pink-div {
background-color: pink;
height: 50%;
}
.yellow-div {
background-color: yellow;
height: 50%;
}
.blue-circle {
background-color: blue;
border-radius: 50%;
height: 140px;
width: 140px;
/* center .blue-circle inside .main */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/* center .text-div inside .blue-circle using display: table */
display: table;
}
.text-div {
display: table-cell;
text-align: center;
vertical-align: middle;
}
<div class="main">
<div class="pink-div"></div>
<div class="blue-circle">
<div class="text-div">Some Text</div>
</div>
<div class="yellow-div"></div>
</div>
#4 Center circle using Flexbox
Note that the following HTML snippet is different from the previous ones.
.main {
height: 200px;
background: linear-gradient(180deg, pink 50%, yellow 50%);
/* prepare .main to center .blue-circle */
display: flex;
align-items: center;
justify-content: center;
}
.blue-circle {
background-color: blue;
border-radius: 50%;
height: 140px;
width: 140px;
/* prepare .blue-circle to center .text-div */
position: relative;
}
.text-div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="main">
<div class="blue-circle">
<div class="text-div">Some Text</div>
</div>
</div>

It depends on the rest of your page & layout, but basically you need a square element with border-radius:50%;
A rough example
.pink-div, .yellow-div {
width:100%;
height:100px;
background-color:#FEAEC9;
}
.yellow-div {
background-color:#B5E51D;
}
.blue-cirle-div {
text-align:center;
position:absolute;
left:150px;
top:60px;
line-height:100px;
height:100px;
width:100px;
border-radius:50%;
background-color:#3F47CC;
}
http://jsfiddle.net/9dhdd9ue/

Use one div with CSS gradient instead of two divs.
Also, I used display:table and display:table-cell for vertical align.
.parent{
height: 500px; /* some height */
background: #ff32e3; /* Old browsers */
background: -moz-linear-gradient(top, #ff32e3 0%, #ff32e3 50%, #ff32e3 50%, #ff32e3 50%, #9ddd77 50%, #9ddd77 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ff32e3), color-stop(50%,#ff32e3), color-stop(50%,#ff32e3), color-stop(50%,#ff32e3), color-stop(50%,#9ddd77), color-stop(100%,#9ddd77)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ff32e3 0%,#ff32e3 50%,#ff32e3 50%,#ff32e3 50%,#9ddd77 50%,#9ddd77 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ff32e3 0%,#ff32e3 50%,#ff32e3 50%,#ff32e3 50%,#9ddd77 50%,#9ddd77 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ff32e3 0%,#ff32e3 50%,#ff32e3 50%,#ff32e3 50%,#9ddd77 50%,#9ddd77 100%); /* IE10+ */
background: linear-gradient(to bottom, #ff32e3 0%,#ff32e3 50%,#ff32e3 50%,#ff32e3 50%,#9ddd77 50%,#9ddd77 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff32e3', endColorstr='#9ddd77',GradientType=0 ); /* IE6-9 */
display:table;
width:100%;
}
.parent>div{
display:table-cell;
vertical-align:middle;
text-align:center;
width:100%;
}
.parent>div>span{
background:aqua;
border-radius: 50%;
padding: 50px;
}
<div class="parent">
<div>
<span>circle</span>
</div>
</div>
JSFiddle
Use Ultimate CSS Gradient Generator for gradients.

Here is the complete solution
HTML
<div class="wrapper">
<div class='pink-div'></div>
<div class='blue-cirle-div'>
</div>
<div class='yellow-div'></div>
</div>
CSS
.wrapper {
width:600px;
margin: 0 auto;
height:600px;
position:relative;
}
.pink-div {
width:600px;
height:300px;
background:pink;
float:left;
}
.yellow-div {
width:600px;
height:300px;
background:yellow;
float:left;
}
.blue-cirle-div {
width:300px;
height:300px;
border-radius:150px;
background:blue;
position:absolute;
top:0px;
bottom:0px;
left:0px;
right:0px;
margin:auto;
}
Check the Demo

Related

Full blled background onto two side-by-side Boxes

I'd need to have two side-by-side Boxes, with background that is extended to full page width, but text content should be contained inside main container that is limited a specific size.
I tried the following HTML code:
<div class="wrapper">
<div class="container">
<section class="left">LEFT</section>
<section class="right">RIGHT</section>
</div>
</div>
and here the sCSS:
.wrapper {
background: lightgray;
padding-block: 10px;
overflow: hidden;
}
.container {
border: dotted 1px red;
display: flex;
max-width: 900px;
margin-inline: auto;
section {
padding-block: 100px;
border: solid 1px blue;
flex: 1;
position: relative;
isolation: isolate;
&.left {
background: green;
&:before {
content:"";
display: block;
background: green;
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 500%;
z-index: -1;
}
}
&.right {
background: orange;
&:before {
content:"";
display: block;
background: orange;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 500%;
z-index: -1;
}
}
}
}
Here a working example. Have you any suggestion to have a better solution with almost the same result?
You could add an extra div inside your wrapper and use a linear gradient on it:
.wrapper {
background: lightgray;
padding-block: 10px;
overflow: hidden;
}
.background {
background: linear-gradient(to right, green, green 50%, orange 50%, orange 100%);
}
.container {
border: dotted 1px red;
display: flex;
max-width: 900px;
margin-inline: auto;
}
.column {
width: 50%;
}
<div class="wrapper">
<div class="background">
<div class="container">
<section class="column left">LEFT</section>
<section class="column right">RIGHT</section>
</div>
</div>
</div>

CSS: Alternative min()

According to the size of the div, I want to set the background-position-x and the background-size.
Using only CSS without JS or JQuery, I use min() which works:
.test {
transition: all 0.5s;
background-image: url(./my-asset.svg);
background-repeat: no-repeat;
background-position-x: min(-50px, -100%);
background-position-y: center;
background-size: min(50px, 100%) 100%;
}
This works properly but only on recent browsers, but I have a Firefox target to v.68 and it is not compatible.
What could be the alternative without using JS or JQuery and only CSS ?
I reproduce what I would like to have in output using min(). Hover the red part to make it work:
body,
html {
height: 100%;
width: 100%;
margin: 5px;
}
#main {
display: flex;
flex-direction: row;
background-color: cyan;
}
.use-px {
width: 300px;
height: 300px;
border: solid 3px black;
}
.use-percentage {
margin-left: 200px;
width: 100px;
height: 300px;
border: solid 3px black;
}
.left-over-image {
width: 25%;
height: 100%;
transition: all 1s;
background-color: red;
background-image: url(https://www.w3schools.com/images/w3schools_green.jpg);
background-repeat: no-repeat;
background-position-x: min(-50px, -100%);
background-position-y: center;
background-size: min(50px, 100%) 100%;
}
.left-over-image:hover {
background-position: left;
}
<html>
<body>
<div id="main">
<div class="use-px">
<!-- It will use 50px, because 25% of 300px is 75px. -->
<div class="left-over-image"></div>
</div>
<div class="use-percentage">
<!-- It will use 100%, because 25% of 100px is 25px. -->
<div class="left-over-image"></div>
</div>
</div>
</body>
</html>
You can consider a trick using pseudo element.
Resize both examples to see that they behave the same:
.box {
height:100px;
width:100px;
border:2px solid;
resize:both;
overflow:hidden;
background:linear-gradient(red,blue) 0/50px 50px no-repeat;
background-position-x: min(4em, 100%);
}
.alt {
height:100px;
width:100px;
border:2px solid;
resize:both;
overflow:hidden;
position:relative;
z-index:0;
}
.alt::before {
content:"";
position:absolute;
background:inherit;
background:linear-gradient(red,blue) 0/50px 50px no-repeat;
background-position-x:100%;
max-width:calc(4em + 50px); /* 4em + width of background */
width:100%;
top:0;
bottom:0;
left:0;
z-index:-1;
}
<div class="box">
</div>
<div class="alt">
</div>
UPDATE
Based on your new code:
body,
html {
height: 100%;
width: 100%;
margin: 0;
overflow: hidden;
}
#main {
display: flex;
flex-direction: row;
background-color: cyan;
}
.use-px {
width: 300px;
height: 300px;
border: solid 1px black;
}
.use-percentage {
width: 100px;
height: 300px;
border: solid 1px black;
}
.left-over-image {
width: 25%;
height: 100%;
background-color: red;
position:relative;
overflow:hidden;
}
.left-over-image::before {
content:"";
position:absolute;
top:0;
bottom:0;
left:0;
width:100%;
max-width:50px;
background-image: url(https://www.w3schools.com/images/w3schools_green.jpg);
background-size: 100% 100%;
transform:translateX(-100%);
transition: all 1s;
}
.left-over-image:hover::before {
transform:translateX(0);
}
<div id="main">
<div class="use-px">
<!-- It will use 50px, because 25% of 300px is 75px. -->
<div class="left-over-image"></div>
</div>
<div class="use-percentage">
<!-- It will use 100%, because 25% of 100px is 25px. -->
<div class="left-over-image"></div>
</div>
</div>

(HTML CSS) trying to center footer links

I made footer, using absolute element, I created 3 group of links, that lay on top of each other.
my problem is when screen size is going down they mess up and the right side group is gone.
I am trying to use flex...
I did the same thing with the rest of the main page and it worked.
freecodewiki.com is the page if you want to see it.
I also tried float method but it is even worse.
* {
box-sizing: border-box;
}
#footer {
display: flex;
width: 100%;
flex-flow: row wrap;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
text-align: center;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
transition: all 0.9s;
left: 0;
bottom: 0;
width: relative;
}
.footer {
height: relative;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
}
.footer p {
text-align: center;
position: relative;
}
.footer a {
display: block;
padding-left: 350px;
position: relative;
}
.webdeveloper {
color: black;
}
.footerbox2 a {
position: relative;
}
.footerbox1 a {
position: relative;
}
.footerbox3 a {
position: relative;
}
.footerbox2 h3 {
padding-left: 350px;
position: relative;
}
.footerbox1 h3 {
padding-left: 350px;
position: relative;
}
.footerbox3 h3 {
position: relative;
padding-left: 350px;
}
.footerbox {
display: flex;
align-items: center;
padding-top: 20px;
}
.hr2 {
border-top: 0.1px #d8e3f5
}
<div class="footer">
<hr>
<footer>
<p>FreeCodeWiki.com © 2020, all right reserved </p>
<div class="footerbox">
<div class="footerbox1">
<h3>Learn programming</h3>
how to collection
learn html free
learn Javascript free
learn Python free
</div>
<div class="footerbox2">
<h3>About</h3>
Contact us
Report bug
About us
Check our live code editor
</div>
<div class="footerbox3">
<h3>Web development courses</h3>
Create buttons
Create sidebar menu
HTML Editors
Learn javascript concepts
</div>
</div>
<br>
</footer>
</div>
Welcome to SO!
You are using wrong approach like padding to create
space between item due to which layout messed up I updated the code
below Using margin on child elements please have a look
* {
box-sizing: border-box;
}
#footer {
display: flex;
width: 100%;
flex-flow: row wrap;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
text-align: center;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
transition: all 0.9s;
left: 0;
bottom: 0;
width: relative;
}
.footer {
height: relative;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
}
.footer p {
text-align: center;
position: relative;
}
.footer a {
display: block;
position: relative;
}
.webdeveloper {
color: black;
}
.footerbox2 a {
position: relative;
}
.footerbox1 a {
position: relative;
}
.footerbox3 a {
position: relative;
}
.footerbox2 h3 {
position: relative;
}
.footerbox1 h3 {
position: relative;
}
.footerbox3 h3 {
position: relative;
}
.footerbox {
display: flex;
align-items: center;
padding-top: 20px;
}
.footerbox > div {
flex:1 1 auto;
text-align:center;
margin:5px;
}
.hr2 {
border-top: 0.1px #d8e3f5
}
<div class="footer">
<hr>
<footer>
<p>FreeCodeWiki.com © 2020, all right reserved </p>
<div class="footerbox">
<div class="footerbox1">
<h3>Learn programming</h3>
how to collection
learn html free
learn Javascript free
learn Python free
</div>
<div class="footerbox2">
<h3>About</h3>
Contact us
Report bug
About us
Check our live code editor
</div>
<div class="footerbox3">
<h3>Web development courses</h3>
Create buttons
Create sidebar menu
HTML Editors
Learn javascript concepts
</div>
</div>
<br>
</footer>
</div>
Use bootstrap grid and remove padding-left: 350px from css
* {
box-sizing: border-box;
}
#footer {
display: flex;
width: 100%;
flex-flow: row wrap;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
text-align: center;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
transition: all 0.9s;
left: 0;
bottom: 0;
width: relative;
}
.footer {
height: relative;
background: linear-gradient(to bottom, #3781a4 0%, #4eb5e5 100%);
color: black;
}
.footer p {
text-align: center;
position: relative;
}
.footer a {
display: block;
// padding-left: 350px;
position: relative;
}
.webdeveloper {
color: black;
}
.footerbox2 a {
position: relative;
}
.footerbox1 a {
position: relative;
}
.footerbox3 a {
position: relative;
}
.footerbox2 h3 {
//padding-left: 350px;
position: relative;
}
.footerbox1 h3 {
// padding-left: 350px;
position: relative;
}
.footerbox3 h3 {
position: relative;
//padding-left: 350px;
}
.footerbox {
display: flex;
align-items: center;
padding-top: 20px;
}
.hr2 {
border-top: 0.1px #d8e3f5
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<div class="footer container">
<hr>
<footer>
<p>FreeCodeWiki.com © 2020, all right reserved </p>
<div class="row">
<div class="footerbox1 col-sm-3">
<h3>Learn programming</h3>
how to collection
learn html free
learn Javascript free
learn Python free
</div>
<div class="footerbox2 col-sm-3">
<h3>About</h3>
Contact us
Report bug
About us
Check our live code editor
</div>
<div class="footerbox3 col-sm-3">
<h3>Web development courses</h3>
Create buttons
Create sidebar menu
HTML Editors
Learn javascript concepts
</div>
</div>
<br>
</footer>
</div>

Background color diagonal split responsive

I'm using Bootstrap.
I need to achieve this result :
For that I started doing this :
<body>
<div id="diagonal-bg"></div>
</body>
#diagonal-bg{
position: absolute;
left: -800px;
width: 200%;
min-height: 700px;
background-image: -webkit-linear-gradient(118deg, #fff 35%, #8aa8ec 35%);
}
It works almost because as soon as I resize my window here is what I get :
How can I have distances A and B to be always the same across different size of screen/window, to make it responsive.
Thanks
You can find the solution below interested for
Background color diagonal split responsive
.shape {
width:400px;
margin:0 auto;
}
.top {
height:0;
border-width:150px 400px 0px 0px;
border-style:solid;
border-color:#d71f55 transparent #d71f55 transparent;
}
.bottom {
height: 50px;
background-color:#d71f55;
}
/* Support transparent border colors in IE6. */
* html .top {
filter:chroma(color=#123456);
border-top-color:#123456;
border-left-color:#123456;
}
<div class="shape">
<div class="bottom"></div>
<div class="top"></div>
</div>
I've resolved my issue :
<div class="background">
<div class="top"></div>
<div class="bottom"></div>
</div>
.background {
position: absolute;
width: 100%;
margin: 0 auto;
}
.top {
height: 100px;
background-color: #23d6c5;
}
.bottom {
width: 100%;
height: 500px;
background: linear-gradient(to right bottom, #2f3441 50%, transparent 50%);
}
body{
background-color: white;
}
.background {
position: absolute;
width: 100%;
margin: 0 auto;
}
.top {
height: 100px;
background-color: #2f3441;
}
.bottom {
width: 100%;
height: 500px;
background: linear-gradient(to right bottom, #2f3441 50%, transparent 50%);
}
<div class="background">
<div class="top"></div>
<div class="bottom"></div>
</div>

Angular 2 Material - How To Center Progress Spinner

I have implemented the Angular 2 progress spinner from the below link
https://github.com/angular/material2/tree/master/src/lib/progress-spinner
I would like to have it centered, however, the only way I can seem to get it to work is to remove the
display: block
from the CSS. However, this causes the spinner to appear huge on the page.
Any advice would be great.
just add margin rule:
<md-progress-spinner style="margin:0 auto;"
mode="indeterminate"></md-progress-spinner>
plunker: http://plnkr.co/edit/sEiTZt830ZE7rqjq9YXO?p=preview
UPDATE
Just wanted to share and demonstrate 6 other general centering solutions
FLEX:
.center {
display: flex;
justify-content: center;
align-items: center;
}
/* +++++++ STYLES +++++++ */
.wrapper {
height: calc(100vh - 20px);
background: red;
}
.inner {
background: green;
color: white;
padding: 12px;
}
<div class="wrapper center">
<div class="inner">INNER CONTENT</div>
</div>
GRID:
.center {
display: grid;
place-items: center;
}
/* +++++++ STYLES +++++++ */
.wrapper {
height: calc(100vh - 20px);
background: red;
}
.inner {
background: green;
color: white;
padding: 12px;
}
<div class="wrapper center">
<div class="inner">INNER CONTENT</div>
</div>
LINE HEIGHT + TEXT ALIGN (will not work as desired for multiple lines, use white-space: nowrap; to ensure one line)
.center {
line-height: calc(100vh - 20px);
text-align: center;
}
/* +++++++ STYLES +++++++ */
.wrapper {
background: red;
white-space: nowrap;
}
.inner {
background: green;
color: white;
padding: 12px;
display: inline;
}
<div class="wrapper center">
<div class="inner">INNER CONTENT</div>
</div>
USING ABSOLUTE, TOP, LEFT and TRANSFORM TRANSLATE
.center.wrapper {
position: relative;
}
.center .inner {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* +++++++ STYLES +++++++ */
.wrapper {
height: calc(100vh - 20px);
background: red;
}
.inner {
background: green;
color: white;
padding: 12px;
}
<div class="wrapper center">
<div class="inner">INNER CONTENT</div>
</div>
USING ABSOLUTE, TOP, LEFT, BOTTOM, RIGHT and MARGIN AUTO (mentioned by György Balássy). Note: inner div width needs to be set.
.center.wrapper {
position: relative;
}
.center .inner {
position: absolute;
inset: 0;
margin: auto;
}
/* +++++++ STYLES +++++++ */
.wrapper {
height: calc(100vh - 20px);
background: red;
}
.inner {
background: green;
color: white;
padding: 12px;
height: max-content;
width: max-content;
}
<div class="wrapper center">
<div class="inner">INNER CONTENT</div>
</div>
Using TABLE
.center {
display: table-cell;
text-align: center;
vertical-align: middle;
}
/* +++++++ STYLES +++++++ */
.wrapper {
height: calc(100vh - 20px);
width: calc(100vw - 20px);;
background: red;
}
.inner {
background: green;
color: white;
padding: 12px;
display: inline-block;
}
<div class="wrapper center">
<div class="inner">INNER CONTENT</div>
</div>
This CodePen helped me to create a page-centered spinner with Material Design in Angular 4: https://codepen.io/MattIn4D/pen/LiKFC
Component.html:
<div class="loading-indicator">
<mat-progress-spinner mode="indeterminate" color="accent"></mat-progress-spinner>
</div>
Component.css:
/* Absolute Center Spinner */
.loading-indicator {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: show;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
/* Transparent Overlay */
.loading-indicator:before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.3);
}
The first answer doesn't work unless height is set in a parent element.
I fixed it using fxFlex
<div fxLayout="row" fxLayoutAlign="space-around center" style="height:100%">
<mat-spinner diameter="50" strokeWidth="5"></mat-spinner>
</div>
I am using angular 6 with material 2+ and used that CSS code:
.mat-spinner {
position: relative;
margin-left: 50%;
margin-right: 50%;
}
Source: Angular Wiki
For me, this worked the best:
Component:
<div class="center">
<mat-spinner> </mat-spinner>
</div>
Scss:
/** Can be used to center any element */
.center {
left: 50%;
position: absolute;
top: 50%;
transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
}
you can use with grid as well :
.wrapper {
display: grid;
place-content: center;
height: calc(100vh - 20px);
background: red;
}

Resources