I'm working on making a progress bar for this project i'm working on and i've half worked it out but now I've hit a wall that i can't seem to work out.
The problem I've got is that the child div doesn't dictate the parent div's width. (so the span doesn't tell progressbar that it should be 60% wide.)
Live demo can be found here -
http://codepen.io/anon/pen/BoGvvL
<div class="progress-container">
<div class="progressbar">
<span style="width:60%"></span>
</div>
</div>
CSS
* {
box-sizing:border-box;
}
.progress-container {
width:150px;
margin:0 auto;
background:#CDCDCD;
height:30px;
border-radius:8px;
padding:3px 5px;
}
.progressbar {
height: 24px;
width:0%;
max-width:100%;
border-radius:8px;
background: -webkit-linear-gradient(left, #f63a0f, #f2d31b, #86e01e);
background: -o-linear-gradient(right, #f63a0f, #f2d31b, #86e01e);
background: -moz-linear-gradient(right, #f63a0f, #f2d31b, #86e01e);
background: linear-gradient(to right, #f63a0f, #f2d31b, #86e01e);
}
Could someone direct me in the right way please?
Thanks in advance.
Any size in percent within a container will make the element with that size that percent of it's parent (given position: relative and probably some other edge cases I'm forgetting).
To use your example:
<div class="progress-container">
<div class="progressbar">
<span style="width:60%"></span>
</div>
</div>
The span will be 60% of .progressbar. This should be obvious simply by the definition of "percent" - it's "some amount of all (specifically 100, which we've collectively agreed is 'all')" or in your specific case: "Six tenths of the width".
What's stopping you from putting width: 60% on the .progressbar element? I did that in your CodePen and it worked wonderfully.
Example:
<div class="progress-container">
<div class="progressbar" style="width: 60%">
</div>
</div>
You can also view the following resource on progress bars: https://css-tricks.com/css3-progress-bars/ . This can give you details for what works with progress bars and some templates if you're interested.
To use the code that you've got you can use the following as an alternative (live-code here: http://codepen.io/anon/pen/RWqEXW#0)
HTML:
<div class="progress-container">
<span class="progressbar" style="width:60%">
</span>
</div>
CSS:
* {
box-sizing: border-box;
}
.progress-container {
position: relative;
width: 150px;
margin: 0 auto;
background: #CDCDCD;
height: 30px;
border-radius: 8px;
padding: 3px 5px;
}
.progressbar {
position: absolute;
height: 24px;
max-width: 100%;
border-radius: 8px;
background: -webkit-linear-gradient(left, #f63a0f, #f2d31b, #86e01e);
background: -o-linear-gradient(right, #f63a0f, #f2d31b, #86e01e);
background: -moz-linear-gradient(right, #f63a0f, #f2d31b, #86e01e);
background: linear-gradient(to right, #f63a0f, #f2d31b, #86e01e);
}
Note the insertion of position attributes and removal of the "width: 0%" in progressbar.
Good Luck!
You have several problems in your code.
First of all the span doesn't tell the progressbar it's 60%, because .progressbar have a width of 0( 60% X 0 = 0 ).
You should add display:block to the span, and also specify the height.
I edited your code and make it work in the way you expect. Here is a code pen: https://codepen.io/anon/pen/YyRBVW
You need to change the display property of the span element to block.
Your .progressbar selector should be large 100% and have no other styles applied. Use .progressbar span instead
SPAN elements are inline elements and you cannot assign them any size!
So, if you try something like that... probably it works!
function updateProgress() {
var val = document.querySelector('.val').value;
var el = document.querySelector('.progressbar span');
el.style.width = val + '%';
el.innerText = val + '%';
};
.progressbar {
background: red;
width: 100%;
font-size: 16px;
}
.progressbar span {
display: block;
text-align: center; color: #fff; transition: 300ms width linear;
line-height: 2em;
background: green;
max-width: 100%;
}
<div style="padding: 1em 0;"><input class="val" max="100" type="number" value="10" onchange="updateProgress()"/></div>
<div class="progressbar">
<span style="width: 10%;">10%</span>
</div>
Related
This question already has answers here:
Border Gradient with Border Radius
(2 answers)
Closed 13 days ago.
body {
margin: 0;
padding: 0;
background: linear-gradient(180deg, #2a5470 25%, #4c4177 100%);
}
.border {
padding: 10px;
border-radius: 20px;
background-image: linear-gradient(25deg, #2a5470 25%, #4c4177 100%);
}
.clock {
display: flex;
flex-direction: column;
align-items: center;
background: linear-gradient(180deg, #2a5470 25%, #4c4177 100%); //How do i make it continue gradient of body?
border-radius: 20px;
}
<body>
<div class="border">
<div class="clock">
<h2>Break/Session</h2>
<div>25:00</div>
</div>
</div>
</body>
Here's how it looks now
In order to make the border have gradient, i found out that i need to make separate div with background as this gradient and then adjust padding.
What i want to achieve is to make .clock background continue gradient of the body, just like it would without having .border around it.
Just take the gradient property outside and add the class names generally as listed below,
body {
margin: 0;
padding: 0;
background-repeat: no-repeat;
min-height: 100vh;
}
body,.clock {
background: linear-gradient(180deg, #2a5470 25%, #4c4177 100%);
}
.border {
padding: 10px;
border-radius: 20px;
background-image: linear-gradient(25deg, #2a5470 25%, #4c4177 100%);
max-width: 200px;
margin: 50px auto 0;
}
.clock {
display: flex;
flex-direction: column;
align-items: center;
border-radius: 20px;
}
h2, .clock div {
color: #fff;
}
.clock div {
font-size: 50px;
}
<body>
<div class="border">
<div class="clock">
<h2>Break/Session</h2>
<div>25:00</div>
</div>
</div>
</body>
Here is an idea on how to achieve this. Using nested divs like in your example might not be the easiest solution through, as you'd probably need to overwrite the inner divs background with some js obtained values, as there is no easy way to reset the background like that.
Edit: See this question for a better solution using just CSS: Border Gradient with Border Radius.
Scroll down for a JS solution.
Using css only with border-image
Answer taken from https://css-tricks.com/gradient-borders-in-css/ and adapted.
You can use the border-image css attribute to more easily achieve what you're looking for, if you don't need a border-radius.
I'm just using the wrapper here to increase the viewport of the example.
body {
margin: 0;
padding: 0;
background: linear-gradient(180deg, #2a5470 25%, #4c4177 100%);
}
.clock {
display: flex;
flex-direction: column;
align-items: center;
border: 15px solid;
border-image-source: linear-gradient(25deg, #2a5470 25%, #4c4177 100%);
border-image-slice: 1;
}
.wrapper {
height: 200px;
}
<body>
<div class="wrapper">
<div class="clock">
<h2>Break/Session</h2>
<div>25:00</div>
</div>
</div>
</body>
Using JS for an actually working solution
The idea here is that you can manually calculate the position of the clock inside the body element and set the background manually. This solution I present below is specifically tailored for this specific background and assumes things like "it will only ever be inside the parent element and never move outside". A more general solution would need to be much more extensive, but I hope it gets my idea across.
// update the background when scrolling
window.addEventListener("scroll", updateBackgroundColor);
const wrapper = document.querySelector("body");
const clock = document.querySelector(".clock");
function updateBackgroundColor(){
const wrapperRect = wrapper.getBoundingClientRect();
const clockRect = clock.getBoundingClientRect();
// in this case we only care about top and bottom, because the gradient is a straight 180°.
// so we get the relative position inside the outer relevant element
const relativePosition = {
top: (clockRect.top - wrapperRect.top) / wrapperRect.height,
bottom: (clockRect.top + clockRect.height - wrapperRect.top) / wrapperRect.height,
}
// since the gradient only starts at 25% down, we need to adjust the calculation to use those relative values instead
const startPercentage = 0.25;
// this math is just a fancy way of saying "(top - 0.25) * (4/3)" because that is what scales the values for us to the desired range.
relativePosition.top = (relativePosition.top - startPercentage) * ((1 / startPercentage) / ((1 - startPercentage) / startPercentage));
relativePosition.bottom = (relativePosition.bottom - startPercentage) * ((1 / startPercentage) / ((1 - startPercentage) / startPercentage));
// if value is negative, set to 0
if(relativePosition.top < 0) relativePosition.top = 0;
if(relativePosition.bottom < 0) relativePosition.bottom = 0;
let newTopColor = getGradientColor({r:42, g:84, b:112} /*#2a5470*/, {r:76, g:65, b:119} /*#4c4177*/, relativePosition.top);
let newBottomColor = getGradientColor({r:42, g:84, b:112} /*#2a5470*/, {r:76, g:65, b:119} /*#4c4177*/, relativePosition.bottom);
clock.style.background = `linear-gradient(180deg, rgb(${newTopColor.r}, ${newTopColor.g}, ${newTopColor.b}) 0%, rgb(${newBottomColor.r}, ${newBottomColor.g}, ${newBottomColor.b}) 100%)`;
}
// returns the linearly interpolated gradient color value between two colors
// colors are represented as {r:, g:, b:} objects for simplicity
function getGradientColor(color1, color2, percentage){
return {
r: color1.r + ((color2.r - color1.r) * percentage),
g: color1.g + ((color2.g - color1.g) * percentage),
b: color1.b + ((color2.b - color1.b) * percentage),
}
}
// run once so it works immediately not just after the first scrolling
updateBackgroundColor();
body {
margin: 0;
padding: 0;
background-repeat: no-repeat;
min-height: 200vh;
}
body, .clock {
background: linear-gradient(180deg, #2a5470 25%, #4c4177 100%);
}
.border {
padding: 10px;
border-radius: 20px;
background-image: linear-gradient(25deg, #2a5470 25%, #4c4177 100%);
max-width: 200px;
margin: 50px auto 0;
position: sticky;
top: 10px;
}
.clock {
display: flex;
flex-direction: column;
align-items: center;
border-radius: 20px;
}
h2, .clock div {
color: #fff;
}
.clock div {
font-size: 50px;
}
<!DOCTYPE html>
<html>
<body>
<div class="border">
<div class="clock">
<h2>Break/Session</h2>
<div>25:00</div>
</div>
</div>
</body>
</html>
Hi I am trying to create a highlight on a CSS shape as shown below.
There will also be content inside of the hexagon including image and text,
The highlight I am referring to is the part in the top left.
the code I currently have for creating the hexagon is:
HTML
<div class="hexagon-big"></div>
CSS
.hexagon-big {
position: relative;
width: 200px;
height: 115.47px;
background-color: #343434;
}
.hexagon-big:before,
.hexagon-big:after {
content: "";
position: absolute;
width: 0;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
}
.hexagon-big:before {
bottom: 100%;
border-bottom: 57.74px solid #343434;
}
.hexagon-big:after {
top: 100%;
width: 0;
border-top: 57.74px solid #343434;
}
There is other code for the content but i left it out because I don't think it is necessary
Do the hexagon shape differently and you can rely on gradient to create that highlight effect:
.hex {
width: 200px;
display: inline-flex;
margin:0 5px;
background:
conic-gradient(at top,#000 230deg, #0000 0),
linear-gradient(to bottom left,#fff , #000 60%);
clip-path: polygon(0% 25%,0% 75%,50% 100%,100% 75%,100% 25%,50% 0%);
}
.hex::before {
content: "";
padding-top: 115%; /* 100%/cos(30) */
}
<div class="hex"></div>
The solution in this answer is heavily based on the previous answer. To use clip-path and stacked gradients is by far the smartest thing to do here, but I still wanted to post this in order to show, how this solution could be improved and adjusted for your use case (text box, coloring, variables for maintenance, etc.).
.hexagon-big {
/* define box and text space */
width: 200px;
height: 230px;
padding: 10.8% 5px; /* adjust text box padding here; mind that top/bottom tip are part of the box */
box-sizing: border-box; /* width/height should include padding */
/* text formatting (optional) */
color: white;
text-align: center;
/* hex shape */
--hex-col: hsl(0deg 0% 20%); /* just your #343434 as a HSL color */
--hex-shadow: hsl(0deg 0% 50%); /* increased lightness by 15% to define highlight root color; 100% would be fully white */
background:
conic-gradient(at top, var(--hex-col) 232deg, transparent 0), /* change the angle of the shadow at "232deg": increase → narrower, decrease → wider */
linear-gradient(to bottom left, var(--hex-shadow), var(--hex-col) 55%);
clip-path: polygon(0% 25%,0% 75%,50% 100%,100% 75%,100% 25%,50% 0%);
}
<div class="hexagon-big">
Lorem ipsum dolor sit amet...
</div>
It should also be mentioned that your current way of using border is well better supported by older browsers than clip-path and conic-gradient (same with var()).
If this should be a problem, you might have to add another HTML tag and work out a way with transform: matrix(...) and box-shadow: inset ... (for example).
I want to change the color only of 1/3 of the bottom border and i want it to be changed only when someone clicks on the text (summer, spring or winter). Is it possible to do something like this with only CSS (with pseudo-elements like before or after) or do i have to use JS in this case?
HTML:
<div class="seasons">
<span id="text1">Summer</span>
<span id="text2">Spring</span>
<span id="text3">Winter</span>
</div>
CSS:
.seasons {
color: #B5BAB8;
display: inline-block;
margin: 10px;
border-bottom: 2px solid #B5BAB8;
padding-bottom: 15px;
margin-top: 465px;
}
.seasons span {
width: 250px;
display: inline-block;
}
Something like this could work using JS
CSS
.seasons {
color: #B5BAB8;
display: inline-block;
margin: 10px;
margin-top: 465px;
}
.seasons span {
width: 250px;
float: left;
padding-bottom: 15px;
border-bottom: 2px solid #B5BAB8;
}
.seasons span.highlighted {
border-bottom-color: red;
}
JS
$('.seasons span').on('click', function() {
$('.seasons span').removeClass('highlighted');
$(this).addClass('highlighted');
})
Edit: upps. I guess you want to change just 33% percentage of the full border. I thought you want to change 33% percentage of the each span elements border. Which has almost the same width the texts.
I tried your code on Codepen but, before suggestions, let me answer your question first:
Answer:
Yes you can -kinda- achive this without JS.
You have to use these following:
1. Linear gradient borders:
You can use
linear-gradient(to right, rgba(255,0,0,0) 0%, rgba(255,0,0,1) 100%);
for your borders. That percentages may change as you like.
2. :active, :focus or :hover pseudo states for these spans:
You can change that gradient for click (:active) state.
linear-gradient(to right, rgba(255,0,0,0) 30%, rgba(255,0,0,1) 70%);
3. Adding effects:
You can also use
transition: all .3s ease-in-out;
for your effect.
But my suggestion:
Using :after element with position: absolute for :active state.
You can create an :after element for these spans' :active states like this:
span:active:after{
content:"";
display: block;
position: absolute;
bottom: 1px;
width: 100px;
height: 5px;
display: block;
}
You can add background to this pseudo element or you can also add normal border for this element.
If positioning not works, try position: relative for parents. This also requires display: block for spans.
Here a possibility without JS.
input[type="radio"] {
display: none;
}
label {
cursor: pointer;
border-bottom: 3px solid #0ff;
}
label:not(:last-child) {
margin-right: 1em;
}
input[type="radio"]:checked+label {
border-bottom: 3px solid transparent;
border-image: linear-gradient(to right, #f0f 0%, #f0f 33%, #3acfd5 33%, #fff, #3acfd5 34%, #0ff, 34%, #0ff 100%);
border-image-slice: 1;
}
<div class="seasons">
<form>
<input id="summer" name="season" type="radio" value="summer">
<label for="summer">Summer</label>
<input id="spring" name="season" type="radio" value="spring">
<label for="spring">Spring</label>
<input id="winter" name="season" type="radio" value="winter">
<label for="winter">Winter</label>
</form>
</div>
I have following CSS class :
.acceptRejectAll a, .acceptRejectAll a:visited{
background-image: url("../images/view-patient.png");
background-position: left top;
background-repeat: no-repeat;
color: #4B555C;
float: left;
height: 35px;
padding-top: 12px;
text-align: center;
text-decoration: none;
width: 100px;
}
and following HTML :
<div style="float: none; display: inline-table" class="acceptRejectAll">
<a style="display:inline-block;height:25px;" href="#" class="fontBlack" id="ctl00_ContentPlaceHolder1_btnAcceptAll">Accept All</a>
</div>
this is display as follows :
when i decrease the size of in css class like : width : 85px
it displays as follows :
it cuts image from right side:
i tried to set background-Position in css class : but either left side or right side, image is not display correctly
wht is solution ?
Thanks
You will need to use background-size for this. Example:
background-size: 100% 100%;
Please note that this setting can scale your image to fill parent.
As the image is 100px (at least the visible part is about 92px so I guess the size is 100px) if you change the size of the button you need to scale the background image rather than change the position.
background-size:85px 35px;
Gradient and Border radius
Another way to approach this — considering the kind of button style you are using — is to go the gradient and border radius route. Whilst the code to use a css gradient looks rather messy, it is dynamically generated so you wont end up with stretched curved corners like you will using background-size.
Everything used below is pretty well supported now by most browsers. For anything that doesn't support the gradient you will get a solid blue background with curved corners instead, and it almost isn't worth worrying about non-support for border radius any more.
markup:
<div class="acceptRejectAll">
Accept All
</div>
css:
.acceptRejectAll {
display: inline-table;
border-radius: 20px;
text-align: center;
padding: 10px;
width: 100px; /* You can change the width as you like */
background: #c3e5fe; /* Old browsers */
background: -moz-linear-gradient(top, #c3e5fe 0%, #98d1fd 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#c3e5fe), color-stop(100%,#98d1fd)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #c3e5fe 0%,#98d1fd 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #c3e5fe 0%,#98d1fd 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #c3e5fe 0%,#98d1fd 100%); /* IE10+ */
background: linear-gradient(to bottom, #c3e5fe 0%,#98d1fd 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c3e5fe', endColorstr='#98d1fd',GradientType=0 );
}
.fontBlack {
font-family: sans-serif;
font-size: 10pt;
color: black;
text-decoration: none;
}
The gradient was generated using:
http://www.colorzilla.com/gradient-editor/#c3e5fe+0,98d1fd+100;Custom
You end up with:
http://jsfiddle.net/NDHtn/
Or as a preview:
When you must use an image
If there is no other choice but to use an image as a background for a button — say, the graphics are too complicated to replicate using css effects — rather than use one image stretched and distorted to fit, you can use something like the following. There are many ways to essentially achieve the same result, I prefer to keep my mark-up simple and my css more complicated (rather than the other way around). However, to make things more supportive of the wider browser community you can break your mark-up into three parts, rather than make use of ::before and ::after:
markup:
<a class="button" href="#">
<span>Round Button with lots of text and then some</span>
</a>
css:
.button:before {
position: absolute;
content: '';
background: url('image.png') left top;
top: 0;
left: -50px;
width: 50px;
height: 99px;
}
.button:after {
position: absolute;
content: '';
background: url('image.png') right top;
top: 0;
right: -50px;
width: 50px;
height: 99px;
}
.button {
background: url('image.png') center -99px;
height: 99px;
margin: 0 50px;
position: relative;
display: inline-block;
color: white;
text-decoration: none;
}
.button span { display: block; padding: 35px 0px; }
image.png, hacked together using this original image and pixlr.com:
Which will give:
http://jsfiddle.net/2K5Kg/1/
Example mark-up without use of psuedo elements:
<a class="button" href="#">
<span class="before"></span>
<span class="after"></span>
<span>Round Button with lots of text and then some</span>
</a>
Then in the css just replace the .button:before with .button .before and the same for :after.
I'm wondering if there's an easier way to create circular divs than what I'm doing now.
Currently, I am just making an image for each different size, but it's annoying to do this.
Is there anyway using CSS to make divs which are circular and I can specify the radius?
Here's a demo: http://jsfiddle.net/thirtydot/JJytE/1170/
CSS:
.circleBase {
border-radius: 50%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
}
.type1 {
width: 100px;
height: 100px;
background: yellow;
border: 3px solid red;
}
.type2 {
width: 50px;
height: 50px;
background: #ccc;
border: 3px solid #000;
}
.type3 {
width: 500px;
height: 500px;
background: aqua;
border: 30px solid blue;
}
HTML:
<div class="circleBase type1"></div>
<div class="circleBase type2"></div><div class="circleBase type2"></div>
<div class="circleBase type3"></div>
To make this work in IE8 and older, you must download and use CSS3 PIE. My demo above won't work in IE8, but that's only because jsFiddle doesn't host PIE.htc.
My demo looks like this:
Setting the border-radius of each side of an element to 50% will create the circle display at any size:
.circle {
border-radius: 50%;
width: 200px;
height: 200px;
/* width and height can be anything, as long as they're equal */
}
Try this
.iphonebadge {
border-radius:99px;
-moz-border-radius:99px;
-webkit-border-radius:99px;
background:red;
color:#fff;
border:3px #fff solid;
background-color: #e7676d;
background-image: -webkit-gradient(linear, left top, left bottom, from(#e7676d), to(#b7070a)); /* Saf4+, Chrome */
background-image: -webkit-linear-gradient(top, #e7676d, #b7070a); /* Chrome 10+, Saf5.1+, iOS 5+ */
background-image: -moz-linear-gradient(top, #e7676d, #b7070a); /* FF3.6 */
background-image: -ms-linear-gradient(top, #e7676d, #b7070a); /* IE10 */
background-image: -o-linear-gradient(top, #e7676d, #b7070a); /* Opera 11.10+ */
background-image: linear-gradient(top, #e7676d, #b7070a);
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#e7676d', EndColorStr='#b7070a');
-webkit-box-shadow: 0px 2px 4px #000000; /* Saf3-4 */
-moz-box-shadow: 0px 2px 4px #000000; /* FF3.5 - 3.6 */
box-shadow: 0px 2px 4px #000000; /* Opera 10.5, IE9, FF4+, Chrome 10+ */
display:inline-block;
padding:2px 2px 2px 2px ;
margin:3px;
font-family:arial;
font-weight:bold;
}
It is actually possible.
See: CSS Tip: How to Make Circles Without Images. See demo.
But be warned, It has serious disadvantages in terms of compatibility basically, you are making a cat bark.
See it working here
As you will see you just have to set up the height and width to half the border-radius
Good luck!
I have 4 solution to finish this task:
border-radius
clip-path
pseudo elements
radial-gradient
#circle1 {
background-color: #B90136;
width: 100px;
height: 100px;
border-radius: 50px;/* specify the radius */
}
#circle2 {
background-color: #B90136;
width: 100px;/* specify the radius */
height: 100px;/* specify the radius */
clip-path: circle();
}
#circle3::before {
content: "";
display: block;
width: 100px;
height: 100px;
border-radius: 50px;/* specify the radius */
background-color: #B90136;
}
#circle4 {
background-image: radial-gradient(#B90136 70%, transparent 30%);
height: 100px;/* specify the radius */
width: 100px;/* specify the radius */
}
<h3>1 border-radius</h3>
<div id="circle1"></div>
<hr/>
<h3>2 clip-path</h3>
<div id="circle2"></div>
<hr/>
<h3>3 pseudo element</h3>
<div id="circle3"></div>
<hr/>
<h3>4 radial-gradient</h3>
<div id="circle4"></div>
Let's say you have this image:
to make a circle out of this you only need to add
.circle {
border-radius: 50%;
width: 100px;
height: 100px;
}
So if you have a div you can do the same thing.
Check the example below:
.circle {
border-radius: 50%;
width: 100px;
height: 100px;
animation: stackoverflow-example infinite 20s linear;
pointer-events: none;
}
#keyframes stackoverflow-example {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
<div>
<img class="circle" src="https://www.sitepoint.com/wp-content/themes/sitepoint/assets/images/icon.javascript.png">
</div>
There's also [the bad idea of] using several (20+) horizontal or vertical 1px divs to construct a circle. This jQuery plugin uses this method to construct different shapes.
Give width and height depending on the size but,keep both equal
.circle {
background-color: gray;
height: 400px;
width: 400px;
border-radius: 100%;
}
<div class="circle">
</div>
.fa-circle{
color: tomato;
}
div{
font-size: 100px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div><i class="fa fa-circle" aria-hidden="true"></i></div>
Just wanted to mention another solution which answers the question of "Easier way to create circle div than using an image?" which is to use FontAwesome.
You import the fontawesome css file or from the CDN here
and then you just:
<div><i class="fa fa-circle" aria-hidden="true"></i></div>
and you can give it any color you want any font size.
You can try the radial-gradient CSS function:
.circle {
width: 500px;
height: 500px;
border-radius: 50%;
background: #ffffff; /* Old browsers */
background: -moz-radial-gradient(center, ellipse cover, #ffffff 17%, #ff0a0a 19%, #ff2828 40%, #000000 41%); /* FF3.6-15 */
background: -webkit-radial-gradient(center, ellipse cover, #ffffff 17%,#ff0a0a 19%,#ff2828 40%,#000000 41%); /* Chrome10-25,Safari5.1-6 */
background: radial-gradient(ellipse at center, #ffffff 17%,#ff0a0a 19%,#ff2828 40%,#000000 41%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
}
Apply it to a div layer:
<div class="circle"></div>
.circle {
height: 20rem;
width: 20rem;
border-radius: 50%;
background-color: #EF6A6A;
}
<div class="circle"></div>
You can use radius but it will not work on IE: border-radius: 5px 5px;.
basically this uses div's position absolute to place a character at the given coordinates. so using the parametric equation for a circle, you can draw a circle. if you were to change div's position to relative, it'll result in a sine wave...
in essence we are graphing equations by abusing the position property. i'm not versed well in css, so someone can surely make this more elegant. enjoy.
this works on all browsers and mobile devices (that i'm aware of). i use it on my own website to draw sine waves of text (www.cpixel.com). the original source of this code is found here: www.mathopenref.com/coordcirclealgorithm.html
<html>
<head></head>
<body>
<script language="Javascript">
var x_center = 50; //0 in both x_center and y_center will place the center
var y_center = 50; // at the top left of the browser
var resolution_step = 360; //how many times to stop along the circle to plot your character.
var radius = 50; //how big ya want your circle?
var plot_character = "·"; //could use any character here, try letters/words for cool effects
var div_top_offset=10;
var div_left_offset=10;
var x,y;
for ( var angle_theta = 0; angle_theta < 2 * Math.PI; angle_theta += 2 * Math.PI/resolution_step ){
x = x_center + radius * Math.cos(angle_theta);
y = y_center - radius * Math.sin(angle_theta);
document.write("<div style='position:absolute;top:" + (y+div_top_offset) + ";left:"+ (x+div_left_offset) + "'>" + plot_character + "</div>");
}
</script>
</body>
</html>
Adding the css property of:
border-radius: 50%;
to any div makes it circular.
For circle, create a div element and then enter width = 2 times of the border radius = 2 times padding. Also line-height = 0
For example, with 50px as radii of the circle, the below code works well:
width: 100px;
padding: 50px 0;
border: solid;
line-height: 0px;
border-radius: 50px;