I am making a solar system website in pure code with no images used. The problem is that I can't figure out how to get stars in the background. I'm trying to get something like a yellow spread-out polka dot pattern on a black background. This is my code (repeat div and styling for every other planet).
html,
body {
width: 100%;
height: 100%;
background-color: black;
}
#sun {
position: absolute;
top: 50%;
left: 50%;
height: 200px;
width: 200px;
margin-top: -100px;
margin-left: -100px;
border-color: orange;
border-width: 2px;
border-style: solid;
border-radius: 50%;
box-shadow: 0 0 64px yellow;
background-color: yellow;
}
#mercury {
position: absolute;
top: 0;
left: 50%;
height: 10px;
width: 10px;
margin-left: -5px;
margin-top: -5px;
border-radius: 50%;
background-color: #ffd9b3;
}
#mercury-orbit {
position: absolute;
top: 50%;
left: 50%;
width: 260px;
height: 260px;
margin-top: -130px;
margin-left: -130px;
border-width: 2px;
border-style: dotted;
border-color: white;
border-radius: 50%;
-webkit-animation: spin-right 22s linear infinite;
-moz-animation: spin-right 22s linear infinite;
-ms-animation: spin-right 22s linear infinite;
-o-animation: spin-right 22s linear infinite;
animation: spin-right 22s linear infinite;
}
#-webkit-keyframes spin-right {
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes spin-right {
100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<div id="sun"></div>
<div id="mercury-orbit">
<div id="mercury"></div>
</div>
From this, a nice starry night.
background-color:black;
background-image:
radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px),
radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 40px),
radial-gradient(rgba(255,255,255,.4), rgba(255,255,255,.1) 2px, transparent 30px);
background-size: 550px 550px, 350px 350px, 250px 250px, 150px 150px;
background-position: 0 0, 40px 60px, 130px 270px, 70px 100px;
I found a pure CSS solution thanks to this code pen. This would make your website look like this - unfortunately I can't copy-paste the entire CSS in, as it's far too long (over 40,000 characters and StackOverflow only permits me to paste 30,000 for a code snippet). The original code was generated with SASS, and compiled, it's ridiculously long.
<div id='stars'></div>
<div id='stars2'></div>
<div id="sun"></div>
<div id="mercury-orbit">
<div id="mercury"></div>
</div>
The SASS code generating these stars:
// n is number of stars required
#function multiple-box-shadow ($n)
$value: '#{random(2000)}px #{random(2000)}px #FFF'
#for $i from 2 through $n
$value: '#{$value} , #{random(2000)}px #{random(2000)}px #FFF'
#return unquote($value)
$shadows-small: multiple-box-shadow(700)
$shadows-medium: multiple-box-shadow(200)
$shadows-big: multiple-box-shadow(100)
#stars
width: 1px
height: 1px
background: transparent
box-shadow: $shadows-small
Related
I'm doing a project with Flutter web. When Flutter web is opened the first time it takes a few seconds to load so I want to show a spinner loader. I've tried adding the following to the index.html:
<div class="loading">
<div class="loader" />
</div>
with these styles:
.loading {
display: flex;
justify-content: center;
align-items: center;
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-image: url("img/images.jpeg");
background-size: contain;
resize: both;
padding: 25px;
}
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border: 15px solid;
border-top: 16px solid #8a2245;
border-right: 16px solid white;
border-bottom: 16px solid #8a2245;
border-left: 16px solid white;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
But background-image has bad size and I want it to be small and located in de middle of spinner. How can I do that?
You can set size of background image using background-size property in px (pixel) or % (percentage). And align the image to center using background-position: center;
I planned to do like a drop of water travelling around a location icon.Tried a bit,but i couldn't let the water revolve perfectly around the location icon as I'm not much into animation stuffs.
Here is my code,
<div id ="location">
<div id = "droplet"></div>
</div>
#location {
background: black;
height: 200px;
width: 200px;
border-radius: 50% 50% 50% 0;
transform:rotate(-45deg);
}
#location::after{
content '';
width 14px;
height 14px;
margin: 8px 0 0 8px;
background: #89849b;
position absolute;
border-radius 50%;
}
#droplet {
background: #2c3e50;
height: 50px;
width: 50px;
border-radius:50%;
border: 5px double darkgreen;
margin: 23%;
-webkit-animation-name: rotate;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration:4s
}
#-webkit-keyframes rotate{
0%{-webkit-transform: rotate(-90deg) rotateY(0) scale(0)}
30%{-webkit-transform: rotate(90eg) rotateY(0) scale(0.7)}
80%{-webkit-transform: rotate(180deg) rotateY(0) scale(1)}
100%{-webkit-transform: rotate(-360deg) rotateY(0) scale(0)}
}
How to make the droplet revolves within the location icon(but it should move around its edges)
I want to add an loader in my angular 4 PWA. https://www.w3schools.com/howto/howto_css_loader.asp this loader is visible till all the contents of page get loaded.
<div *ngIf="isLoaded" class="loader"></div>
<div class="home-container" [hidden]="isLoaded"></div>
Initially isLoaded is true after loading all contents it will become false.
loader poistion => top => 0, right = 50%, left = 50%, bottom= 100%
.scss file
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #59d4bf; /* green */
border-radius: 50%;
margin: auto;
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
here -stackblitz live code sample
Your should put your css,
margin-right: 50%; or margin-right: auto;
margin-top: 50%;
margin-left: 50%; or margin-right: auto;
your loader
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
margin-left: 50%;
margin-right: 50%;
margin-top: 50%;
}
is it working , Live working code sample
I know it's a noob questioin but I got stuck on this thing.
How to center vertically and horizontally "slide-loading" div in this situation?
.blueimp-gallery > .slides > .slide-loading
Element with class "blueimp-gallery" has position fixed.
Element with class "slides" has position relative.
Element with class "slide-loading" is a simple CSS preloader (without specified position).
.blueimp-gallery > .slides > .slide-loading {
border: 4px solid #f3f3f3;
border-radius: 50%;
border-top: 4px solid #3498db;
width: 60px;
height: 60px;
-webkit-animation: spin 1s linear infinite;
animation: spin 1s linear infinite;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
SOLUTION:
You can achieve this using the transform css property, using the following:
position: absolute;
top: calc(50% - 30px); //minus half the height of your spinner (30px)
left: calc(50% - 30px); //minus half the width of your spinner (30px)
transform: translate(-50%, -50%);
jsFIDDLE
CODE SNIPPET:
body {
margin: 0;
}
* {
box-sizing: border-box;
}
.rulerX,
.rulerY {
position: absolute;
z-index: 9999;
background-color: red;
}
.rulerX {
top: calc(50% - .5px);
height: 1px;
width: 100%;
}
.rulerY {
left: calc(50% - .5px);
width: 1px;
height: 100%;
}
.blueimp-gallery {
position: relative;
border: 3px solid royalblue;
height: 100vh;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.slides {
height: 100%;
border: 3px dotted white;
position: relative;
background-color: #262626;
}
#-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.blueimp-gallery > .slides > .slide-loading {
border: 4px solid #f3f3f3;
border-radius: 50%;
border-top: 4px solid #3498db;
width: 60px;
height: 60px;
-webkit-animation: spin 1s linear infinite;
animation: spin 1s linear infinite;
position: absolute;
top: calc(50% - 30px);
left: calc(50% - 30px);
transform: translate(-50%, -50%);
}
<div class="blueimp-gallery">
<div class="rulerX"></div>
<div class="rulerY"></div>
<div class="slides">
<div class="slide-loading">
</div>
</div>
</div>
This is a css
#loading {
margin: 80px auto;
position: relative;
width: 100px;
height: 100px;
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
border-radius: 50px;
background: #ccc;
font: 12px "Lucida Grande", Sans-Serif;
text-align: center;
line-height: 100px;
color: white;
-webkit-box-shadow: 0 0 5px rgba(0,0,0,0.5);
-moz-box-shadow: 0 0 5px rgba(0,0,0,0.5);
box-shadow: 0 0 5px rgba(0,0,0,0.5);
}
#loading:before {
content: "";
position: absolute;
left: -20px;
top: -20px;
bottom: -20px;
right: -20px;
-webkit-border-radius: 70px;
-moz-border-radius: 70px;
border-radius: 70px;
background: #eee;
z-index: -2;
-webkit-box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
-moz-box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
}
#loading span {
position: absolute;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 80px solid rgba(255,255,255,0.7);
z-index: -1;
top: -28px;
left: 0px;
-webkit-animation: ticktock 5s linear infinite;
-moz-animation: ticktock 5s linear infinite;
animation:ticktock 5s linear infinite;
-webkit-transform-origin: 50px 80px;
-moz-transform-origin: 50px 80px;
transform-origin:50px 80px;
}
#loading strong {
overflow: hidden;
display: block;
margin: 0 auto;
-webkit-animation: expand 2.5s linear infinite;
-moz-animation: expand 2.5s linear infinite;
animation:expand 2.5s linear infinite;
}
#-webkit-keyframes expand {
0% {
width: 0;
}
100% {
width: 60px;
}
}
#-webkit-keyframes ticktock {
0% {
-webkit-transform: rotate(0);
-ms-transform: rotate(0);
transform: rotate(0);
-moz-transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
-moz-transform: rotate(360deg);
}
}
#-moz-keyframes expand {
0% {
width: 0;
}
100% {
width: 60px;
}
}
#-moz-keyframes ticktock {
0% {
-webkit-transform: rotate(0);
-ms-transform: rotate(0);
transform: rotate(0);
-moz-transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform: rotate(360deg);
-moz-transform: rotate(360deg);
}
}
#keyframes ticktock {
0% {
-webkit-transform: rotate(0);
-ms-transform: rotate(0);
transform: rotate(0);
-moz-transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
-ms-transform: rotate(360deg);
transform:rotate(360deg);
-moz-transform: rotate(360deg);
}
}
#keyframes expand {
0% {
width: 0;
}
100% {
width: 60px;
}
}
this is the html
<div id="loading"><strong>loading...</strong><span></span></div>
The problem that this is the result
http://jsfiddle.net/jtrax/
It is working good and the circle is rotating
But when I add a completely separate css the circle is disappear, this is a jfiddle after adding the css which is not related to the circle
http://jsfiddle.net/HSJ3j/
Before adding the unrelated css:
After adding the unrelated css:
I forgot to tell you that the wrong is happening in the span in the html
Edit
when I change the z of loading span to 1 and the z of #loading:before to 0, I got this result
I restructured your loading div so it makes more sense and easier to understand
http://jsfiddle.net/jtrax/1/
<div id="loading">
<span></span>
<div class="inner"><strong>loading...</strong></div>
</div>
You can check the css in the fiddle. The spinning span might need more adjustment to centre it but you get the idea
UPDATED fiddle:
http://jsfiddle.net/HSJ3j/3/
If you look at the stacking order, the loading text should be the highest, then the grey smaller circle, then the spinning span and finally the outer bigger circle. Construct your div according to that and it makes things much easier
It's just an arrangement issue.
Your fieldset tag is over your animation. Try to arrange your fieldset to be styled with z-index:-1;.