I am trying to display numbers in circle which is number over total numbers for example 90/100.
Like this:
I tried like this but need small help because Circle is breaking up.
.kanban-circle{
border-radius: 50%;
width: 36px;
height: 36px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
}
<span class="kanban-circle">
<u>90</u>
<br></br>
100
</span>
Here it is, if you like more space between the number and the horizontal line, change the css for .line like { margin: 5px 0; }
.kanban-circle {
border-radius: 50%;
width: 36px;
height: 36px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
display: flex;
flex-direction: column;
}
.line {
padding: 0;
margin: 0;
width: 100%
}
span {
font-size: 15px;
}
<div class="kanban-circle">
<span>90</span>
<hr class="line" />
<span>100
</span></div>
The problem is with the <br> tag. I don't really know why, but through this tag, the lower number is not seen as part of the circle and the border is not drawn around it.
I experimented a little bit and came to following solution with following code:
.kanban-circle{
border-radius: 50%;
background-color: coral;
width: 70px;
height: 70px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
text-align: center;
font: 32px Arial, sans-serif;
}
<div class="kanban-circle">
<div>
<u>90</u>
110
</div>
</div>
I replaced span with div, but the result should be the same.
here the solution with also the comments, if you want to read it.
I make it responsive to the width, just change the width of parent element, and automatically change all the things inside!
the first 2 lines of CSS are css variables
--width: 3rem;
--color: #666;
Change their value, and all the elements will be changed automatically, and be show always good.
if you want to also be more responsive, you can use some new CSS units in --width: like vw, vh, %, etc... this is relative to something (parent elements, or viewport width, etc...)
so for responsive layout try to not use (avoid) absolute units like cm, px, in, pt. details: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units
in html I used <hr> instead of <br>
#container {
--width: 3rem;
--color: #666;
/* same height, same width */
width: var(--width);
height: var(--width);
/* responsive padding that is relative to the container width*/
padding: calc(var(--width) / 5);
/* always perfect circle */
border-radius: var(--width);
/* centering */
display: grid;
place-items: center;
/* coloring with the same color */
border: 2px solid var(--color);
color: var(--color);
/* font responsive to parent container */
font-size: calc(var(--width) / 3)
}
#container hr {
/* responsive width */
width: 100%;
/* removing a little bug if we use GRID */
margin: 0;
}
<div id="container">
<span>97</span>
<hr>
<span>100</span>
</div>
You could do it as below. Feel free to adjust it to your need.
.kanban-circle {
border-radius: 50%;
width: 86px;
height: 86px;
padding: 8px;
background: #fff;
border: 2px solid #666;
color: #666;
font: 32px Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.kanban-circle hr {
width: 100%;
margin:0;
border: 1px solid #666;
}
<span class="kanban-circle">
<span>90</span>
<hr/>
<span>100</span>
</span>
Related
Here I want to align this inside circle at the left border. As shown in the image by orange lines.
Here is my HTML code for this
<section style="height: 300px;border: 2px solid green;">
<ul id="Name_Section">
<li style=" border: 2px solid blue;">I AM PRAVEEN KUMAR </li>
<li id="logo"></li>
</ul>
</section>
Below is the CSS for this.
Ignore the extra code if there it is.
#Name_Section{
display: flex;
justify-content: space-around;
padding: 30px;
}
#Name_Section li{
list-style: none;
padding: 10px;
font-weight: bold;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
#logo{
outline: 1px solid rgb(255, 255, 255);
outline-offset: 15px;
background-color: rgb(38, 38, 54);
height: 120px;
width: 120px;
border-radius: 70px;
}
You only need two container for you to reproduce the effect you desire, basically the outer container should have a white border, the inside container containing the text should have a smaller dimension than the outer container. In my example there's a 2em height and width difference to achieve the effect. Both then sould have display: flex;, align-items and justify-content set to center, to align the items inside of them to the center. See the snippet below for your reference.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
section {
height: 300px;
border: 2px solid green;
background: #4A495B;
}
#Name_Section {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.outside {
display: flex;
justify-content: center;
align-items: center;
border: 1px solid grey;
border-radius: 50%;
height: 12em;
width: 12em;
}
.inside{
background: #272636;
color: #fff;
border-radius: 50%;
height: 10em;
width: 10em;
font-weight: bold;
font-family: Verdana, Geneva, Tahoma, sans-serif;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
<section>
<ul id="Name_Section">
<li class="outside">
<p class="inside">I AM PRAVEEN KUMAR </p>
</li>
</ul>
</section>
place the element inside a parent div that own the size, the padding and the border
the parent have a relative position
the logo have an absolute position
you can now move the child where you want in the parent with properties top, bottom, left or right
#logo{
background-color: rgb(38, 38, 54);
border-radius: 70px;
height: calc(100% - 14px);
width: calc(100% - 14px);
position: absolute;
right:0;
top:7px; //the midle of the parent padding
}
.element-border {
position:relative;
border: solid grey 1px;
border-radius: 70px;
padding: 14px;
height: 120px;
width: 120px;
}
<div class="element-border">
<div id="logo"></div>
</div>
Basically I am trying to achieve the hover effect as seen in the image below, but I'm not sure on how to make the background color exceed the borders of its parent container without effecting the height of the parent. I've attached a Codepen as well, thank you in advance!
What I want to replicate
/* =============
Base
============= */
#aspo-container {
background-color: #F3F5FF;
padding: 1.5em;
display: flex;
justify-content: center;
}
#aspo-container p {
font-size: rem-calc(20);
font-family: 'Barlow', sans-serif;
}
#aspo-container #aspo-inner-container {
display: flex;
flex-direction: row;
justify-content: space-between;
border: 3px solid #171838;
border-radius: 5px;
width: 50%;
}
#aspo-container #aspo-inner-container div:hover {
background-color: #171838;
color: #FFFFFF;
font-weight: 700;
}
#aspo-container #aspo-inner-container #activities {
text-align: center;
width: 100%;
border-right: 1.5px solid #171838;
cursor: pointer;
}
#aspo-container #aspo-inner-container #staffing {
text-align: center;
width: 100%;
border-left: 1.5px solid #171838;
border-right: 1.5px solid #171838;
cursor: pointer;
}
#aspo-container #aspo-inner-container #participation {
text-align: center;
width: 100%;
border-left: 1.5px solid #171838;
border-right: 1.5px solid #171838;
cursor: pointer;
}
#aspo-container #aspo-inner-container #outcomes {
text-align: center;
width: 100%;
border-left: 1.5px solid #171838;
cursor: pointer;
}
<main>
<section id="aspo-container">
<div id="aspo-inner-container">
<div id="activities" class="active">
<p>Activities</p>
</div>
<div id="staffing">
<p>Staffing</p>
</div>
<div id="participation">
<p>Participation</p>
</div>
<div id="outcomes">
<p>Outcomes</p>
</div>
</div>
</section>
</main>
This could be done with padding-top and a negative margin-top.
Note that I haven't tried very hard to make the example below look very nice, or look like your image, because I didn't see the point – presumably you have the code for most of it already. The snippet is just to demonstrate the method.
Hover over the text to see the effect.
nav {
height: 30px;
width: 340px;
border: 2px solid black;
padding-top: 10px;
font-family: sans-serif;
}
.nav-option {
display: inline-block;
height: 40px;
margin: 6px;
/* These are the important lines */
padding-top: 20px;
margin-top: -30px;
}
.nav-option:hover {
background-color: blue;
color: white;
}
<nav>
<div class="nav-option">Activities</div>
<div class="nav-option">Staffing</div>
<div class="nav-option">Participation</div>
<div class="nav-option">Outcomes</div>
</nav>
I would suggest using transform property of css with scale function to make it bigger on hover e.g transform:scale(1.5) ;
You can adjust number in scale to make it fit whichever size is needed.
I think this is close to what you want. I also added an animated transition, but as-is it's a bit buggy in my browser (leaves behind artifacts). The overall effect is achieved by increasing the padding the same as the negative margin.
A few notes:
Generally you wouldn't set widths on flex children if you want them to be fluid. flex-grow works better.
p elements aren't the best choice for menu items, both semantically and practically. Menu elements aren't usually paragraphs of text, and the default styling for p tags has extras you may wish to reset. So it's easier to use div or span, or the more semantic ul/li tags (although you would have to reset some of that styling also)
Changing font-weight on hover is problematic for fluid width elements, as it changes the element width, which causes jitter.
For this use case, you don't actually want any space-between the menu items, as you expect them to all be right next to each other.
It is a good idea to have the container padding be big enough to contain the hovered elements.
/* =============
Base
============= */
#aspo-container {
background-color: #F3F5FF;
padding: 1.5em;
justify-content: center;
}
#aspo-container #aspo-inner-container {
display: flex;
flex-direction: row;
border: 3px solid #171838;
border-radius: 5px;
}
#aspo-container #aspo-inner-container>div:hover {
background-color: #171838;
color: #FFFFFF;
margin: -0.5em;
padding: 1em;
border-radius: 5px;
}
#aspo-container #aspo-inner-container>div {
text-align: center;
flex-grow: 1;
border-right: 1.5px solid #171838;
border-left: 1.5px solid #171838;
cursor: pointer;
padding: .5em;
font-size: rem-calc(20);
font-family: 'Barlow', sans-serif;
transition: all linear 0.25s;
}
#aspo-container #aspo-inner-container>div:first-child {
border-left: none;
}
#aspo-container #aspo-inner-container>div:last-child {
border-right: none;
}
<main>
<section id="aspo-container">
<div id="aspo-inner-container">
<div id="activities" class="active">
Activities
</div>
<div id="staffing">
Staffing
</div>
<div id="participation">
Participation
</div>
<div id="outcomes">
Outcomes
</div>
</div>
</section>
</main>
So I have this code:
<h1 id="result" style="color:black; font-family: Bradley Hand; font-size:50px; position:absolute; top:17%; left:60%">
text
</h1>
How can I make a border that if I put a longer text in, my border will keep its position and change its size, to make my text still in the border? Thanks!
Just adding border: 1px solid black (for example) to what you have works perfectly fine. The h1 element will grow and shrink to fit it's content and the border will do so as well:
const result = document.getElementById('result');
const sentence = "HELLO! IT LOOKS LIKE THIS IS WORKING FINE...";
let index = 0;
setInterval(() => {
index = (index % sentence.length) + 1;
result.innerHTML = sentence.slice(0, index);
}, 250);
#result {
position:absolute;
top: 10%;
left: 10%;
padding: 0 .5rem;
font-family: Sans-Serif;
font-size: 2rem;
line-height: 3rem;
color: black;
border: 3px solid black;
border-radius: 3px;
min-height: 3rem;
}
<h1 id="result"></h1>
Anyway, I suspect you may be referring to the border changing your element's dimension:
#bar1 {
width: 50%;
height: 1rem;
background: red;
margin: .25rem;
}
#bar2 {
width: 50%;
height: 1rem;
background: cyan;
margin: .25rem;
border: 3px solid black;
}
<div id="bar1"></div>
<div id="bar2"></div>
That's because by default, your element's width and height are actually a sum of the specified width and height properties, plus padding plus border, as you can see from the example above.
If that's the case, you have two options to keep the dimensions just as specified with width and height:
Using box-sizing: border-box. That will make padding and border included in the element's total width and height.
Using box-shadow instead of border. You can use the inset property to draw the shadow to the inside of the element instead of to the outside.
#bar1 {
width: 50%;
height: 1rem;
background: red;
margin: .25rem;
}
#bar2 {
width: 50%;
height: 1rem;
background: cyan;
margin: .25rem;
border: 3px solid black;
box-sizing: border-box;
}
#bar3 {
width: 50%;
height: 1rem;
background: yellow;
margin: .25rem;
box-shadow: inset 0 0 0 3px black;
}
#bar4 {
width: 50%;
height: 1rem;
background: lime;
margin: .25rem;
box-shadow: 0 0 0 3px black;
}
<div id="bar1"></div>
<div id="bar2"></div>
<div id="bar3"></div>
<div id="bar4"></div>
Note the 4th bar, the one with the outer box-shadow looks bigger, but if you inspect it, its dimensions are exactly the same as those in the other 3 bars.
Can you just add border: solid 1px black; to the style attribute, like this?
<h1 id="result" style="border: solid 1px black; color:black; font-family: Bradley Hand; font-size:50px; position:absolute; top:17%; left:60%">text</h1>
Fiddle: https://jsfiddle.net/myingling/LL57yd8j/
Here's some reading on CSS borders: https://www.w3schools.com/css/css_border.asp
I have this CSS class:
.numberCircle {
border-radius: 30%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
width: 36px;
height: 36px;
padding: 0px 5px 0px 5px;
background: #fff;
border: 2px solid #333;
color: #333;
text-align: center;
font-size: large;
font-weight:bold;
}
I want to keep the same border width even when the number changes, from 10 to 9.
Right now, the border expands when the number changes.
Here's a JFiddle of what I mean.
I've already tried changing the padding attribute but I can't make it work.
Try this. Add display:inline-block and then line-height to vertically align the numbers. By setting this the box will expand. adjust the height & width as per your need. If so, do not forget to adjust the line-height relative to height of the box.
.numberCircle {
border-radius: 30%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
line-height:36px; /*vertcally center the numbers*/
width: 36px;
height: 36px;
padding: 0px 5px 0px 5px;
display:inline-block; /* Added */
background: #fff;
border: 2px solid #333;
color: #333;
text-align: center;
font-size: large;
font-weight:bold;
}
<span class='numberCircle'>10</span>
<span class='numberCircle'>9</span>
You can just explicitly set the width. I suggest a unit of mesure that's relative to the font size (namely ems)
Edit: it seems all you were missing was display:inline-block. You can't set the width of an inline element. Adding it will probably get you most of the way there.
.numberCircle {
border-radius: 30%;
behavior: url(PIE.htc); /* remove if you don't care about IE8 */
/*width: 36px;
height: 36px;*/
padding: 0px 5px 0px 5px;
background: #fff;
border: 2px solid #333;
color: #333;
text-align: center;
font-size: large;
font-weight:bold;
display: inline-block;
width: 1.5em;
height: 1.5em;
line-height: 1.5em;
}
<span class='numberCircle'>10</span>
<span class='numberCircle'>9</span>
Check out these properties:
line-height:20px; /*this will center your numbers inside the border*/
width: 20px; /*set the same as line-height and height in order to give a square shaped border*/
height: 20px; /*set the same as line-height and width in order to give a square shaped border*/
display: inline-block;
line-height, width and height will shape your box. While the new display property will help to align the elements in a "one after the other" fashion. :)
I'm trying to create some CSS to have a icon or image in the center with a line on both sides, but it seems like i'm doing something wrong and need some help.
For simplicity I just use a star character in the code.
<div class='line-container'><div class='line-icon'>*</div></div>
.line-icon {
text-align: center;
}
.line-icon::before {
width: 25%;
height: 1px;
border: 1px solid #ccc;
}
.line-icon::after {
width: 25%;
height: 1px;
border: 1px solid #ccc;
}
Try adding a content to your ::after and ::before, and setting its display:
.line-icon {
text-align: center;
}
/* Joined both selectors, since were pretty much the same */
.line-icon::before,
.line-icon::after {
/* Styles kept */
width: 25%;
height: 1px;
/* Changed to border-top (instead of border) to simulate a line better */
border-top: 1px solid #ccc;
/* Styles added */
display: inline-block;
content: '';
/* Use padding to vertical align the line */
/* Use padding in em for a responsive icon height */
padding-top: 0.5em;
/* Use margins to give the lines some spacement around the icon */
/* Use margins in % for a responsive spacement */
margin-left: 5%;
margin-right: 5%;
}
<div class='line-container'><div class='line-icon'>*</div></div>
A different style but may be usefull for u
.seperator {
padding: 0;
border: 0px;
border-top: 1px solid #ccc;
color: #000;
text-align: center;
}
.seperator:after {
content: "vs";
display: inline-block;
position: relative;
top: -0.7em;
font-size: 1.5em;
padding: 0 0.50em;
background: #fff;
}
<hr class="seperator"></hr>