How to make one circle inside of another using CSS - css

I am trying to make one circle inside of another circle using css, but I am having an issue making it completely centered. I am close, but still not there. Any ideas?
<div id="content">
<h1>Test Circle</h1>
<div id="outer-circle">
<div id="inner-circle">
<span id="inside-content"></span>
</div>
</div>
</div>
Here is my CSS:
#outer-circle {
background: #385a94;
border-radius: 50%;
height:500px;
width:500px;
}
#inner-circle {
position: relative;
background: #a9aaab;
border-radius: 50%;
height:300px;
width:300px;
margin: 0px 0px 0px 100px;
}
Also, here is a fiddle:
http://jsfiddle.net/972SF/

Ta da!
Explained in the CSS comments:
#outer-circle {
background: #385a94;
border-radius: 50%;
height: 500px;
width: 500px;
position: relative;
/*
Child elements with absolute positioning will be
positioned relative to this div
*/
}
#inner-circle {
position: absolute;
background: #a9aaab;
border-radius: 50%;
height: 300px;
width: 300px;
/*
Put top edge and left edge in the center
*/
top: 50%;
left: 50%;
margin: -150px 0px 0px -150px;
/*
Offset the position correctly with
minus half of the width and minus half of the height
*/
}
<div id="outer-circle">
<div id="inner-circle">
</div>
</div>

You don't need extra elements in CSS3
You can do it all with one element and a box-shadow.
JSFiddle Demo.
CSS
#outer-circle {
background: #385a94;
border-radius: 50%;
height:300px;
width:300px;
position: relative;
box-shadow: 0 0 0 100px black;
margin:100px;
}

If you want to use only one div to add circle inside circle, then use box-shadow.
div {
border-radius: 50%;
box-shadow: 0px 0px 0px 10px red, 0px 0px 0px 20px green, 0px 0px 0px 30px yellow, 0px 0px 0px 40px pink;
width: 100px;
height:100px;
margin: 3em;
}
<div></div>

Solved this by using CSS transform property:
You can refer to this JS fiddle link for below output:
http://jsfiddle.net/suprabhasupi/74b1ptne/
div {
border-radius: 50%;
/* border: 1px solid red; */
}
.circle1 {
position: relative;
width: 300px;
height: 300px;
background-color: red;
}
.circle2 {
transform: translate(25%, 25%);
width: 200px;
height: 200px;
background-color: green;
}
.circle3 {
transform: translate(48%, 46%);
width: 100px;
height: 100px;
background-color: blue;
}
<div class="circle1">
<div class="circle2">
<div class="circle3">
</div>
</div>
</div>

Use position: relative on the outer circle, position:absolute on the inner circle, and set all offset to the same value. Let the automatic calculation of height and width handle the rest (JSFiddle):
#outer-circle {
position:relative;
background: #385a94;
border-radius: 50%;
height:500px;
width:500px;
}
#inner-circle {
position:absolute;
background: #a9aaab;
border-radius: 50%;
right: 100px;
left: 100px;
top: 100px;
bottom: 100px;
/* no margin, no width, they get automatically calculated*/
}

Seems that top is the only thing you need to alter -> http://jsfiddle.net/972SF/12/
#inner-circle {
position: relative;
background: #a9aaab;
border-radius: 50%;
height:300px;
width:300px;
top: 100px; /* <--- */
margin: 0px 0px 0px 100px;
}

Just use box-shadow to get the effect you want:
Demo in a fiddle: http://jsfiddle.net/972SF/16/
The html is reduced to:
<div id="content">
<h1>Test Circle</h1>
<div id="circle">
</div>
</div>
Css:
#circle {
margin: 10em auto;
background: #385a94;
border-radius: 50%;
height:200px;
width:200px;
-webkit-box-shadow: 1px 1px 0px 100px black;
-moz-box-shadow: 1px 1px 0px 100px black;
box-shadow: 1px 1px 0px 100px black;
}
its simple, easy, and makes sure that your circles are always perfectly positioned next to each other.
You can change the size of the circle by changing the 4th property ( 100px ) on box-shadow to what ever you want.

take a look at this fiddle
which calculates centering automatically
#outer-circle {
background: #385a94;
border-radius: 50%;
height:500px;
width:500px;
display:table-cell;
vertical-align:middle;
}
#inner-circle {
display:inline-block;
background: #a9aaab;
border-radius: 50%;
height:300px;
width:300px;
}

