how can i customize button like this..? - css

A image I designed on Figma:
My attempt:
.pagenumber {
display: flex;
width: 252.27px;
height: 45px;
justify-content: space-between;
align-items: center;
padding: 6.761954261954262% 0 0 37.680647534952171%;
}
button {
background: none;
border: none;
}
.no {
width: 65.750981091687478%;
padding: 0 12px 0 22.5px;
}
.numbers {
background: #ffe400;
border-radius: 50%;
height: 45px;
width: 45.24px;
}
.no a {
color: black;
font-family: Lobster;
font-size: 187.5%;
}
<div class="pagenumber">
<div class="arrowbtn">
<button type="submit" onclick="history.back(-1)"><i class="fas fa-greater-than fa-flip-horizontal fa-2x" style="color: #ffe400;"></i></button>
</div>
<div class="no">
<button class="numbers">1</button>
<button class="numbers">2</button>
<button class="numbers">3</button>
</div>
<div class="arrowbtn">
<button type="submit" method="get" action="/page2"><i class="fas fa-greater-than fa-2x" style="color: #ffe400;"></i></button>
</div>
</div>
I wanna a page number button like this image but I don't know how to make space between 1,2,3 button. The space between the buttons is 15.08px. If you find some drawback from my code pls notice me.

Try adding the flex properties to your .no class instead and update the width.
If you're just wanting a simple way to get spacing between your elements just set a desired width without using calc and space-between will do the rest.
If you're looking to get the exact spacing you desire then I recommend using calc to calculate what the width of the parent element should be to fit your required spacing.
My calculation explained:
Multiply the width of the 3 number elements (45.24px * 3)
Add that to the multiplication of the exact spacing you want between the number elements (15.08px * 2), in this case multiplying the desired spacing by 2 since you have 3 elements and only require 2 spaces in between.
Note that if you use the calc method you will have to update the calculation each time you update the number of elements you want to display.
.pagenumber {
display: flex;
width: 252.27px;
height: 45px;
justify-content: space-between;
align-items: center;
padding: 6.761954261954262% 0 0 37.680647534952171%;
}
button {
background: none;
border: none;
}
.no {
display: flex;
align-items: center;
justify-content: space-between;
width: calc(45.24px * 3 + 15.08px * 2);
padding: 0 12px;
}
.numbers {
background: #ffe400;
border-radius: 50%;
height: 45px;
width: 45.24px;
}
.no a {
color: black;
font-family: Lobster;
font-size: 187.5%;
}
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<div class="pagenumber">
<div class="arrowbtn">
<button type="submit" onclick="history.back(-1)"><i class="fas fa-greater-than fa-flip-horizontal fa-2x" style="color: #ffe400;"></i></button>
</div>
<div class="no">
<button class="numbers">1</button>
<button class="numbers">2</button>
<button class="numbers">3</button>
</div>
<div class="arrowbtn">
<button type="submit" method="get" action="/page2"><i class="fas fa-greater-than fa-2x" style="color: #ffe400;"></i></button>
</div>
</div>

<div class="pagenumber">
<div class="arrowbtn">
<button type="submit" onclick="history.back(-1)"><i class="fas fa-greater-than fa-flip-horizontal fa-2x" style="color: #ffe400;"></i></button>
</div>
<div class="no">
<button class="numbers">1</button>
<button class="numbers">2</button>
<button class="numbers">3</button>
</div>
<div class="arrowbtn">
<button type="submit" method="get" action="/page2"><i class="fas fa-greater-than fa-2x" style="color: #ffe400;"></i></button>
</div>
</div>
<style>
.pagenumber {
display: flex;
width: 252.27px;
height: 45px;
justify-content: space-between;
align-items: center;
padding: 6.761954261954262% 0 0 37.680647534952171%;
}
button {
background: none;
border: none;
}
.no {
padding: 0 12px 0 22.5px;
}
.numbers {
background: #ffe400;
border-radius: 50%;
height: 45px;
width: 45px;
margin-right: 15.08px;
}
.no :nth-last-child(1) {
margin-right: 0px;
}
.no a {
color: black;
font-family: Lobster;
font-size: 187.5%;
}
</style>
Remove the width on no and set margin-right on numbers will do.

