Placing an image inside irregular shaped div - html

I have sets of skewed divs that I would like a separate image in each. Is this possible? If I try to place an image inside, the image is also skewed and looks distorted. How can I fix this? Essentially I would like an image in the black colored spaced. Please and thank you for all your help in advance!!!
.wrap {
position: relative;
width: 95vw;
height: 20vw;
margin-right: auto;
margin-left: auto;
background: white;
overflow: hidden;
}
.button-skewed .button {
width: 98%;
height: 100%;
background: black;
display: inline-block;
text-align: center;
box-shadow: inset 0 0 0 1vw #008080, inset 0 0 0 1.1vw #fff;
}
.button-skewed .button:hover ~ span {
background: #007a7a !important;
}
.button-skewed .button:hover ~ span:before {
background: #007a7a !important;
}
.button-skewed .button:hover {
background: #007a7a;
box-shadow: inset 0 0 0 1vw #007a7a, inset 0 0 0 1.1vw #fff;
}
.button-skewed .button.left {
margin-left: -1.7vw;
position: absolute;
left: 0%;
transform: skewX(-20deg) translate(-50%, -50%);
top: 50%;
}
.button-skewed .button.right {
margin-right: 1.7vw;
width: 200%;
position: absolute;
transform: skewX(-20deg) translate(100%, -50%);
top: 50%;
right: 50%;
}
.button-skewed .button .titleleft {
position: absolute;
top: 50%;
left: 71%;
transform: skewX(20deg) translate(-50%, -50%);
display: inline-block;
font-family: montserrat;
color: white;
font-size: 2.6vw;
text-shadow: 2px 2px 5px #000;
}
.button-skewed .button .titleright {
position: absolute;
top: 50%;
left: 12%;
transform: skewX(20deg) translate(-50%, -50%);
display: inline-block;
font-family: montserrat;
color: white;
font-size: 2.6vw;
text-shadow: 2px 2px 5px #000;
}
.button-skewed img {
position: relative;
background-size: cover;
}
.mask-outer-left {
position: absolute;
left: 0;
top: 0;
height: calc(100% - 2vw);
margin-top: 1vw;
margin-bottom: 1vw;
}
.mask-outer-left:before {
content: '';
background: white;
position: absolute;
height: 200%;
width: 100%;
top: 50%;
left: 49%;
transform: translate(-50%, -50%);
}
.mask-outer-right {
position: absolute;
right: 0;
top: 0;
height: calc(100% - 2vw);
margin-top: 1vw;
margin-bottom: 1vw;
}
.mask-outer-right:before {
content: '';
background: white;
position: absolute;
height: 200%;
width: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="wrap">
<div class="button-skewed"><a class="button left" href="#"><span class="titleleft">title here</span></a><span class="mask mask-outer-left"></span><a class="button right" href="#"><span class="titleright">title here</span></a><span class="mask mask-outer-right"></span></div>
</div>
<br>
<div class="wrap">
<div class="button-skewed"><a class="button left" href="#"><span class="titleleft">title here</span></a><span class="mask mask-outer-left"></span><a class="button right" href="#"><span class="titleright">title here</span></a><span class="mask mask-outer-right"></span></div>
</div>

You may simply add a second css class which skews in the opposite direction. Perhaps someone has a more elegant solution:
.button-skewed .button img {
transform: skewX(20deg)
}
.wrap {
position: relative;
width: 95vw;
height: 20vw;
margin-right: auto;
margin-left: auto;
background: white;
overflow: hidden;
}
.button-skewed .button {
width: 98%;
height: 100%;
background: black;
display: inline-block;
text-align: center;
box-shadow: inset 0 0 0 1vw #008080, inset 0 0 0 1.1vw #fff;
}
.button-skewed .button:hover ~ span {
background: #007a7a !important;
}
.button-skewed .button:hover ~ span:before {
background: #007a7a !important;
}
.button-skewed .button:hover {
background: #007a7a;
box-shadow: inset 0 0 0 1vw #007a7a, inset 0 0 0 1.1vw #fff;
}
.button-skewed .button.left {
margin-left: -1.7vw;
position: absolute;
left: 0%;
transform: skewX(-20deg) translate(-50%, -50%);
top: 50%;
}
.button-skewed .button.right {
margin-right: 1.7vw;
width: 200%;
position: absolute;
transform: skewX(-20deg) translate(100%, -50%);
top: 50%;
right: 50%;
}
.button-skewed .button .titleleft {
position: absolute;
top: 50%;
left: 71%;
transform: skewX(20deg) translate(-50%, -50%);
display: inline-block;
font-family: montserrat;
color: white;
font-size: 2.6vw;
text-shadow: 2px 2px 5px #000;
}
.button-skewed .button .titleright {
position: absolute;
top: 50%;
left: 12%;
transform: skewX(20deg) translate(-50%, -50%);
display: inline-block;
font-family: montserrat;
color: white;
font-size: 2.6vw;
text-shadow: 2px 2px 5px #000;
}
.button-skewed img {
position: relative;
background-size: cover;
}
.mask-outer-left {
position: absolute;
left: 0;
top: 0;
height: calc(100% - 2vw);
margin-top: 1vw;
margin-bottom: 1vw;
}
.mask-outer-left:before {
content: '';
background: white;
position: absolute;
height: 200%;
width: 100%;
top: 50%;
left: 49%;
transform: translate(-50%, -50%);
}
.mask-outer-right {
position: absolute;
right: 0;
top: 0;
height: calc(100% - 2vw);
margin-top: 1vw;
margin-bottom: 1vw;
}
.mask-outer-right:before {
content: '';
background: white;
position: absolute;
height: 200%;
width: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.button-skewed .button img {
transform: skewX(20deg)
}
<div class="wrap">
<div class="button-skewed"><a class="button left" href="#"><img src="https://fxfactory.com/downloads/docs/noiseindustries/fxfactorypro/Thumbnails/Stripes.jpg"/><span class="titleleft">title here</span></a><span class="mask mask-outer-left"></span><a class="button right" href="#"><span class="titleright">title here</span></a><span class="mask mask-outer-right"></span></div>
</div>
<br>
<div class="wrap">
<div class="button-skewed"><a class="button left" href="#"><span class="titleleft">title here</span></a><span class="mask mask-outer-left"></span><a class="button right" href="#"><span class="titleright">title here</span></a><span class="mask mask-outer-right"></span></div>
</div>

Related

How to Overly Text and Button on an Image

I'm trying to place Text and button on an image like this. Can someone help with this.
this is what I have tried. The thing is it does render properly in outlook email
CSS:
.container {
position: relative;
width: 100%;
max-width: 400px;
}
.container img {
width: 100%;
height: auto;
}
.container .btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #55A646;
color: white;
font-size: 16px;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
}
.container .btn:hover {
background-color: #55A646 ;
}
HTML:
<div class="container">
<img src="http://image.com" alt="" style="width:100%">
<button class="btn">Button</button>
</div>
Folow The link: https://www.w3schools.com/howto/howto_css_image_text.asp
/* Container holding the image and the text */
.container {
position: relative;
text-align: center;
color: white;
}
/* Bottom center text */
.bottom-center {
position: absolute;
bottom: 8px;
left: 45%;
}
/* Centered text */
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="container">
<img src="https://cdn.searchenginejournal.com/wp-content/uploads/2019/07/the-essential-guide-to-using-images-legally-online-760x400.png" alt="Snow" style="width:100%;">
<div class="bottom-center">
<button>Bottom Center</button>
</div>
<div class="centered">Centered</div>
</div>
try this instead,
.container {
position: relative;
width: 100%;
max-width: 400px;
}
.container img {
width: 100%;
height: 100%
}
.container .btn {
position: absolute;
bottom: 10px;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #55A646;
color: white;
font-size: 16px;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
}
.container .btn:hover {
background-color: #00cc00 ;
}
h4{
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
color: #fff;
background:#111;
padding: 7px;
}
<div class="container">
<img src="https://i.stack.imgur.com/bf3jO.png" alt="" style="width:100%">
<h4>The table Fan</h4>
<button class="btn">Fan</button>
</div>

Container loses top margin when element is made visible

I was trying to participate in a CSS challenge when this occurred. Everything seems working as expected, however when clicking on the plus circle to display div#card the div.container loses it's top margin and I cannot understand why. Please if anyone can help me with this, I'd be really grateful - And maybe we can all learn from it ;)
Thanks!
Codepen: https://codepen.io/albertrf147/pen/LMKKeK
HTML
html,
body {
width: 100%;
height: 100%;
}
body {
margin: 0px;
overflow: hidden;
background: lightblue;
}
.container {
width: 400px;
height: 400px;
margin: 20px auto !important;
position: relative;
display: flex;
flex-wrap: wrap;
background: white;
padding: 2px;
}
.square {
box-sizing: border-box;
padding: 2px;
width: 50%;
height: 50%;
position: relative;
background: white;
}
.square>img {
height: 100%;
width: 100%;
object-fit: cover;
display: block;
margin: auto;
}
.onhover {
box-sizing: border-box;
width: 100%;
height: 100%;
position: absolute;
cursor: pointer;
transition: all .6s ease-in-out;
}
.onhover:hover {
background: rgba(0, 0, 0, 0.5);
}
.circle-aux {
position: relative;
width: 100%;
height: 100%;
transition: all .6s ease-in-out;
}
.circle-aux:hover .circle {
visibility: visible;
opacity: 1;
transform: scale(0.2);
transition: all .6s ease-in-out;
}
.circle {
visibility: hidden;
opacity: 0;
position: absolute;
border-radius: 50%;
width: 100%;
height: 100%;
background: salmon;
}
.circle:before {
content: "";
background: white;
height: 50%;
width: 6px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.circle:after {
content: "";
background: white;
height: 6px;
width: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.container-card {
visibility: hidden;
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
.container-card>img {
width: 100%;
height: 60%;
object-fit: cover;
}
.container-card:target {
visibility: visible;
}
.avatar {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
box-shadow: 0px 0px 20px black;
width: 25%;
height: 25%;
background: white;
z-index: 2;
text-align: center;
font-family: calibri;
font-weight: bold;
color: white;
font-size: 18px;
}
.avatar>img {
box-sizing: border-box;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: inherit;
padding: 4px;
}
.mini-circle {
display: inline-block;
width: 15%;
height: 15%;
border: 1px solid white;
border-radius: 50%;
margin-top: 12px;
}
.mini-circle:hover {
background: white;
cursor: pointer;
}
footer {
box-sizing: border-box;
position: absolute;
bottom: 0;
left: 0;
background: salmon;
height: 50%;
width: 100%;
z-index: 1;
padding: 2px;
}
.close {
position: absolute;
border-radius: 50%;
width: 8%;
height: 8%;
background: black;
transform: rotate(45deg);
right: 10px;
top: 10px;
cursor: pointer;
}
.close:before {
content: "";
background: white;
height: 60%;
width: 2px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.close:after {
content: "";
background: white;
height: 2px;
width: 60%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<main>
<div class="container">
<div class="square">
<div class="onhover">
<div class="circle-aux">
<a class="circle" href="#card"></a>
</div>
</div>
<img src="https://images.pexels.com/photos/305241/pexels-photo-305241.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1546711/pexels-photo-1546711.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1800433/pexels-photo-1800433.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1757111/pexels-photo-1757111.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div id="card" class="container-card">
<a class="close" href="#"></a>
<img src="https://images.pexels.com/photos/1769331/pexels-photo-1769331.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
<div class="avatar">
<img src="https://images.pexels.com/photos/769772/pexels-photo-769772.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
<span>David Craig</span>
<span>
<div class="mini-circle"></div>
<div class="mini-circle"></div>
<div class="mini-circle"></div>
</span>
</div>
<footer></footer>
</div>
</div>
</main>
Welcome to SO!
As the appearing container is position: absolute no margin takes effect.
You need to work with the top attribute to place it properly.
Check this out: https://codepen.io/anon/pen/pGzVyL
For more informations click here: https://www.w3schools.com/css/css_positioning.asp

Making images more responsive relative to a non background image. Resize and stuck in a fixed position

I need help making my icons around the main wheel be more responsive to the page size increasing and decreasing. Right now they move around and I need them to stay put relevant to the middle wheel. I also would like the wheel and icons to resize better when the page shrinks or grows. I feel like it has something to do with my positioning but I am not sure. Been stuck for hours. Anything helps!
My website is www.marshalllanning.com and I will put my CSS code below...
.bg {
/* Set rules to fill background */
min-height: 100%;
min-width: 1024px;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
z-index: 0;
}
.navbar-custom {
background-color: black;
z-index: 3;
}
.navbar-brand
{
position: absolute;
width: 100%;
left: 0;
text-align: center;
margin: 0;
}
.navbar-toggle {
z-index:3;
}
.navbar-custom .navbar-toggle .icon-bar {
background-color: red;
}
.navbar-custom .navbar-toggle {
background-color: white;
}
#media screen and (max-width: 1024px) { /* Specific to
this particular image */
.bg {
left: 50%;
margin-left: -512px; /* 50% */
}
}
.img1 {
border-radius: 50%;
display: block;
margin-left: auto;
margin-right: auto;
width: 500px;
height: 500px;
border-color: white;
border-width: 15px;
border-style: solid;
position: absolute;
margin: 0;
top: 52%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 1;
}
.fb {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
width: 64px;
height: 64px;
position: absolute;
margin: 0;
top: 30%;
left: 34%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 2;
border-color: black;
border-width: 1px;
border-style: solid;
}
.fb:hover {
opacity: 0.7;
}
.sc {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
position: absolute;
margin: 0;
top: 16.8%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 2;
border-color: black;
border-width: 1px;
border-style: solid;
}
.sc:hover {
opacity: 0.7;
}
.gh {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
width: 64px;
height: 64px;
position: absolute;
margin: 0;
top: 30%;
left: 66%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 2;
background-color: white;
border-color: black;
border-width: 1px;
border-style: solid;
}
.gh:hover {
opacity: 0.7;
}
.ig {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
width: 64px;
height: 64px;
position: absolute;
margin: 0;
top: 83%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 2;
border-color: black;
border-width: 1px;
border-style: solid;
}
.ig:hover {
opacity: 0.7;
}
.li {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
width: 64px;
height: 64px;
position: absolute;
margin: 0;
top: 50%;
left: 30%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 2;
border-color: black;
border-width: 1px;
border-style: solid;
}
.li:hover {
opacity: 0.7;
}
.xb {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
width: 64px;
height: 64px;
position: absolute;
margin: 0;
top: 50%;
left: 70%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 2;
border-color: black;
border-width: 1px;
border-style: solid;
}
.xb:hover {
opacity: 0.7;
}
.az {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
width: 64px;
height: 64px;
position: absolute;
margin: 0;
top: 70%;
left: 66%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 2;
border-color: black;
border-width: 1px;
border-style: solid;
}
.az:hover {
opacity: 0.7;
}
.gc {
border-radius: 20%;
display: block;
margin-left: auto;
margin-right: auto;
width: 64px;
height: 64px;
position: absolute;
margin: 0;
top: 70%;
left: 34%;
margin-right: -50%;
transform: translate(-50%, -50%);
z-index: 2;
border-color: black;
border-width: 1px;
border-style: solid;
}
.gc:hover {
opacity: 0.7;
}
.center {
color: whitesmoke;
height: 10em;
position: absolute;
margin: 0;
top: 30%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
Create a div around all items like <div style="width: 500px;height: 500px;position: relative;margin: auto;"> and then change in css the top and the left values.

Overflow:hidden is not for the divs of circle shape?

I'm having trouble with the code below.
I want the reflection of the windmill and all to be embedded inside the circle shape, but i'm unable to do so.
Please help me.
Thank you in advance.
Here is my html
body {
background-color: white;
}
#Circle {
background-color: #22304D;
background: linear-gradient(to bottom, #22304D, #5E7B9B);
width: 500px;
height: 500px;
border-radius: 100%;
margin: 0 auto;
overflow: hidden;
}
#Circle #cont {
background-color: transparent;
width: 500px;
height: 500px;
border-radius: 100%;
margin: 0 auto;
box-shadow: inset 0 0 100px black;
}
#Circle #cont .top {
height: 250px;
position: relative;
background-color: transparent;
border-top-left-radius: 900px;
border-top-right-radius: 900px;
}
.bottom {
display: inline-block;
position: relative;
margin-top: 390px;
opacity: 0.6;
filter: blur(2px);
transform: scaleY(-1);
}
.floor {
background-color: #1E2D49;
width: 468px;
margin-left: 16px;
position: absolute;
height: 20px;
margin-top: 320px;
z-index: 0;
}
.floor::after {
content: "";
background-color: #1E2D49;
width: 200px;
height: 50px;
position: absolute;
transform: rotateX(45deg);
margin-top: -30px;
margin-left: -3px;
border-radius: 90% 100% 0 0;
}
.floor::before {
content: "";
background-color: content:"";
background-color: #1E2D49;
width: 200px;
height: 50px;
position: absolute;
transform: rotateX(45deg);
border-radius: 90% 100% 0 0;
;
width: 347px;
height: 70px;
position: absolute;
transform: rotateX(45deg);
margin-left: 122px;
margin-top: -50px;
border-radius: 100% 100% 0 0;
}
.sky {}
.moon {
background-color: white;
width: 48px;
height: 48px;
z-index: 2;
border-radius: 100%;
position: absolute;
margin-left: 130px;
margin-top: 180px;
box-shadow: 0 0 5px white, 0 0 10px #1E2D49, 0 0 90px white;
}
.stars {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
display: block;
}
.stars {
background: url(http://www.script-tutorials.com/demos/360/images/stars.png) repeat top center;
z-index: 0;
}
.mill {
background-color: #1E2D49;
width: 50px;
height: 140px;
transform: perspective(12px) rotateX(3deg);
position: absolute;
z-index: 3;
margin-top: 150px;
margin-left: 330px;
}
.mill::before {
content: "";
background-color: #FDC500;
width: 20px;
height: 20px;
position: absolute;
margin-left: 15px;
margin-top: 35px;
}
.mill::after {
content: "";
background-color: #FDC500;
width: 20px;
height: 25px;
position: absolute;
margin-left: 15px;
margin-top: 70px;
}
.dome {
background-color: #1E2D49;
width: 35px;
height: 35px;
position: absolute;
transform-origin: 0 100%;
transform: rotate(45deg);
overflow: hidden;
margin-left: 330px;
margin-top: 125px;
z-index: 4;
}
.fan {
background-color: #37475E;
/*37475E */
width: 10px;
height: 10px;
border-radius: 100%;
position: absolute;
margin-top: 155px;
margin-left: 350px;
z-index: 7;
animation-name: rotate_fan;
animation-duration: 6s;
animation-iteration-count: infinite;
}
.fan_blade1,
.fan_blade2,
.fan_blade3,
.fan_blade4 {
background-color: #37475E;
width: 4px;
height: 60px;
position: absolute;
z-index: 6;
margin-left: 35px;
margin-top: -28px;
border-left: 1.5px solid black;
border-top: 1px solid black;
transform: rotate(90deg);
}
.fan_blade2 {
transform: rotate(180deg);
margin-left: 1px;
margin-top: 5px;
}
.fan_blade3 {
transform: rotate(360deg);
margin-left: 3px;
margin-top: -60px;
}
.fan_blade4 {
transform: rotate(270deg);
margin-top: -28px;
margin-left: -30px;
}
.fan_blade1::before,
.fan_blade2::before,
.fan_blade3::before,
.fan_blade4::before {
content: "";
background-color: transparent;
width: 20px;
height: 45px;
margin-left: 5px;
background-size: 10px 11px;
background-image: linear-gradient(to left, gray 2px, transparent 1px), linear-gradient(to bottom, gray 2px, transparent 1px), linear-gradient(to top, gray 1px, transparent 0px);
position: absolute;
}
#keyframes rotate_fan {
from {}
to {
transform: rotate(360deg);
}
}
<div id="Circle">
<div id="cont">
<div class="top">
<div class="dome"></div>
<div class="fan">
<div class="fan_blade1"></div>
<div class="fan_blade2"></div>
<div class="fan_blade3"></div>
<div class="fan_blade4"></div>
</div>
<div class="mill"></div>
<div class="sky">
<div class="stars"></div>
<div class="moon"></div>
</div>
<div class="floor">
</div>
</div>
<div class="bottom">
<div class="dome"></div>
<div class="fan">
<div class="fan_blade1"></div>
<div class="fan_blade2"></div>
<div class="fan_blade3"></div>
<div class="fan_blade4"></div>
</div>
<div class="mill"></div>
<div class="sky">
<div class="stars"></div>
<div class="moon"></div>
</div>
<div class="floor">
</div>
</div>
</div>
</div>
You can clip the circle like this:
body {
background-color: white;
}
#Circle {
-webkit-clip-path: inset(0 0 0 0 round 250px);
clip-path: inset(0 0 0 0 round 250px);
background-color: #22304D;
background: linear-gradient(to bottom, #22304D, #5E7B9B);
width: 500px;
height: 500px;
border-radius: 100%;
margin: 0 auto;
overflow: hidden;
}
#Circle #cont {
background-color: transparent;
width: 500px;
height: 500px;
border-radius: 100%;
margin: 0 auto;
box-shadow: inset 0 0 100px black;
}
#Circle #cont .top {
height: 250px;
position: relative;
background-color: transparent;
border-top-left-radius: 900px;
border-top-right-radius: 900px;
}
.bottom {
display: inline-block;
position: relative;
margin-top: 390px;
opacity: 0.6;
filter: blur(2px);
transform: scaleY(-1);
}
.floor {
background-color: #1E2D49;
width: 468px;
margin-left: 16px;
position: absolute;
height: 20px;
margin-top: 320px;
z-index: 0;
}
.floor::after {
content: "";
background-color: #1E2D49;
width: 200px;
height: 50px;
position: absolute;
transform: rotateX(45deg);
margin-top: -30px;
margin-left: -3px;
border-radius: 90% 100% 0 0;
}
.floor::before {
content: "";
background-color: content:"";
background-color: #1E2D49;
width: 200px;
height: 50px;
position: absolute;
transform: rotateX(45deg);
border-radius: 90% 100% 0 0;
;
width: 347px;
height: 70px;
position: absolute;
transform: rotateX(45deg);
margin-left: 122px;
margin-top: -50px;
border-radius: 100% 100% 0 0;
}
.sky {}
.moon {
background-color: white;
width: 48px;
height: 48px;
z-index: 2;
border-radius: 100%;
position: absolute;
margin-left: 130px;
margin-top: 180px;
box-shadow: 0 0 5px white, 0 0 10px #1E2D49, 0 0 90px white;
}
.stars {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
display: block;
}
.stars {
background: url(http://www.script-tutorials.com/demos/360/images/stars.png) repeat top center;
z-index: 0;
}
.mill {
background-color: #1E2D49;
width: 50px;
height: 140px;
transform: perspective(12px) rotateX(3deg);
position: absolute;
z-index: 3;
margin-top: 150px;
margin-left: 330px;
}
.mill::before {
content: "";
background-color: #FDC500;
width: 20px;
height: 20px;
position: absolute;
margin-left: 15px;
margin-top: 35px;
}
.mill::after {
content: "";
background-color: #FDC500;
width: 20px;
height: 25px;
position: absolute;
margin-left: 15px;
margin-top: 70px;
}
.dome {
background-color: #1E2D49;
width: 35px;
height: 35px;
position: absolute;
transform-origin: 0 100%;
transform: rotate(45deg);
overflow: hidden;
margin-left: 330px;
margin-top: 125px;
z-index: 4;
}
.fan {
background-color: #37475E;
/*37475E */
width: 10px;
height: 10px;
border-radius: 100%;
position: absolute;
margin-top: 155px;
margin-left: 350px;
z-index: 7;
animation-name: rotate_fan;
animation-duration: 6s;
animation-iteration-count: infinite;
}
.fan_blade1,
.fan_blade2,
.fan_blade3,
.fan_blade4 {
background-color: #37475E;
width: 4px;
height: 60px;
position: absolute;
z-index: 6;
margin-left: 35px;
margin-top: -28px;
border-left: 1.5px solid black;
border-top: 1px solid black;
transform: rotate(90deg);
}
.fan_blade2 {
transform: rotate(180deg);
margin-left: 1px;
margin-top: 5px;
}
.fan_blade3 {
transform: rotate(360deg);
margin-left: 3px;
margin-top: -60px;
}
.fan_blade4 {
transform: rotate(270deg);
margin-top: -28px;
margin-left: -30px;
}
.fan_blade1::before,
.fan_blade2::before,
.fan_blade3::before,
.fan_blade4::before {
content: "";
background-color: transparent;
width: 20px;
height: 45px;
margin-left: 5px;
background-size: 10px 11px;
background-image: linear-gradient(to left, gray 2px, transparent 1px), linear-gradient(to bottom, gray 2px, transparent 1px), linear-gradient(to top, gray 1px, transparent 0px);
position: absolute;
}
#keyframes rotate_fan {
from {}
to {
transform: rotate(360deg);
}
}
<div id="Circle">
<div id="cont">
<div class="top">
<div class="dome"></div>
<div class="fan">
<div class="fan_blade1"></div>
<div class="fan_blade2"></div>
<div class="fan_blade3"></div>
<div class="fan_blade4"></div>
</div>
<div class="mill"></div>
<div class="sky">
<div class="stars"></div>
<div class="moon"></div>
</div>
<div class="floor">
</div>
</div>
<div class="bottom">
<div class="dome"></div>
<div class="fan">
<div class="fan_blade1"></div>
<div class="fan_blade2"></div>
<div class="fan_blade3"></div>
<div class="fan_blade4"></div>
</div>
<div class="mill"></div>
<div class="sky">
<div class="stars"></div>
<div class="moon"></div>
</div>
<div class="floor">
</div>
</div>
</div>
</div>
Set position: relative; z-index: 1; to #Circle
body {
background-color: white;
}
#Circle {
position: relative;
z-index: 1;
background-color: #22304D;
background: linear-gradient(to bottom, #22304D, #5E7B9B);
width: 500px;
height: 500px;
border-radius: 100%;
margin: 0 auto;
overflow: hidden;
}
#Circle #cont {
background-color: transparent;
width: 500px;
height: 500px;
border-radius: 100%;
margin: 0 auto;
box-shadow: inset 0 0 100px black;
}
#Circle #cont .top {
height: 250px;
position: relative;
background-color: transparent;
border-top-left-radius: 900px;
border-top-right-radius: 900px;
}
.bottom {
display: inline-block;
position: relative;
margin-top: 390px;
opacity: 0.6;
filter: blur(2px);
transform: scaleY(-1);
}
.floor {
background-color: #1E2D49;
width: 468px;
margin-left: 16px;
position: absolute;
height: 20px;
margin-top: 320px;
z-index: 0;
}
.floor::after {
content: "";
background-color: #1E2D49;
width: 200px;
height: 50px;
position: absolute;
transform: rotateX(45deg);
margin-top: -30px;
margin-left: -3px;
border-radius: 90% 100% 0 0;
}
.floor::before {
content: "";
background-color: content:"";
background-color: #1E2D49;
width: 200px;
height: 50px;
position: absolute;
transform: rotateX(45deg);
border-radius: 90% 100% 0 0;
;
width: 347px;
height: 70px;
position: absolute;
transform: rotateX(45deg);
margin-left: 122px;
margin-top: -50px;
border-radius: 100% 100% 0 0;
}
.sky {}
.moon {
background-color: white;
width: 48px;
height: 48px;
z-index: 2;
border-radius: 100%;
position: absolute;
margin-left: 130px;
margin-top: 180px;
box-shadow: 0 0 5px white, 0 0 10px #1E2D49, 0 0 90px white;
}
.stars {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
display: block;
}
.stars {
background: url(http://www.script-tutorials.com/demos/360/images/stars.png) repeat top center;
z-index: 0;
}
.mill {
background-color: #1E2D49;
width: 50px;
height: 140px;
transform: perspective(12px) rotateX(3deg);
position: absolute;
z-index: 3;
margin-top: 150px;
margin-left: 330px;
}
.mill::before {
content: "";
background-color: #FDC500;
width: 20px;
height: 20px;
position: absolute;
margin-left: 15px;
margin-top: 35px;
}
.mill::after {
content: "";
background-color: #FDC500;
width: 20px;
height: 25px;
position: absolute;
margin-left: 15px;
margin-top: 70px;
}
.dome {
background-color: #1E2D49;
width: 35px;
height: 35px;
position: absolute;
transform-origin: 0 100%;
transform: rotate(45deg);
overflow: hidden;
margin-left: 330px;
margin-top: 125px;
z-index: 4;
}
.fan {
background-color: #37475E;
/*37475E */
width: 10px;
height: 10px;
border-radius: 100%;
position: absolute;
margin-top: 155px;
margin-left: 350px;
z-index: 7;
animation-name: rotate_fan;
animation-duration: 6s;
animation-iteration-count: infinite;
}
.fan_blade1,
.fan_blade2,
.fan_blade3,
.fan_blade4 {
background-color: #37475E;
width: 4px;
height: 60px;
position: absolute;
z-index: 6;
margin-left: 35px;
margin-top: -28px;
border-left: 1.5px solid black;
border-top: 1px solid black;
transform: rotate(90deg);
}
.fan_blade2 {
transform: rotate(180deg);
margin-left: 1px;
margin-top: 5px;
}
.fan_blade3 {
transform: rotate(360deg);
margin-left: 3px;
margin-top: -60px;
}
.fan_blade4 {
transform: rotate(270deg);
margin-top: -28px;
margin-left: -30px;
}
.fan_blade1::before,
.fan_blade2::before,
.fan_blade3::before,
.fan_blade4::before {
content: "";
background-color: transparent;
width: 20px;
height: 45px;
margin-left: 5px;
background-size: 10px 11px;
background-image: linear-gradient(to left, gray 2px, transparent 1px), linear-gradient(to bottom, gray 2px, transparent 1px), linear-gradient(to top, gray 1px, transparent 0px);
position: absolute;
}
#keyframes rotate_fan {
from {}
to {
transform: rotate(360deg);
}
}
<div id="Circle">
<div id="cont">
<div class="top">
<div class="dome"></div>
<div class="fan">
<div class="fan_blade1"></div>
<div class="fan_blade2"></div>
<div class="fan_blade3"></div>
<div class="fan_blade4"></div>
</div>
<div class="mill"></div>
<div class="sky">
<div class="stars"></div>
<div class="moon"></div>
</div>
<div class="floor">
</div>
</div>
<div class="bottom">
<div class="dome"></div>
<div class="fan">
<div class="fan_blade1"></div>
<div class="fan_blade2"></div>
<div class="fan_blade3"></div>
<div class="fan_blade4"></div>
</div>
<div class="mill"></div>
<div class="sky">
<div class="stars"></div>
<div class="moon"></div>
</div>
<div class="floor">
</div>
</div>
</div>
</div>
Like in similar questions (Overflow hidden with border radius not working in chrome), it seems that setting
#Circle {
position: relative;
z-index: 1;
}
will solve your issue.
increase width and height of #circle and #Circle #cont so its display properly
body {
background-color: white;
}
#Circle {
background-color: #22304D;
background: linear-gradient(to bottom, #22304D, #5E7B9B);
width: 570px;
height: 570px;
border-radius: 100%;
margin: 0 auto;
overflow: hidden;
z-index:-2px;
position:absolute;
}
#Circle #cont {
background-color: transparent;
width: 570px;
height: 570px;
border-radius: 100%;
margin: 0 auto;
box-shadow: inset 0 0 100px black;
}
#Circle #cont .top {
height: 250px;
position: relative;
background-color: transparent;
border-top-left-radius: 900px;
border-top-right-radius: 900px;
}
.bottom {
display: inline-block;
position: relative;
margin-top: 390px;
opacity: 0.6;
filter: blur(2px);
transform: scaleY(-1);
}
.floor {
background-color: #1E2D49;
width: 468px;
margin-left: 16px;
position: absolute;
height: 20px;
margin-top: 320px;
z-index: 0;
}
.floor::after {
content: "";
background-color: #1E2D49;
width: 200px;
height: 50px;
position: absolute;
transform: rotateX(45deg);
margin-top: -30px;
margin-left: -3px;
border-radius: 90% 100% 0 0;
}
.floor::before {
content: "";
background-color: content:"";
background-color: #1E2D49;
width: 200px;
height: 50px;
position: absolute;
transform: rotateX(45deg);
border-radius: 90% 100% 0 0;
;
width: 347px;
height: 70px;
position: absolute;
transform: rotateX(45deg);
margin-left: 122px;
margin-top: -50px;
border-radius: 100% 100% 0 0;
}
.sky {}
.moon {
background-color: white;
width: 48px;
height: 48px;
z-index: 2;
border-radius: 100%;
position: absolute;
margin-left: 130px;
margin-top: 180px;
box-shadow: 0 0 5px white, 0 0 10px #1E2D49, 0 0 90px white;
}
.stars {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
display: block;
}
.stars {
background: url(http://www.script-tutorials.com/demos/360/images/stars.png) repeat top center;
z-index: 0;
}
.mill {
background-color: #1E2D49;
width: 50px;
height: 140px;
transform: perspective(12px) rotateX(3deg);
position: absolute;
z-index: 3;
margin-top: 150px;
margin-left: 330px;
}
.mill::before {
content: "";
background-color: #FDC500;
width: 20px;
height: 20px;
position: absolute;
margin-left: 15px;
margin-top: 35px;
}
.mill::after {
content: "";
background-color: #FDC500;
width: 20px;
height: 25px;
position: absolute;
margin-left: 15px;
margin-top: 70px;
}
.dome {
background-color: #1E2D49;
width: 35px;
height: 35px;
position: absolute;
transform-origin: 0 100%;
transform: rotate(45deg);
overflow: hidden;
margin-left: 330px;
margin-top: 125px;
z-index: 4;
}
.fan {
background-color: #37475E;
/*37475E */
width: 10px;
height: 10px;
border-radius: 100%;
position: absolute;
margin-top: 155px;
margin-left: 350px;
z-index: 7;
animation-name: rotate_fan;
animation-duration: 6s;
animation-iteration-count: infinite;
}
.fan_blade1,
.fan_blade2,
.fan_blade3,
.fan_blade4 {
background-color: #37475E;
width: 4px;
height: 60px;
position: absolute;
z-index: 6;
margin-left: 35px;
margin-top: -28px;
border-left: 1.5px solid black;
border-top: 1px solid black;
transform: rotate(90deg);
}
.fan_blade2 {
transform: rotate(180deg);
margin-left: 1px;
margin-top: 5px;
}
.fan_blade3 {
transform: rotate(360deg);
margin-left: 3px;
margin-top: -60px;
}
.fan_blade4 {
transform: rotate(270deg);
margin-top: -28px;
margin-left: -30px;
}
.fan_blade1::before,
.fan_blade2::before,
.fan_blade3::before,
.fan_blade4::before {
content: "";
background-color: transparent;
width: 20px;
height: 45px;
margin-left: 5px;
background-size: 10px 11px;
background-image: linear-gradient(to left, gray 2px, transparent 1px), linear-gradient(to bottom, gray 2px, transparent 1px), linear-gradient(to top, gray 1px, transparent 0px);
position: absolute;
}
#keyframes rotate_fan {
from {}
to {
transform: rotate(360deg);
}
}
<div id="Circle">
<div id="cont">
<div class="top">
<div class="dome"></div>
<div class="fan">
<div class="fan_blade1"></div>
<div class="fan_blade2"></div>
<div class="fan_blade3"></div>
<div class="fan_blade4"></div>
</div>
<div class="mill"></div>
<div class="sky">
<div class="stars"></div>
<div class="moon"></div>
</div>
<div class="floor">
</div>
</div>
<div class="bottom">
<div class="dome"></div>
<div class="fan">
<div class="fan_blade1"></div>
<div class="fan_blade2"></div>
<div class="fan_blade3"></div>
<div class="fan_blade4"></div>
</div>
<div class="mill"></div>
<div class="sky">
<div class="stars"></div>
<div class="moon"></div>
</div>
<div class="floor">
</div>
</div>
</div>
</div>

Centering an absolute positioned div

I need to center this div that is wrapped inside another div:
Div to be centered:
.post-username {
padding: 10px;
background: #000;
border-radius: 4px;
position: absolute;
top: 0;
}
It should be centered inside of this:
.post {
background: #3e4758;
overflow: hidden;
border-radius: 4px;
width: 270px;
height: 330px;
position: relative;
}
.post-username {
padding: 50px;
background: #000;
border-radius: 4px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
}
.post {
background: #3e4758;
overflow: hidden;
border-radius: 4px;
width: 270px;
height: 330px;
position: relative;
}
.post-username {
padding: 10px;
background: #000;
border-radius: 4px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.post {
background: #3e4758;
overflow: hidden;
border-radius: 4px;
width: 270px;
height: 330px;
position: relative;
}
<div class="post">
<div class="post-username">asdasd</div>
</div>