Here is an example of a circle with outer border.
HTML:
<div id="inner-circle"></div>
Styles:
#inner-circle {
background: #385a94;
border : 2px solid white;
border-radius: 50%;
height:30px;
width:30px;
position: relative;
box-shadow: 0 0 0 1px #cfd1d1;
}
See results:
JSFiddle

Try,
#inner-circle {
position: absolute;
background: #a9aaab;
border-radius: 50%;
height:300px;
width:300px;
margin: 15% 0px 0px 100px;
}
Here is ur Updated JSFIDDLE

See How I have positioned the Divs, Just border-radius should do the Job
.outer{width:500px;height:500px;background:#f00;border-radius:50%;position:relative;top:0;left:100;}
.inner{width:250px;height:250px;background:#000;border-radius:50%;position:absolute;top:125;left:125;}
<div class="outer">
<div class="inner">
</div>
</div>
DEMO

try to give the innercircle a top:50% and than margin-top: a nagative value from the half of the height of the innercircle.
http://jsfiddle.net/972SF/19/

SOLVED! Exactly the way you want:
DEMO: http://jsfiddle.net/aniruddha153/RLWua/
HTML:
<div id="content">
<div id="outer-circle">
<div id="inner-circle">
</div>
</div>
</div>
CSS:
#content {
position: relative;
width: 100%;
padding-bottom: 100%;
}
#outer-circle {
position: absolute;
width: 50%;
height: 50%;
background-color: #000000;
border-radius: 50%;
}
#inner-circle{
margin-top: 25%;
margin-left: 25%;
position: absolute;
width: 50%;
height: 50%;
background-color: #e5e5e5;
border-radius: 50%;
}

You can use the top and left property of CSS to center it.
body {
width: 100%
margin:0px;
text-align: center;
}
#content {
width: 500px;
margin-left: auto;
margin-right: auto;
}
#outer-circle {
background: #385a94;
border-radius: 50%;
height:200px;
width:200px;
}
#inner-circle {
position: relative;
background: #a9aaab;
border-radius: 50%;
height:100px;
width:100px;
top:50px;
left:50px;
}
<div id="content">
<h1>Test Circle</h1>
<div id="outer-circle">
<div id="inner-circle">
<span id="inside-content"></span>
</div>
</div>
</div>

Related

CSS, Flexbox, CSS Grid, Borders, overwrite parent border by inside child div

I have this situation: https://jsfiddle.net/johnsam/L811uzey/
I need a to cover (overwrite) the border of container with the triangle content.
How can I?
The code:
<div class="container">
<div class="triangle">How are you ?</div>
</div>
.container {
border: 1px solid gray;
position: relative;
width: 50vw;
height: 100px;
background: #fff;
overflow: hidden;
}
.triangle {
background-color: red;
display: inline-block;
transform: translateX(-50%) rotate(45deg) translateX(50%) rotate(-90deg);
transform-origin: center top;
box-shadow: 0px -50px 0px 50px red;
}
You can use a box-shadow for the border instead.
.container {
position: relative;
width: 50vw;
height: 100px;
background: #fff;
overflow: hidden;
box-shadow: inset 0 0 0 1px gray;
}
.triangle {
background-color: red;
display: inline-block;
transform: translateX(-50%) rotate(45deg) translateX(50%) rotate(-90deg);
transform-origin: center top;
box-shadow: 0px -50px 0px 50px red;
}
<div class="container">
<div class="triangle">How are you ?</div>
</div>
You could use a pseudo to do that, and then simply move the triangle with a negative margin.
I also moved the overflow: hidden to the triangle or else it won't overlay the border.
Note, I used a thicker border for this sample, so one easily can see it works
.container {
border: 5px solid gray;
position: relative;
width: 50vw;
height: 80px;
background: #fff;
}
.triangle {
display: inline-block;
height: calc(100% + 10px); /* 10px = border size * 2 */
margin: -5px 0 0 -5px; /* move element left/top = border size */
width: 100%;
overflow: hidden;
}
.triangle::before {
content: attr(data-text);
display: inline-block;
background-color: red;
transform: translateX(-50%) rotate(45deg) translateX(50%) rotate(-90deg);
transform-origin: center top;
box-shadow: 0px -50px 0px 50px red;
}
<div class="container">
<div class="triangle" data-text="How ?"></div>
</div>
<br>
<div class="container">
<div class="triangle" data-text="How are you ?"></div>
</div>
If you want to do more than what is possible with a pseudo, you can of course add an element, here done with a span
In this sample I used relative position instead of negative margin, to show yet another way.
.container {
border: 5px solid gray;
position: relative;
width: 50vw;
height: 80px;
background: #fff;
}
.triangle {
display: inline-block;
position: relative;
left: -5px; /* move element left = border size */
top: -5px; /* move element top = border size */
height: calc(100% + 10px); /* 10px = border size * 2 */
width: 100%;
overflow: hidden;
}
.triangle span {
display: inline-block;
background-color: red;
transform: translateX(-50%) rotate(45deg) translateX(50%) rotate(-90deg);
transform-origin: center top;
box-shadow: 0px -50px 0px 50px red;
}
<div class="container">
<div class="triangle">
<span>How ?</span>
</div>
</div>
<br>
<div class="container">
<div class="triangle">
<span>How are you ?</span>
</div>
</div>