Do you mean something like this?
button {background: yellow; border-radius:50%}
<button>1</button>
<button>2</button>
<button>3</button>

Hi to get space between your number button you just need to apply margin like margin: 0 5px or something on your number class and if you want to remove lines which is on number button apply text-decoration: none on anchor tag
like that...
<style type="text/css">
.pagenumber {
/*display: flex;*/
/*width: 252.27px;*/
height: 45px;
justify-content: space-between;
align-items: center;
padding: 6.761954261954262% 0 0 37.680647534952171%;
}
button {
background: none;
border: none;
}
.no {
width: 65.750981091687478%;
padding: 0 12px 0 22.5px;
}
.numbers {
background: #ffe400;
border-radius: 50%;
height: 45px;
width: 45.24px;
margin: 0 5px;
}
.no a {
color: black;
font-family: Lobster;
font-size: 187.5%;
text-decoration: none;
font-weight: bold;
}
</style>
<div class="pagenumber">
<div class="arrowbtn">
<button type="submit" onclick="history.back(-1)"><i class="fas fa-greater-than fa-flip-horizontal fa-2x" style="color: #ffe400;"></i></button>
</div>
<div class="no">
<button class=""><</button>
<button class="numbers">1</button>
<button class="numbers">2</button>
<button class="numbers">3</button>
<button class="">></button>
</div>
<div class="arrowbtn">
<button type="submit" method="get" action="/page2"><i class="fas fa-greater-than fa-2x" style="color: #ffe400;"></i></button>
</div>
</div>

Related

Side by side subitem, grand child of flex container sticks out of area

