This question already has answers here:
How to use CSS to surround a number with a circle?
(20 answers)
Closed 7 months ago.
I'm trying to make the divs round as much as possible. however it should be "small", without having to increase width and height to 100px.
image of my calcualtor
here is the code:
.contas div {
color: white;
display: inline-block;
border: 0;
width: 40px;
border-radius: 100%;
text-align: center;
padding: 10px;
margin: 20px 4px 10px 1px;
cursor: pointer;
background-color: #202020;
transition: border-color .2s ease-in-out, background-color .2s, box-shadow .2s;
}
If you really want to get a circle, you need an equal amount of height and width on your div.
That way you get a square.
Then you add a border-radius of 50% for the perfect circle.
You're less likely to get a perfect circle if the height and width of the div are not the same.
Use for buttons display:inline-flex; and border-radius: 50%;
here is code HTML:
<aricle class="contas">
<!-- row 0 -->
<input class="contas__head" placeholder="0" type="text" />
<!-- row 1 -->
<button class="contas__btn">C</button>
<button class="contas__btn">()</button>
<button class="contas__btn">%</button>
<button class="contas__btn">/</button>
<!-- row 2 -->
<button class="contas__btn">7</button>
<button class="contas__btn">8</button>
<button class="contas__btn">9</button>
<button class="contas__btn">*</button>
<!-- row 3 -->
<button class="contas__btn">4</button>
<button class="contas__btn">5</button>
<button class="contas__btn">6</button>
<button class="contas__btn">-</button>
<!-- row 4 -->
<button class="contas__btn">1</button>
<button class="contas__btn">2</button>
<button class="contas__btn">3</button>
<button class="contas__btn">+</button>
<!-- row 5 -->
<button class="contas__btn">+/-</button>
<button class="contas__btn">0</button>
<button class="contas__btn">.</button>
<button class="contas__btn">=</button>
</aricle>
here is code SCSS:
$contas-color: #f2f2f2;
$contas-fill: #000000;
$contas-fill-light:#202020;
$contas-radius: 1rem;
$contas-space: 0.75rem;
$contas-field-size: 4rem;
$contas-btn-size: var(--contas-btn-size, 2.5rem);
$contas-btn-hover-fill: #ff810f;
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 1.5rem;
background-color: $contas-color;
}
.contas {
position: relative;
display: grid;
grid-gap: 0.8rem 0.5rem;
grid-template-columns: repeat(4, $contas-btn-size);
justify-content: center;
align-items: center;
width: 12.5rem;
padding: calc(#{ $contas-field-size + ($contas-space* 1.5)}) $contas-space ($contas-space* 1.5) ;
background-color: $contas-fill;
border-radius: $contas-radius;
overflow: hidden;
&__head {
position: absolute;
inset: 0 0 auto;
min-height: $contas-field-size;
padding: 0 ($contas-space*1.5);
font-size: 1.5rem;
font-weight: 500;
text-align:right;
color:$contas-color;
border: unset;
user-select: none;
background: $contas-fill-light;
pointer-events:none;
&:focus, &:active, &:hover {
color:$contas-color;
outline: none;
box-shadow: none;
}
}
&__btn {
display: inline-flex;
align-items: center;
justify-content: center;
color: white;
width: $contas-btn-size;
aspect-ratio: 1 / 1;
text-align: center;
border-radius: 50%;
border: unset;
background-color: $contas-fill-light;
transition: .3s lianer;
transition-property: background-color, box-shadow, transform;
cursor: pointer;
&:hover, &:active{
background-color: $contas-btn-hover-fill;
}
&:active{
transform: scale(1.15);
}
}
}
see https://jsfiddle.net/d4htsLgb/2/
You can fix it using pixels instead of percents:
.contas .div {
border-radius: 99999px;
}
Related
This question already has answers here:
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
Closed 1 year ago.
CodeSandbox:
https://codesandbox.io/s/eloquent-haibt-1bnib?file=/src/main.js
I want to center the - text in the button, but I cannot find a way to do it.
html
<button class="round-button align-middle mr-1">
<span>-</span>
</button>
css
.round-button {
min-width: 20px;
max-height: 20px;
text-decoration: none;
display: inline-block;
outline: none;
cursor: pointer;
border-style: none;
color: white;
background-color: #3498db;
border-radius: 100%;
overflow: none;
text-align: center;
padding: 0;
}
.round-button:before {
content: "";
display: inline-block;
vertical-align: middle;
}
html
<button class="round-button align-middle mr-1">-</button>
css
.round-button {
min-width: 20px;
height: 20px;
border-style: none;
color: white;
background-color: #3498db;
border-radius: 50%;
text-align: center;
padding: 0;
line-height: 20px; // to center text vertically
}
You just need to add the same line-height as your button's height and don't need an extra span element to add text. I've also removed unnecessary styles.
Try setting line-height: 20px to that. If it still looks off, you might be using a custom font with non-standard line height. In this case play with the line-height property until it looks okay.
Add the following style properties to .round-button:
.round-button {
display: flex;
align-items: center;
justify-content: center;
}
And, remove style for .round-button:before.
Try this.
.round-button {
background-color: #3498db;
border-style: none;
border-radius: 100%;
color: #fff;
cursor: pointer;
aspect-ratio: 1 / 1;
width: 48px;
display: flex;
align-items: center;
justify-content: center;
}
<button class="round-button">
<span>-</span>
</button>
Try changing <span>-</span> to <span style="position:relative; left:0px; top:-3px">-</span>. If it doesn't look right you can play around with it.
I want to show a list of tags at the bottom of the screen and if they don't all fit, I want it to wrap so that it's the first line that is the shortest - not the last line.
Once the bottom line is full, I would prefer if the next item added would be what would then appear above instead of below. But if it's easier to make the first item move up that would be ok too.
This example should make it clear:
div {
position: fixed;
bottom: 0%;
right: 0%;
line-height: 1.4;
text-align: right;
}
span {
border-radius: 5px;
padding: 1px 3px;
font-family: sans-serif;
color: white;
background-color: #7B68EE;
}
<div>
<span>Apple</span>
<span>Orange</span>
<span>Banana</span>
<span>Pear</span>
<span>Apricot</span>
<span>Cranberry</span>
<span>Blackcurrant</span>
<span>Raspberry</span>
<span>Strawberry</span>
<span>Plum</span>
<span>Tomato</span>
<span>Lemon</span>
<span>Lime</span>
<span>Coconut</span>
</div>
This can be achieved by adding flexbox styles to the parent container like so:
div {
position: fixed;
bottom: 0%;
right: 0%;
line-height: 1.4;
text-align: right;
/* flexbox styles */
display: flex;
flex-wrap: wrap-reverse;
justify-content: flex-end;
}
span {
border-radius: 5px;
padding: 1px 3px;
font-family: sans-serif;
color: white;
background-color: #7B68EE;
/* margin to separate tags */
margin: 0.1em;
}
<div>
<span>Apple</span>
<span>Orange</span>
<span>Banana</span>
<span>Pear</span>
<span>Apricot</span>
<span>Cranberry</span>
<span>Blackcurrant</span>
<span>Raspberry</span>
<span>Strawberry</span>
<span>Plum</span>
<span>Tomato</span>
<span>Lemon</span>
<span>Lime</span>
<span>Coconut</span>
</div>
Try using display:flex, also use flex-wrap:wrap-reverse in order to wrap the elements the way you want.
div {
display: flex;
flex-wrap: wrap-reverse;
position: fixed;
bottom: 0%;
right: 0%;
line-height: 1.4;
text-align: right;
}
span {
border-radius: 5px;
padding: 1px 3px;
font-family: sans-serif;
color: white;
background-color: #7B68EE;
}
Using flex property to align like this,
div {
display: flex;
flex-wrap: wrap-reverse; // reverse the wrapping
flex-direction: row-reverse; // reverse the row
}
also add some margin to span
span{
margin:3px;
}
flex-wrap - The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked.
flex-direction: row-reverse - Work in a left-to-right language such as English. If you are working in a right-to-left language like Arabic then row would start on the right, row-reverse on the left.
Result:-
LIVE DEMO
div {
position: fixed;
bottom: 0%;
right: 0%;
line-height: 1.4;
display: flex;
flex-wrap: wrap-reverse;
flex-direction: row-reverse;
}
span {
border-radius: 5px;
padding: 1px 3px;
font-family: sans-serif;
color: white;
background-color: #7B68EE;
margin:3px;
}
<div>
<span>Apple</span>
<span>Orange</span>
<span>Banana</span>
<span>Pear</span>
<span>Apricot</span>
<span>Cranberry</span>
<span>Blackcurrant</span>
<span>Raspberry</span>
<span>Strawberry</span>
<span>Plum</span>
<span>Tomato</span>
<span>Lemon</span>
<span>Lime</span>
<span>Coconut</span>
</div>
So, my objective here is to have the div slide in once the state (React) value is met, but all it ever does is abruptly appear instead of slide in from off the screen.
.network-message {
position: relative;
top: -67px;
width: 100%;
height: 5vh;
display: flex;
justify-content: center;
background-color: red;
color: #fff;
font-size: calc(15px + (17 - 15) * (100vw - 1440px) / (2560 - 1440));
align-items: center;
transition: transform 1s ease-in;
transform: translateY(67px);
.network-button {
margin-left: 2em;
button {
border: none;
padding: 0.5em 1.5em;
background-color: #254294;
color: #fff;
font-size: calc(11px + (13 - 11) * (100vw - 1440px) / (2560 - 1440));
cursor: pointer;
}
}
}
<div class='network-message'>
Looks like Microsoft's CRM is down at the moment. Please be patient
while they work to resolve the issue.
<div class='network-button'>
<button type='button'>
OK
</button>
</div>
</div>
I am dealing with text blocks (background blocks over text) and face some issues with paddings on new line. The problem occurs when the browser(e.g. mobile) cuts the text into to two lines due to lack of width. text then looks like this:
I don't really know how to set a padding css on the end of the new lines, since it could break up anywhere of the sentence. You could say put a span on it with padding, but it is not fixed where the line will break down. It depends on the width. Any recommendations?
You could apply display: inline-block but that will turn the background color into an ugly box which doesn't look as nice as having an exact width background for each line. Unfortunately CSS doesn't let us target individual lines except for the first one.
If you don't mind getting a little "creative" (or hacky) you could wrap each word in its own element in the backend or using JavaScript and apply the background color to those elements. Adjust the parent's word-spacing accordingly to eliminate gaps.
.main {
font-family: sans-serif;
font-weight: bold;
background-color: #99c;
display: flex;
height: 400px;
flex-direction: row;
align-items: center;
}
.text-container {
max-width: 500px;
display: inline-block;
word-spacing: -15px;
position: relative;
padding-left: 20px;
overflow: hidden;
}
.text-container::before {
content: '';
background-color: black;
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 100%;
z-index: 1;
}
span {
font-size: 36px;
line-height: 1.5em;
color: white;
background-color: black;
padding: 0.25em 0.5em 0.25em 0;
max-width: 360px;
}
<div class="main">
<div class="text-container">
<span>A</span> <span>Movie</span> <span>in</span> <span>the</span> <span>park:</span> <span>Kung</span> <span>Fu</span> <span>Panda</span>
</div>
</div>
You can use box-shadow for this issue and display inline:
<div class="text">
<span class="text-container">A Movie in the park: Kung Fu Panda</span>
</div>
And css:
.text > span {
display: inline;
box-shadow: 25px 0 0 black, -10px 0 0 black;
background-color: black;
color: white;
}
Try to add after "Park:" and before "Kung"
padding workded!!!
change width by console browser and see result:
h1{
background-color: #ff6a6a;
padding: 33px;
display: inline-block;
word-wrap: break-word;
width:300px
}
<h1>rert ert erttttttttttttttt 00000000000000000000 dfgdfgd dfgdfgdft ertert </h1>
Use <p> tag to wrap up the text and it apparently works demo
<div class="main">
<div class="text-container">
<p id="test">A Movie in the park: Kung Fu Panda</p>
</div>
</div>
css
.main {
font-family: sans-serif;
font-weight: bold;
background-color: #99c;
display: flex;
height: 400px;
flex-direction: row;
align-items: center;
}
.text-container {
max-width: 400px;
}
p {
font-size: 36px;
line-height: 2em;
color: white;
background-color: black;
padding: 0.5em;
max-width: 360px;
}
I have a bunch of inline buttons made using anchor tags and CSS. I am making them so that on hover the main text shrinks in size and some subtext displays underneath. For some reason when I do that my button gets out of line with the other buttons and things just don't look right. Any help would be appreciated.
Here is my code
HTML
<div class="day-picker">
<a href="#" data-day="0" class="dayChange button">
<span class="day">Wednesday</span>
<span class="date">January 27th, 2016</span>
</a>
<a href="#" data-day="1" class="dayChange button selected">
<span class="day">Thursday</span>
<span class="date">January 28th, 2016</span>
</a>
<a href="#" data-day="2" class="dayChange button">
<span class="day">Friday</span>
<span class="date">January 29th, 2016</span>
</a>
<a href="#" data-day="3" class="dayChange button">
<span class="day">Saturday</span>
<span class="date">January 30th, 2016</span>
</a>
</div>
CSS
.button {
border-radius: 10px;
border: 2px solid #fff;
display: inline-block;
margin: 20px;
font: 300 18px HelveticaNeue;
color: #ffffff;
padding: 15px 35px; }
#media (max-width: 47.9em) {
.button {
width: 80%; } }
.button:hover {
color: #ffffff;
text-decoration: none;
-webkit-animation-name: button-hover;
animation-name: button-hover;
-webkit-animation-duration: 2s;
animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite; }
.button.on-white {
border-color: #00aeef;
color: #00aeef; }
.button.on-white:hover {
-webkit-animation-name: button-hover-on-white;
animation-name: button-hover-on-white; }
.selector {
text-align: center;
padding: 80px;
background: url(/images/agenda-bg.png) no-repeat;
background-size: cover; }
.selector .button {
border: 2px solid #00aeef;
border-radius: 10px;
color: #00aeef;
min-width: 223px;
text-align: center;
-webkit-animation: none;
animation: none; }
.selector .button.selected {
background-color: #00aeef;
color: #FFF; }
.selector .button .day {
display: block;
font-size: 22px; }
.selector .button .date {
display: none;
font-size: 8px; }
.selector .button.selected, .selector .button:hover {
text-decoration: none; }
.selector .button.selected .day, .selector .button:hover .day {
font-size: 14px; }
.selector .button.selected .date, .selector .button:hover .date {
display: block; }
the full code with scss is on my jsfiddle
The reason your buttons move when you hover is that your button height is not set, so it shrinks and expands with its content.
When you change the font size, your button height is smaller (even though you add the other line).
You can fix this in a couple of ways.
The easiest and most reliable (cross-browser, cross-platform) is to give it a set height:
.button{
...
height: 48px;
}
but this a lot of scaling issues and isn't very responsive.
Another option is to adjust your font size(s) until they don't move, this will likely give you poor cross-anything support.
If you're only targeting newer browsers you could give vw, vh, and vmin a try. They size things based on the width, height, and smaller of the two of the viewport respectively. For example, 10vw is 10% of the viewport's width.