Divs side-by-side, centred, and overflowing edge of screen

I am trying to design a landing page to link to 2 web apps. I am trying to make the design as visually attractive as possible. I think it would look good if the Divs containing the links were side-by-side at the centre of the screen, with their edges overflowing the left and right of the screen. I can then put a border-radius on them and some nice blocky colour:
Goal:
I have tried numerous options, including inline-block and overflow:hidden:
HTML
<div id="centre-pane">
<div class="app-btn">
<img src="icon.png">link text
</div>
<div class="app-btn">
<img src="icon2.png">link text
</div>
</div>
CSS
.app-btn
{
width:1000px;
height:320px;
display:inline-block;
border:10px solid black;
border-radius: 50px;
}
#centre-pane {
width:2000px;
margin:0 auto;
text-align:center;
overflow-x: hidden;
}
Is this possible? I have found several ways of getting them side-by-side (eg here) but nothing that also lets them overflow the screen.
Just using position absolute would do the trick.
I've added a wrapper but it may not be required.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body,
html,
.wrapper {
height: 100%;
}
.wrapper {
position: relative;
}
.btn {
width: 45%;
height: 30%;
background: lightblue;
border: 2px solid blue;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.left {
left: 0;
border-radius: 0 25% 25% 0;
border-left: none;
}
.right {
right: 0;
border-radius: 25% 0 0 25%;
border-right: none;
}
<div class="wrapper">
<div class="btn left"></div>
<div class="btn right"></div>
</div>
You can achieve this with absolute positioning and negative margins (for the right item). You'll have to fix the size of the body though in order to achieve the effect. I've also added individual classes to the first and second item respectively (.app-btn-1 and .app-btn-2):
body {
width: 2000px;
overflow-x: hidden;
}
.app-btn {
width:1000px;
height:320px;
position: absolute;
border:10px solid black;
border-radius: 50px;
overflow-x: hidden;
}
.app-btn-1 {
left: -500px;
text-align: right;
}
.app-btn-2 {
left: 100%;
margin-left: -500px;
}
DEMO
NOTE: For my demo to look right in jsfiddle, I've quartered the sizes so you can see the effect in the small window
Here is the code you need:
.menu {
display: inline-block;
height: 200px;
width: 40%;
margin-top: calc(50% - 100px);
border: 2px solid red;
background-color: brown;
color: black;
text-decoration: none;
transition: all 0.5s;
}
#left {
float: left;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
margin-left: -10px;
}
#right {
float: right;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
margin-right: -10px;
}
.menu:hover {
background-color: gray;
border-color: brown;
color: red;
}
<div class="menu" id="left">Left</div>
<div class="menu" id="right">Right</div>
I made a
JS Fiddle for you.

How to get Three DIV element in one row?