My goal is to do a "row" with three columns. The layout works but when I add a specific class (which doesn't have width) it makes the grandchild input stick out.
My html is:
<div class="product-box" >
<div class="flex-container">
<div class="flex-child">
<input class="qty-box">
</div>
<div class="flex-child">
<button type="button" class="qty-add-sub">
<span class="qty-add">+</span>
</button>
</div>
<div class="flex-child">
<button type="button" class="qty-add-sub">
<span class="qty-minus">-</span>
</button>
</div>
</div>
</div>
My css is:
.flex-container {
display: flex;
max-width: 180px;
}
.flex-child {
flex: 1;
}
.product-box {
display: flex;
flex-direction: column;
font-weight: 300;
width: 200px;
padding: 10px;
text-align: center;
background-color: #c5c5c5;
border-radius: 5px;
}
input.qty-box {
border: 2px solid rgb(179, 179, 179);
font-family: Arial, Helvetica, sans-serif;
border-radius: 5px;
font-weight: bold;
font-size: 22px;
height: 55px;
}
.qty-add {
color:rgb(84, 0, 0);
font-size: 30px;
}
.qty-minus {
color:rgb(84, 0, 0);
font-size: 30px;
}
The display appears like so:
Sandbox URL:
https://codesandbox.io/embed/html-css-forked-eu1680?fontsize=14&hidenavigation=1&theme=dark
So I've had a good look at this and there's a few thing to note:
Setting the width of the input box to 100% works but there's still an element that pokes out of the end, this is due to the box-sizing being content-box and not border-box. I've set the flex box so that the first child tries to grow and the buttons don't. I've also set a width for your buttons too. Example below
* {
box-sizing: border-box;
}
.flex-container {
display: flex;
gap:0.125rem;
}
.flex-child {
flex-grow: 0;
}
.flex-child:first-child {
flex-grow: 1;
}
.product-box {
font-weight: 300;
width: 200px;
padding: 10px;
background-color: #c5c5c5;
border-radius: 5px;
}
input.qty-box {
border: 2px solid rgb(179, 179, 179);
font-family: Arial, Helvetica, sans-serif;
border-radius: 5px;
font-weight: bold;
font-size: 22px;
height: 55px;
width: 100%;
}
.qty-add {
color: rgb(84, 0, 0);
font-size: 30px;
}
.qty-minus {
color: rgb(84, 0, 0);
font-size: 30px;
}
.qty-add-sub {
width: 2rem;
}
<div class="product-box">
<div class="flex-container">
<div class="flex-child">
<input class="qty-box" />
</div>
<div class="flex-child">
<button type="button" class="qty-add-sub">
<span class="qty-add">+</span>
</button>
</div>
<div class="flex-child">
<button type="button" class="qty-add-sub">
<span class="qty-minus">-</span>
</button>
</div>
</div>
</div>
The input default size is 20 characters, and there is not
enough space for that
input w3 schools
If you want to resize the input to less characters you can use
<input size="number">

aligned Icon on left input

I have a problem that I want to solve,the date icon when I set the alignment to the left does not move the icon tried all the ways and no benefit but work with me transform but it needs to reponsive on all screen and I must do it for all screens
.zsg-cp,
.zsg-datepicker-wrapper {
position: relative
}
.zsg-datepicker-wrapper .zsg-datepicker-link {
color: #006AFF;
font-size: 1.34em;
line-height: 1;
position: absolute;
left: 7px;
top: 5px
}
<div class="zsg-datepicker-wrapper">
<input name="dateField" type="text" value="" id="cal1DateField" min="2019-08-22" max="2020-08-22" class="zsg-datepicker">
<a id="wrapper" style="text-align:left;left:0;float:left;transform: translateX(50px);" href="" class="zsg-datepicker-link"><span class="zsg-icon-calendar"></span></a>
</div>
Try this with your own CSS classes
.input-container {
display: -ms-flexbox;
/* IE10 */
display: flex;
width: 100%;
margin-bottom: 15px;
}
.icon {
padding: 10px;
background: dodgerblue;
color: white;
min-width: 50px;
text-align: center;
}
.input-field {
width: 100%;
padding: 10px;
outline: none;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<form>
<div class="input-container">
<input class="input-field" type="text" placeholder="Date" name="dateField">
<i class="fa fa-calendar icon"></i>
</div>
</form>

Buttons inside three divs won't center

What I am trying to do is when the max width of a screen is 750px I want the buttons inside of my side-bar to be centered both vertically and horizontally using flexbox. Here is what I have tried:
.side-bar {
height: calc(100vh - 55px);
width: 18.5%;
background-color: #F5F5F5;
overflow: auto;
}
.side-bar .content {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
padding-top: 30px;
box-sizing: border-box;
}
.side-bar .button {
margin-bottom: 5px;
}
.side-bar .button:hover i {
color: dodgerblue;
}
.side-bar .button div {
text-align: left;
}
.side-bar .button form {
display: flex;
}
.side-bar .button a {
align-self: center;
margin-left: 12%;
margin-right: 5%;
}
.side-bar .button a i {
color: black;
font-size: 18px;
transition: 0.3s;
}
.side-bar .button input {
border: none;
font-size: 15px;
background-color: Transparent;
}
.side-bar .button input:active {
color: black;
}
.side-bar .sub-title {
margin-left: 12%;
}
.side-bar .sub-title p {
color: #6C6C6D;
font-weight: bold;
font-size: 14px;
}
#media (max-width: 750px) {
.side-bar .content {
justify-content: center;
}
.side-bar .button input {
display: none;
}
.side-bar .sub-title {
display: none;
}
}
<div class="side-bar">
<div class="content">
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-tachometer-alt"></i>
<input type="submit" value="Dashboard">
</form>
</div>
</div>
<div class="sub-title">
<p>TOOLS</p>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-minus-circle"></i>
<input type="submit" value="Ban Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-exclamation-circle"></i>
<input type="submit" value="Warn Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-gift"></i>
<input type="submit" value="Gift Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-user"></i>
<input type="submit" value="User Info">
</form>
</div>
</div>
<div class="sub-title">
<p>NEWS</p>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-newspaper"></i>
<input type="submit" value="News Panel">
</form>
</div>
</div>
</div>
</div>
When when I use justify-content on my content div the children of the content div aren't centered. I would like the buttons centered both vertically and horizontally.
Note on potential duplicates
Before anyone marks this a duplicate, it's not. I looked at the solutions to my last post about it being a duplicate for the same reason and it's not.
How my post is different from my previous post: My previous post I was trying to center a div inside a div, that didn't work out so I tried a different approach and got my result that I wanted. Now, I am trying to center my div inside three other divs but do not understand what it is not centering after using flexbox to center it.
I believe below solution fixes your issue. Content was a little off to the bottom, because .content had only padding-top: 30px, which I changed to padding: 30px 0. I also removed display: none rules, because then, well, nothing was inside this sidebar.
Key part
.side-bar .content {
...
padding: 30px 0;
...
}
Snippet
.side-bar {
height: calc(100vh - 55px);
width: 18.5%;
background-color: #F5F5F5;
overflow: auto;
}
.side-bar .content {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
padding: 30px 0;
box-sizing: border-box;
}
.side-bar .button {
margin-bottom: 5px;
}
.side-bar .button:hover i {
color: dodgerblue;
}
.side-bar .button div {
text-align: left;
}
.side-bar .button form {
display: flex;
}
.side-bar .button a {
align-self: center;
margin-left: 12%;
margin-right: 5%;
}
.side-bar .button a i {
color: black;
font-size: 18px;
transition: 0.3s;
}
.side-bar .button input {
border: none;
font-size: 15px;
background-color: Transparent;
}
.side-bar .button input:active {
color: black;
}
.side-bar .sub-title {
margin-left: 12%;
}
.side-bar .sub-title p {
color: #6C6C6D;
font-weight: bold;
font-size: 14px;
}
#media (max-width: 750px) {
.side-bar .content {
justify-content: center;
}
.side-bar .button input
}
.side-bar .sub-title {
}
}
<div class="side-bar">
<div class="content">
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-tachometer-alt"></i>
<input type="submit" value="Dashboard">
</form>
</div>
</div>
<div class="sub-title">
<p>TOOLS</p>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-minus-circle"></i>
<input type="submit" value="Ban Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-exclamation-circle"></i>
<input type="submit" value="Warn Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-gift"></i>
<input type="submit" value="Gift Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-user"></i>
<input type="submit" value="User Info">
</form>
</div>
</div>
<div class="sub-title">
<p>NEWS</p>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-newspaper"></i>
<input type="submit" value="News Panel">
</form>
</div>
</div>
</div>
</div>