I can't seem to be able to get the third "promobox" to come up to the first row with the other two, it just goes onto the next row but it is set to a percentage so it shouldn't matter.
I have tried to fix this with an answer from another forum but I simply can't do it.
Help would be great.
Thanks heaps.
<html>
<head>
<style>
* {
margin: 0px; padding: 0px; border: 0px;
}
#container {
width: 100%; height: 500px;
max-width: 1440px; min-width: 1024px;
margin: 0px auto;
border: 2px solid blue;
text-align: center;
}
.bigbox {
height: 530px;
background-image: url(images/photos/landscape-1440.jpg);
background-position: 50% 50%;
border: 2px solid red;
}
.promobox {
width: 25%;
height: 200px;
display: inline-block;
background-position: 50% 0%;
border: 2px solid green;
margin: 0px;
padding: 0px;
vertical-align: top;
}
.promobox div {
height: 200px;
border-color: #FFF;
border-style: none;
}
div {
text-align: center;
position: relative;
}
div a {
position: absolute;
bottom: 10px; right: 10px;
color: #FFF;
text-shadow: 1px 1px 1px #000;
}
#pb1 {width: 25%;}
#pb2 {width: 50%;}
#pb3 {width: 25%}
</style>
</head>
<body bgcolor="white">
<div id="container">
<div class="bigbox">
<div class="promobox" id="pb1">#</div>
<div class="promobox" id="pb2">#</div>
<div class="promobox" id="pb3">#</div></div></div></body></html>
You have two things that could mess the 3 boxes getting aligned next to each other.
The given border:2px solid green; and the display: inline-block;
You cant have the boxes have a total of 100% when using border.. because the borders need to be a part of the 100%.
.promobox {
width: 25%;
height: 200px;
float:left; /*Change the display:inline-block to this */
background-position: 50% 0%;
margin: 0px;
padding: 0px;
vertical-align: top;
}
Working DEMO (without the borders)
You are not accounting for the border of the divs thus you're going over the 100% width. The simplest solution would be either removing the border or having the total width less than or equals to 98%
e.g.
#pb1 {width: 24%;}
#pb2 {width: 50%;}
#pb3 {width: 24%}
Finaly i make an answser of my comment : DEMO with the fix below
In your HTML you have empty space in between div, it generates a white-space once you display your div as inline-block.
25%+50%+25% + 2 white-space +borders is more than 100% .
borders can be included using box-sizing, and white-space erased from HTML with <!--comment--> or via CSS setting font-size to 0 and back to 16px or so for .promobox.
Update for your CSS:
.bigbox {
font-size:0;
}
.promobox {
box-sizing:border-box;/* add vendor prefix where needed */
font-size:16px;/* fallback*/
font-size:1rem;
}
Try this:
<html>
<head>
<style>
* {
margin: 0px; padding: 0px; border: 0px;
}
#container {
width: 100%; height: 500px;
max-width: 1440px; min-width: 1024px;
margin: 0px auto;
text-align: center;
}
.bigbox {
height: 530px;
background-image: url(images/photos/landscape-1440.jpg);
background-position: 50% 50%;
}
.promobox {
width: 25%;
height: 200px;
display: inline-block;
background-position: 50% 0%;
margin: 0px;
padding: 0px;
vertical-align: top;
float:left;
}
.promobox div {
height: 200px;
border-color: #FFF;
border-style: none;
}
div {
text-align: center;
position: relative;
}
div a {
position: absolute;
bottom: 10px; right: 10px;
color: #FFF;
text-shadow: 1px 1px 1px #000;
}
#pb1 {width: 25%;}
#pb2 {width: 50%;}
#pb3 {width: 25%}
</style>
</head>
<body bgcolor="white">
<div id="container">
<div class="bigbox">
<div style='background:red' class="promobox" id="pb1">#</div>
<div style='background:green' class="promobox" id="pb2">#</div>
<div style='background:yellow' class="promobox" id="pb3">#</div></div></div></body></html>
here's a working demo of two divs in a row
<div style="text-align:center;">
<div style="border:1px solid #000; display:inline-block;">Div 1</div>
<div style="border:1px solid red; display:inline-block;">Div 2</div>
Demo

CSS: align border to the circle