How to get sidebar to take up 90% of the page when top bar is using pixels?

I've got a difficult question and have spent a good half-hour researching on what to do to fix this problem but have had no luck.
As you can see the in the below, there is a small gap on the bottom left of the picture. The gap is between the side bar and the bottom of the page. The side bar uses a percentage of 90% for it's height while the top bar using a height of 60px. The reason why I am using pixels for the top bar is because I do not want it to resize when resizing the window vertically. I have highlighted the problem in a red box, here is the screenshot...
HTML
<div class="wrapper">
<div class="top-bar">
<div class="left">
<div class="title">
<p>Cold Ops</p>
</div>
</div>
<div class="right">
</div>
</div>
<div class="side-bar">
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-tachometer-alt fa-lg"></i>
<input type="submit" value="Dashboard">
</form>
</div>
</div>
<div class="sub-title">
<p>TOOLS</p>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-ban fa-lg"></i>
<input type="submit" value="Ban Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-exclamation-circle fa-lg"></i>
<input type="submit" value="Warn Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-gift fa-lg"></i>
<input type="submit" value="Gift Panel">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-user fa-lg"></i>
<input type="submit" value="User Info">
</form>
</div>
</div>
<div class="sub-title">
<p>NEWS</p>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-file fa-lg"></i>
<input type="submit" value="New Post">
</form>
</div>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-trash fa-lg"></i>
<input type="submit" value="Remove Post">
</form>
</div>
</div>
<div class="sub-title">
<p>OTHER</p>
</div>
<div class="button">
<div>
<form action="http://google.com">
<i class="fas fa-chart-pie fa-lg"></i>
<input type="submit" value="Game Statistics">
</form>
</div>
</div>
</div>
</div>
CSS
body {
margin: 0;
padding: 0;
background-color: #FAFAFA;
font-family: sans-serif;
}
.wrapper {
height: 100vh;
}
.top-bar {
display: flex;
width: 100%;
height: 60px;
background-color: white;
box-shadow: 0 5px 5px -5px rgba(169,169,169,0.5);
}
.top-bar .left {
flex: 2.195;
}
.top-bar .left .title {
display: flex;
justify-content: center;
height: 100%;
}
.top-bar .left .title p {
align-self: center;
font-weight: lighter;
font-size: 18px;
}
.top-bar .right {
flex: 10;
background-color: white;
}
.side-bar {
display: flex;
flex-direction: column;
overflow: auto;
width: 18%;
margin-top: 1px;
height: 89.9%;
background-color: white;
box-shadow: 3px 0 10px -5px rgba(169,169,169,0.5);
}
.side-bar > div:first-of-type {
margin-top: 25px;
margin-left: 12%;
}
.side-bar .button {
position: relative;
margin-left: 12%;
margin-bottom: 3px;
}
.side-bar .button div {
text-align: left;
}
.button form input {
margin-left: 40px;
background-color: Transparent;
border: none;
font-size: 14px;
}
.button form input:active {
color: black;
}
.button form i {
color: black;
font-size: 16px;
transition: 0.3s;
position: absolute;
left: 0px;
top: 2.5px;
padding: 5px 0px;
}
.button:hover form i {
color: dodgerblue;
}
.sub-title {
margin-top: 12px;
margin-left: 12%;
}
.sub-title p {
font-size: 13px;
font-weight: bold;
color: #7A8B92;
}
Note: When the window is not in full-screen mode this issue does not occur.
If you have extra time: what do you think of the theme and my CSS code? Can it be improved? Is it good?