I'm trying to align the border to the circle, to make it look like clipped there.
Here is an example:
http://jsfiddle.net/Beck/P63VY/1/
<div class="circle">
</div>
<div class="rounded"></div>
.circle {
width:150px;
height:150px;
border-radius:82px;
border:7px solid black;
}
.rounded {
position: absolute;
left: 22px;
top: 23px;
border: 1px solid red;
border-radius: 62px/66px 0px 0px 0px;
width: 200px;
height: 50px;
}
Is there a way to actually clip that top left corner?
Thanks.
try this
.circle {
width:150px;
height:150px;
border-radius:82px;
border:7px solid black;
}
.rounded {
position: absolute;
left: 18px;
top: 15px;
border: 1px solid red;
border-radius:72.5px;
width: 145px;
height: 145px;
}
</style>
<div class="circle">
<div class="rounded"></div>
</div>
Fiddle
The way I did it is:
Place <div class="rounded"></div> inside the <div class="circle">
If you want to keep the position: absolute in .rounded, add position: relative to the parent .circle
Add overflow: hidden to the parent, so the child gets clipped.
Remove all border-radius from the child .rounded since it's no longer needed.
HTML
<div class="circle">
<div class="rounded"></div>
</div>
CSS
.circle {
width:150px;
height:150px;
border-radius:82px;
border:7px solid black;
/* These were added: */
overflow:hidden;
position:relative;
}
.rounded {
position: absolute;
top: 10px;
border: 1px solid red;
width: 200px;
height: 50px;
}
Make the radius the same for both classes and make the height of .rounded to half the height of .circle. I also have changed the left and top values to align it.
HTML
<div class="circle"></div>
<div class="rounded"></div>
CSS
.circle {
width:150px;
height:150px;
border-radius:82px;
border:7px solid black;
}
.rounded {
position: absolute;
left: 12px;
top: 12px;
border: 1px solid red;
border-radius: 82px 0px 0px 0px;
width: 200px;
height: 75px;
}
Here's the fiddle: http://jsfiddle.net/Xs2Mr/.
Hope this helps!
I think Kai did it correctly, but in case you don't want it to touch the top of the circle, here is the best I could do with your fixed height of the red box.
http://jsfiddle.net/P63VY/18/
.circle {
width:150px;
height:150px;
border-radius:82px;
border:7px solid black;
}
.rounded {
position: absolute;
left: 20px;
top: 23px;
border: 1px solid red;
border-radius: 150px / 160px 0px 0px 0px;
width: 200px;
height: 50px;
}
try if any issue comment it
<style>
.circle {
border: 7px solid black;
border-radius: 82px 82px 82px 82px;
height: 150px;
margin-left: 1px;
width: 150px;
}
.rounded {
border: 1px solid red;
border-radius: 60px 0 0 0;
font-size: 30px;
height: 50px;
left: 20px;
line-height: 46px;
padding-left: 20px;
position: absolute;
top: 22px;
font-size:30px;
}
</style>
<div class="circle">
</div>
<div class="rounded">blah blah blah blah blah blah</div>
Got it working, but with a trick.
Here is the answer:
http://jsfiddle.net/Beck/P63VY/64/
Thanks for trying though ppl.
64 updates lol :D
<div id="rounded1" class="rounded"></div>
<div class="circle">
<div class="rounded"></div>
</div>
<div id="text">blah blah blah blah blah blah</div>
.circle {
width:150px;
height:150px;
border-radius:82px;
border:7px solid black;
overflow:hidden;
}
.rounded {
position: relative;
top: 23px;
left:-3px;
background:red;
width: 400px;
height: 50px;
}
#rounded1 {
position:absolute;
top:38px;
left:40px;
background:red;
}
#text {
position:absolute;
top:38px;
line-height:50px;
padding-left:20px;
font-size:30px;
color:white;
}

How do I create a box-shadow effect that looks like a curve?

I am familiar with creating basic box-shadows but I can't understand how to create something that looks like a curve. To better explain what I am looking for, I've attached the image. I need something similar to that. How can I create it?
I've tried to achieve that somehow with using absolute positioned elements, box shadow and a radial gradient. But overall I would use a background image.
But still have a look at my fiddle which unfortunately doesn't really look like your goal. But it might give you a starting point.
HTML
<div id="wrapper">
<ul id="nav">
</ul>
<div id="first"></div>
<div id="second"></div>
</div>
CSS
body {
background: #FEFEFE;
}
#wrapper {
position: relative;
display: block;
width: 960px;
height: 80px;
overflow: hidden;
}
ul {
height: 40px;
width: 100%;
background: #FFF;
box-shadow: 0px 3px 5px 0px #ccc;
position: absolute;
z-index: 300;
display: block;
padding: 0;
margin: 0;
border: solid 2px #EEE;
border-bottom: solid 1px #FEFEFE;
}
#first {
position: absolute;
background: none;
width: 800px;
height: 50px;
box-shadow: 0px 10px 50px 5px #000;
margin-left: -400px;
top:-20px;
left: 50%;
z-index: 100;
}
#second {
left: 50%;
position: absolute;
width: 900px;
z-index: 200;
margin-left: -450px;
height:80px;
top: 15px;
background: radial-gradient(ellipse at center, rgba(255,255,255,1) 0%,rgba(255,255,255,1) 15%,rgba(255,255,255,1) 25%,rgba(255,255,255,0.28) 79%,rgba(255,255,255,0) 100%); /* W3C */
}

Resources