How to float to the right of, and level with block-level elements

I want a web page that looks like this ...
header {
border-style: solid;
border-top-width: 5px;
background-color: red;
}
p {
background-color: yellow;
}
header #btnLogIn {
float: right;
position: absolute;
right: 170px;
top: 40px;
}
header #btnGoogleLogIn {
float: right;
position: absolute;
right: 30px;
top: 40px;
}
<header>
<h1>Site Title</h1>
<button id="btnLogIn" type="button">Log in</button>
<button id="btnGoogleLogIn" type="button">Log in with Google</button>
</header>
<hr/>
<p>Some text</p>
The buttons need to be on the same horizontal level as the h1 header, floating to the right, with some nice margin in between. The button captions can change dynamically (via language selection), so any solution with hard-coded right property values is a fail.
How can I get the buttons to float to the right, on the same row as the h1 element, in a way that is independent of button width? The solution needs to be css.
Use flexbox like this:
header {
border-style: solid;
border-top-width: 5px;
background-color: red;
display: flex;
align-items: center;
}
p {
background-color: yellow;
}
header button {
margin: 0 10px;
}
header h1 {
margin-right: auto;
}
<header>
<h1>Site Title</h1>
<button id="btnLogIn" type="button">Log in</button>
<button id="btnGoogleLogIn" type="button">Log in with Google</button>
</header>
<hr>
<p>Some text</p>
Flexbox is the answer:
HTML:
<header>
<div class="header-left">
<h1>Site Title</h1>
</div>
<div class="header-right">
<button class="btn" type="button">Log in</button>
<button class="btn" type="button">Log in with Google</button>
</div>
</header>
<hr/>
<p>Some text</p>
CSS:
header {
border-style: solid;
border-top-width: 5px;
background-color: red;
display: flex;
align-items: center;
justify-content: space-between;
}
header .btn {
margin: 0 10px;
}
p {
background-color: yellow;
}
Would this work for you?
header {
border-style: solid;
border-top-width: 5px;
background-color: red;
display: flex;
align-items: center;
}
header h1 {
flex: 1;
}
header button {
margin: 0 1em;
}
p {
background-color: yellow;
}
<header>
<h1>Site Title</h1>
<button id="btnLogIn" type="button">Log in</button>
<button id="btnGoogleLogIn" type="button">Log in with Google</button>
</header>
<hr/>
<p>Some text</p>

Resources