I'm creating a number pad on screen. I would like to either center the number 0 or to make a larger button to cover the whole area of the div.
Here is the code that I'm using:
.numPad {
border: 1px solid #b7b7b7;
width: 100px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
padding: 0px;
background-color: #f1f1f1;
}
.numPad button {
padding: 5px;
background-color: #f1f1f1;
border: 1px solid #b7b7b7;
outline: none;
color: #000;
padding: 5px 5px;
text-align: center;
text-decoration: none;
font-size: 16px;
font-family: 'Cinzel Decorative', cursive;
margin: 0;
cursor: pointer;
z-index: 0;
transform: scale(1);
transition: all 0.05s;
}
.numPad button:active {
z-index: 1;
background-color: #dedede;
transform: scale(1.15);
}
.zero {
display: block !important;
width: 100%;
}
The .zero class is the one trying to give that 0 button's effect.
Here is the HTML:
<div class="numPad">
<button value="1">1</button>
<button value="2">2</button>
<button value="3">3</button>
<button value="4">4</button>
<button value="5">5</button>
<button value="6">6</button>
<button value="7">7</button>
<button value="8">8</button>
<button value="9">9</button>
<button value="0" class="zero">0</button>
</div>
Thank you for your time and help!
To fill whole space use grid-column: 1 / span 3;
.numPad {
border: 1px solid #b7b7b7;
width: 100px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
padding: 0px;
background-color: #f1f1f1;
}
.numPad button {
padding: 5px;
background-color: #f1f1f1;
border: 1px solid #b7b7b7;
outline: none;
color: #000;
padding: 5px 5px;
text-align: center;
text-decoration: none;
font-size: 16px;
font-family: 'Cinzel Decorative', cursive;
margin: 0;
cursor: pointer;
z-index: 0;
transform: scale(1);
transition: all 0.05s;
}
.numPad button:active {
z-index: 1;
background-color: #dedede;
transform: scale(1.15);
}
.zero {
grid-column: 1 / span 3;
}
<div class="numPad">
<button value="1">1</button>
<button value="2">2</button>
<button value="3">3</button>
<button value="4">4</button>
<button value="5">5</button>
<button value="6">6</button>
<button value="7">7</button>
<button value="8">8</button>
<button value="9">9</button>
<button value="0" class="zero">0</button>
</div>
To fill middle of keypad use grid-column: 2 / span 1;
.numPad {
border: 1px solid #b7b7b7;
width: 100px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
padding: 0px;
background-color: #f1f1f1;
}
.numPad button {
padding: 5px;
background-color: #f1f1f1;
border: 1px solid #b7b7b7;
outline: none;
color: #000;
padding: 5px 5px;
text-align: center;
text-decoration: none;
font-size: 16px;
font-family: 'Cinzel Decorative', cursive;
margin: 0;
cursor: pointer;
z-index: 0;
transform: scale(1);
transition: all 0.05s;
}
.numPad button:active {
z-index: 1;
background-color: #dedede;
transform: scale(1.15);
}
.zero {
grid-column: 2 / span 1;
}
<div class="numPad">
<button value="1">1</button>
<button value="2">2</button>
<button value="3">3</button>
<button value="4">4</button>
<button value="5">5</button>
<button value="6">6</button>
<button value="7">7</button>
<button value="8">8</button>
<button value="9">9</button>
<button value="0" class="zero">0</button>
</div>
You may set the grid column to centre the number 0 button.
.zero {
display: block !important;
grid-column: 2 / 3; /* set grid column */
width: 100%;
}
.numPad {
border: 1px solid #b7b7b7;
width: 100px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
padding: 0px;
background-color: #f1f1f1;
}
.numPad button {
padding: 5px;
background-color: #f1f1f1;
border: 1px solid #b7b7b7;
outline: none;
color: #000;
padding: 5px 5px;
text-align: center;
text-decoration: none;
font-size: 16px;
font-family: 'Cinzel Decorative', cursive;
margin: 0;
cursor: pointer;
z-index: 0;
transform: scale(1);
transition: all 0.05s;
}
.numPad button:active {
z-index: 1;
background-color: #dedede;
transform: scale(1.15);
}
.zero {
display: block !important;
grid-column: 2 / 3; /* set grid column */
width: 100%;
}
<div class="numPad">
<button value="1">1</button>
<button value="2">2</button>
<button value="3">3</button>
<button value="4">4</button>
<button value="5">5</button>
<button value="6">6</button>
<button value="7">7</button>
<button value="8">8</button>
<button value="9">9</button>
<button value="0" class="zero">0</button>
</div>
You can have it span the whole bottom by adding
.zero {
grid-column: 1/4;
}
Like this:
.numPad {
border: 1px solid #b7b7b7;
width: 100px;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
padding: 0px;
background-color: #f1f1f1;
}
.numPad button {
padding: 5px;
background-color: #f1f1f1;
border: 1px solid #b7b7b7;
outline: none;
color: #000;
padding: 5px 5px;
text-align: center;
text-decoration: none;
font-size: 16px;
font-family: 'Cinzel Decorative', cursive;
margin: 0;
cursor: pointer;
z-index: 0;
transform: scale(1);
transition: all 0.05s;
}
.numPad button:active {
z-index: 1;
background-color: #dedede;
transform: scale(1.15);
}
.zero {
grid-column: 1/4;
}
<div class="numPad">
<button value="1">1</button>
<button value="2">2</button>
<button value="3">3</button>
<button value="4">4</button>
<button value="5">5</button>
<button value="6">6</button>
<button value="7">7</button>
<button value="8">8</button>
<button value="9">9</button>
<button value="0" class="zero">0</button>
</div>
Related
currently I have encountered a project that needs to change the background color of the input checkbox to black. I searched for some information on the Internet but I still can’t successfully change the color. Would you like to help me find out what went wrong?
input[type=checkbox] {
background-color: #222;
padding: 3px 6px;
border: 1px solid red;
color: #fff;
user-select: none; /* 防止文字被滑鼠選取反白 */
}
input[type=checkbox]:checked:after {
display: inline-block;
content:"";
color: #fff;
background-color:#222;
}
/* input[type=checkbox]:checked:after {
content: "X";
background-color: #FFFFFF;
font-size: 12px;
text-align:center;
} */
<input type="checkbox"><label for="enter-send" class="enter-send"> Enter </label>
You have to write custom CSS to style checkboxes.
/* This css is for normalizing styles. You can skip this. */
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.new {
padding: 50px;
}
.form-group {
display: block;
margin-bottom: 15px;
}
.form-group input {
padding: 0;
height: initial;
width: initial;
margin-bottom: 0;
display: none;
cursor: pointer;
}
.form-group label {
position: relative;
cursor: pointer;
}
.form-group label:before {
content:'';
-webkit-appearance: none;
background-color: transparent;
border: 2px solid black;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
padding: 10px;
display: inline-block;
position: relative;
vertical-align: middle;
cursor: pointer;
margin-right: 5px;
}
.form-group input:checked + label:before {
background: black;
}
.form-group input:checked + label:after {
content: '';
display: block;
position: absolute;
top: 2px;
left: 9px;
width: 6px;
height: 14px;
border: solid white;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
<div class="new">
<form>
<div class="form-group">
<input type="checkbox" id="html">
<label for="html">HTML</label>
</div>
<div class="form-group">
<input type="checkbox" id="css">
<label for="css">CSS</label>
</div>
<div class="form-group">
<input type="checkbox" id="javascript">
<label for="javascript">Javascript</label>
</div>
</form>
</div>
I want to move the "Not got account" submit button to below the form but not sure what I am doing wrong
I think it is the CSS for .box but not sure how to edit it so it moves the button below and I tried using div tags to move it and they did not work.
Is there a bit of code in my CSS that is keeping it in the centre
I would like to keep it in the same style
Any help would be greatly appreiated
* {
box-sizing: border-box;
}
html {
background: #191919;
}
body {
background: #191919, #f5f5f5;
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
text-align: center;
font-weight: 100;
width 100vw;
height 100vh;
}
.box {
width: 400px;
padding: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #191919;
text-align: center;
}
.box h1 {
color: white;
text-transform: uppercase;
font-weight: 500;
}
.box input[type="text"],
.box input[type="password"] .box input[type="email"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #3498db;
padding: 14px 10px;
width: 200px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
}
.box input[type="text"]:focus,
.box input[type="password"]:focus .box input[type="email"]:focus {
width: 280px;
border-color: #2ecc71;
}
.box input[type="submit"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #2ecc71;
padding: 14px 40px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
cursor: pointer;
}
.box input[type="submit"]:hover {
background: #2ecc71;
}
<html>
<form class="box" action="login.php" method="post">
<h1>Login</h1>
<input type="text" name="u_email" placeholder="Email">
<input type="password" name="u_pass" placeholder="Password">
<input type="submit" name="u_btn" value="Login">
</form>
<div id="right-bar">
<form class="box" action="register.php" method="POST">
<input type="submit" name="" value="Not got an Account?">
</form>
</div>
</html>
This is because the 2nd form uses the same class box which centers the element with the first one.
.box {
...
top: 50%; <--- this is the problem
left: 50%;
...
}
* {
box-sizing: border-box;
}
html {
background: #191919;
}
body {
background: #191919, #f5f5f5;
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
text-align: center;
font-weight: 100;
width 100vw;
height 100vh;
}
.box {
width: 400px;
padding: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #191919;
text-align: center;
}
.box h1 {
color: white;
text-transform: uppercase;
font-weight: 500;
}
.box input[type="text"],
.box input[type="password"] .box input[type="email"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #3498db;
padding: 14px 10px;
width: 200px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
}
.box input[type="text"]:focus,
.box input[type="password"]:focus .box input[type="email"]:focus {
width: 280px;
border-color: #2ecc71;
}
.box input[type="submit"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #2ecc71;
padding: 14px 40px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
cursor: pointer;
}
.box input[type="submit"]:hover {
background: #2ecc71;
}
.box2 {
padding: 0px;
top: 90%;
}
<html>
<form class="box" action="login.php" method="post">
<h1>Login</h1>
<input type="text" name="u_email" placeholder="Email">
<input type="password" name="u_pass" placeholder="Password">
<input type="submit" name="u_btn" value="Login">
</form>
<div id="right-bar">
<form class="box box2" action="register.php" method="POST">
<input type="submit" name="" value="Not got an Account?">
</form>
</div>
</html>
Just don't position your boxes absolute. Makes it quite difficult to get the positioning right.
* {
box-sizing: border-box;
}
html {
background: #191919;
}
body {
background: #191919, #f5f5f5;
margin: 0;
padding: 0;
font-family: 'Lato', sans-serif;
text-align: center;
font-weight: 100;
width 100vw;
height 100vh;
}
.box {
width: 400px;
padding: 40px;
margin: 0 auto;
background: #191919;
text-align: center;
}
.box h1 {
color: white;
text-transform: uppercase;
font-weight: 500;
}
.box input[type="text"],
.box input[type="password"] .box input[type="email"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #3498db;
padding: 14px 10px;
width: 200px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
}
.box input[type="text"]:focus,
.box input[type="password"]:focus .box input[type="email"]:focus {
width: 280px;
border-color: #2ecc71;
}
.box input[type="submit"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #2ecc71;
padding: 14px 40px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
cursor: pointer;
}
.box input[type="submit"]:hover {
background: #2ecc71;
}
<html>
<form class="box" action="login.php" method="post">
<h1>Login</h1>
<input type="text" name="u_email" placeholder="Email">
<input type="password" name="u_pass" placeholder="Password">
<input type="submit" name="u_btn" value="Login">
</form>
<div id="right-bar">
<form class="box" action="register.php" method="POST">
<input type="submit" name="" value="Not got an Account?">
</form>
</div>
</html>
Not sure if this is what you are looking for, but position absolute in your form is not the best use in this case. You can read more about it here: https://developer.mozilla.org/en-US/docs/Web/CSS/position
Anyway, I made some adjustments in your code: I added a div container for the whole page and made some changes in your css as well. You can check it out in the demo below.
* {
box-sizing: border-box;
}
html {
background: #191919;
}
body {
background: #191919, #f5f5f5;
margin: 0;
padding: 0;
font-family: "Lato", sans-serif;
text-align: center;
font-weight: 100;
width: 100vw;
height: 100vh;
}
.main-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.box {
margin-top: 10%;
width: 400px;
padding: 40px;
/* position: absolute; */
/* top: 50%;
left: 50%; */
/* transform: translate(-50%, -50%); */
background: #191919;
text-align: center;
}
.box h1 {
color: white;
text-transform: uppercase;
font-weight: 500;
}
.box input[type="text"],
.box input[type="password"] .box input[type="email"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #3498db;
padding: 14px 10px;
width: 200px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
}
.box input[type="text"]:focus,
.box input[type="password"]:focus .box input[type="email"]:focus {
width: 280px;
border-color: #2ecc71;
}
.box input[type="submit"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #2ecc71;
padding: 14px 40px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
cursor: pointer;
}
.box input[type="submit"]:hover {
background: #2ecc71;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="main-container">
<form class="box" action="login.php" method="post">
<h1>Login</h1>
<input type="text" name="u_email" placeholder="Email" />
<input type="password" name="u_pass" placeholder="Password" />
<input type="submit" name="u_btn" value="Login" />
</form>
<div id="right-bar">
<form class="box" action="register.php" method="POST">
<input type="submit" name="" value="Not got an Account?" />
</form>
</div>
</div>
</body>
</html>
I have a some basic button styles where on :hover I add the letter-spacing property:
.btn {
display: inline-block;
text-align: center;
background-color: transparent;
border: 1px solid transparent;
padding: 0.375rem 0.75rem;
font-size: 1rem;
border-radius: 0.25rem;
cursor: pointer;
transition: all 0.2s ease;
}
.btn-primary {
background-color: #8065F1;
color: #FFFFFF;
}
.btn-large {
border-radius: 32px;
box-shadow: 0 2px 80px 0 rgba(74, 74, 74, 0.23);
padding: 0.25rem 3rem;
font-size: 1.5rem;
text-transform: uppercase;
}
.btn:hover {
letter-spacing: 4px;
}
<button type="button" class="btn btn-primary btn-large">Lorem</button>
Is there a way that width doesn't expand? Like adding min/max-width? However the problem is that button elements can contain different string length:
.btn {
display: inline-block;
text-align: center;
background-color: transparent;
border: 1px solid transparent;
padding: 0.375rem 0.75rem;
box-shadow: 0 2px 80px 0 rgba($grey, 0.23);
font-size: 1rem;
border-radius: 0.25rem;
cursor: pointer;
transition: all 0.2s ease;
}
.btn-primary {
background-color: #8065F1;
color: #FFFFFF;
}
.btn-large {
border-radius: 32px;
-webkit-box-shadow: 0 2px 80px 0 rgba(74, 74, 74, 0.23);
box-shadow: 0 2px 80px 0 rgba(74, 74, 74, 0.23);
padding: 0.25rem 3rem;
font-size: 1.5rem;
text-transform: uppercase;
min-width: 240px;
}
.btn:hover {
letter-spacing: 4px;
}
<p>I need this "effect" (I added some min-width):</p>
<button type="button" class="btn btn-primary btn-large">Lorem</button>
<p>However it won't work for larger strings</p>
<button type="button" class="btn btn-primary btn-large">Lorem Ipsum</button><br><br>
<button type="button" class="btn btn-primary btn-large">Lorem Ipsum Dolor</button>
I know I can use JS and append the elements fixed width to it, however I'm looking for a CSS solution - if there is one?
On idea to approximate this is to duplicate the text considering a hidden one that has already the letter-spacing and another one on the top that you animate to fill the space already defined by the hidden text:
Here is an idea by making the text color the same as background:
.btn {
display: inline-block;
text-align: center;
background-color: transparent;
border: 1px solid transparent;
padding: 0.375rem 0.75rem;
font-size: 1rem;
border-radius: 0.25rem;
cursor: pointer;
transition: all 0.2s ease;
margin-bottom:10px;
}
.btn-primary {
background-color: #8065F1;
color: #FFFFFF;
}
.btn-large {
border-radius: 32px;
box-shadow: 0 2px 80px 0 rgba(74, 74, 74, 0.23);
padding: 0.25rem 3rem;
font-size: 1.5rem;
text-transform: uppercase;
}
.btn::before {
content:attr(data-text);
position:absolute;
left:0;
right:0;
text-align:center;
letter-spacing: initial;
color:#fff;
transition: all 0.2s ease;
}
.btn {
letter-spacing: 4px;
color:#8065F1;
position:relative;
}
.btn:hover::before {
letter-spacing: 4px;
}
<div><button type="button" class="btn btn-primary btn-large" data-text="Lorem">Lorem</button></div>
<div><button type="button" class="btn btn-primary btn-large" data-text="Lorem Ipsum">Lorem Ipsum</button></div>
<div><button type="button" class="btn btn-primary btn-large" data-text="Lorem Ipsum Dolor">Lorem Ipsum Dolor</button></div>
Another one using opacity and both pseudo element in case the background is not a solid color:
.btn {
display: inline-block;
text-align: center;
background-color: transparent;
border: 1px solid transparent;
padding: 0.375rem 0.75rem;
font-size: 1rem;
border-radius: 0.25rem;
cursor: pointer;
transition: all 0.2s ease;
margin-bottom:10px;
}
.btn-primary {
background: linear-gradient(#8065F1,purple);
color: #FFFFFF;
}
.btn-large {
border-radius: 32px;
box-shadow: 0 2px 80px 0 rgba(74, 74, 74, 0.23);
padding: 0.25rem 3rem;
font-size: 1.5rem;
text-transform: uppercase;
}
.btn {
position:relative;
font-size:0;
}
.btn::before {
content:attr(data-text);
position:absolute;
left:0;
right:0;
text-align:center;
letter-spacing: initial;
font-size: 1.5rem;
transition: all 0.2s ease;
}
.btn::after {
content:attr(data-text);
letter-spacing: 4px;
opacity:0;
font-size: 1.5rem;
}
.btn:hover::before {
letter-spacing: 4px;
}
<div><button type="button" class="btn btn-primary btn-large" data-text="Lorem">Lorem</button></div>
<div><button type="button" class="btn btn-primary btn-large" data-text="Lorem Ipsum">Lorem Ipsum</button></div>
<div><button type="button" class="btn btn-primary btn-large" data-text="Lorem Ipsum Dolor">Lorem Ipsum Dolor</button></div>
How about turning off box-sizing, then using a percentage for your padding? It should work well no matter what the size of your contents is, but my numbers are probably wrong so you'll need to adjust the numbers to make it accurate.
.wrapper{
display:inline-block;
}
button{
box-sizing: content-box;
padding: 0 10.4%;
border: none;
width: 100%;
font-size:13px;
}
button:hover{
letter-spacing:0.1em;
padding:0;
}
.outer-wrapper{
}
<div class="outer-wrapper">
<div class="wrapper">
<button class='button'>Small Text</button>
</div>
</div>
<div class="outer-wrapper">
<div class="wrapper">
<button class='button'>Much much bigger text</button>
</div>
</div>
<div class="outer-wrapper">
<div class="wrapper">
<button class='button'>Small TextSmall TextSmall TextSmall TextSmall Text</button>
</div>
</div>
Edit: Well, it's...more or less working, except that it turns out to be impossible. No matter how finely I tune it, I'm getting problems because of differences in browser rendering of sub-pixels. (The browser apparently rounds rem differently than it does %, which means this is going to be impossible to do with pure CSS.)
I have an input field and a button that I want to have horizontally and vertically centered (without transform) side by side in the middle. I can easily fix the centering part, but to place the input field and the button side by side has proven to be much harder. For whatever reason, the button is placed lower than the input field.
The HTML and CSS:
body {
background: #000;
text-align: center;
}
.hd {
font-size: 3.9rem;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
color: rgb(250, 250, 250);
margin-bottom: 30px;
}
.content {
margin: 0;
position: relative;
margin-top: 20vh;
}
.form-control, .btn {
display: inline-block;
padding: 10px 25px;
font-size: 1rem;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
border-radius: 0;
-webkit-appearance: none;
}
.form-group {
display: inline-block;
}
.form-control {
border: 0;
float: left;
width: 250px;
}
*:focus {
outline: none;
}
.form-controlt:focus{
outline: none;
}
.btn {
background-color: lightgreen;
border: 0;
background-color: #ff8e41;
-o-transition: all .3s;
transition: all .3s;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
font-style: normal;
font-weight: 600;
position: relative;
border: 0;
box-sizing: border-box;
color: #fff;
text-align: center;
margin: 0 auto;
-webkit-appearance: button;
cursor: pointer;
}
.btn::-moz-focus-inner {
border: 0;
}
.btn[type=submit]:active {
background: #ed7a18;
box-shadow: 0 1px 0 0 hsla(0,0%,100%,.27),inset 0 1px 0 0 #bc5f10;
}
.btn[type=submit]:hover {
background-color: #ffa353;
-o-transition: all .3s;
transition: all .3s;
}
<div class="content">
<div class="hd">Text</div>
<form action="8dy9s8hsd9.php" method="POST">
<div id="name-group" class="form-group">
<input type="text" class="form-control">
</div>
<button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
</form>
</div>
Put the input and the button elements inside the same div with .form-group class.
body {
background: #000;
text-align: center;
}
.hd {
font-size: 3.9rem;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
color: rgb(250, 250, 250);
margin-bottom: 30px;
}
.content {
margin: 0;
position: relative;
margin-top: 20vh;
}
.form-control, .btn {
display: inline-block;
padding: 10px 25px;
font-size: 1rem;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
border-radius: 0;
-webkit-appearance: none;
}
.form-group {
display: inline-block;
}
.form-control {
border: 0;
float: left;
width: 250px;
}
*:focus {
outline: none;
}
.form-controlt:focus{
outline: none;
}
.btn {
background-color: lightgreen;
border: 0;
background-color: #ff8e41;
-o-transition: all .3s;
transition: all .3s;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
font-style: normal;
font-weight: 600;
position: relative;
border: 0;
box-sizing: border-box;
color: #fff;
text-align: center;
margin: 0 auto;
-webkit-appearance: button;
cursor: pointer;
}
.btn::-moz-focus-inner {
border: 0;
}
.btn[type=submit]:active {
background: #ed7a18;
box-shadow: 0 1px 0 0 hsla(0,0%,100%,.27),inset 0 1px 0 0 #bc5f10;
}
.btn[type=submit]:hover {
background-color: #ffa353;
-o-transition: all .3s;
transition: all .3s;
}
<div class="content">
<div class="hd">Text</div>
<form action="8dy9s8hsd9.php" method="POST">
<div id="name-group" class="form-group">
<input type="text" class="form-control">
<button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
</div>
</form>
</div>
Change:
<div id="name-group" class="form-group">
<input type="text" class="form-control">
</div>
<button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
To:
<div id="name-group" class="form-group">
<input type="text" class="form-control">
<button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
</div>
body {
background: #000;
text-align: center;
}
.hd {
font-size: 3.9rem;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
color: rgb(250, 250, 250);
margin-bottom: 30px;
}
.content {
margin: 0;
position: relative;
margin-top: 20vh;
}
.form-control, .btn {
display: inline-block;
padding: 10px 25px;
font-size: 1rem;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
border-radius: 0;
-webkit-appearance: none;
}
.form-group {
display: inline-block;
}
.form-control {
border: 0;
float: left;
width: 250px;
}
*:focus {
outline: none;
}
.form-controlt:focus{
outline: none;
}
.btn {
background-color: lightgreen;
border: 0;
background-color: #ff8e41;
-o-transition: all .3s;
transition: all .3s;
font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
font-style: normal;
font-weight: 600;
position: relative;
border: 0;
box-sizing: border-box;
color: #fff;
text-align: center;
margin: 0 auto;
-webkit-appearance: button;
cursor: pointer;
}
.btn::-moz-focus-inner {
border: 0;
}
.btn[type=submit]:active {
background: #ed7a18;
box-shadow: 0 1px 0 0 hsla(0,0%,100%,.27),inset 0 1px 0 0 #bc5f10;
}
.btn[type=submit]:hover {
background-color: #ffa353;
-o-transition: all .3s;
transition: all .3s;
}
<div class="content">
<div class="hd">Text</div>
<form action="8dy9s8hsd9.php" method="POST">
<div id="name-group" class="form-group">
<input type="text" class="form-control">
<button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
</div>
</form>
</div>
I have created a login using css grid layout. I want to implement a form input box inside the panel body. However, the input box not respecting inside the panel body. The input box was overflow outside the panel body. For some reason, the code is working with regular css. I just want to implement css grid and i'm not sure about to go about this.
Thanks for any help.
Here is the fiddle.
<pre>
https://jsfiddle.net/80fc325h/
Just use *{box-sizing: border-box} It will be updated. Hope it is helpful to you. Kindly check the snippet. As CSS3 box-sizing property allows us to include the padding and border in an element's total width and height.
body {
margin: 0;
font-size: 13px;
color: #222;
background-color: #f5f5f5;
}
* {
box-sizing:border-box;
}
.text-right{
text-align: right;
}
/*--------------------------------------------------------------
style:
--------------------------------------------------------------*/
.login-wrapper{
display:grid;
grid-template-columns:1fr;
width: 50%;
margin: 0 auto;
}
.content{
display:grid;
grid-template-columns:1fr;
border:1px solid red;
}
.panel {
background-color: #fff;
border: 1px solid #dbd9d9;
border-radius: 4px;
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}
.panel-body {
padding: 15px;
}
.panel-heading {
text-align: center;
padding: 5px 10px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
.panel-title {
margin-top: 0;
margin-bottom: 0;
color: inherit;
}
.panel-footer {
padding: 10px 15px;
background-color: #fff;
border-top: 1px solid #dbd9d9;
}
/*--------------------------------------------------------------
Form:
--------------------------------------------------------------*/
.form-control {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
}
.form-control:focus {
outline: 0;
}
.form-control::-moz-placeholder {
color: #999;
opacity: 1;
}
.form-control:-ms-input-placeholder {
color: #999;
}
.form-control::-webkit-input-placeholder {
color: #999;
}
.form-control::-ms-expand {
background-color: transparent;
border: 0;
}
.input-sm {
height: 29px;
padding: 5px 10px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
.has-feedback {
position: relative;
}
.has-feedback .form-control {
padding-right: 42.5px;
}
.form-control-feedback {
position: absolute;
top: 0;
right: 0;
z-index: 2;
display: block;
width: 34px;
height: 34px;
line-height: 34px;
text-align: center;
pointer-events: none;
}
.has-error .help-block,
.has-error .control-label,
.has-error .radio,
.has-error .checkbox,
.has-error .radio-inline,
.has-error .checkbox-inline,
.has-error.radio label,
.has-error.checkbox label,
.has-error.radio-inline label,
.has-error.checkbox-inline label {
color: #f44336;
}
.has-error .form-control {
border-color: #f44336;
}
.has-error .form-control:focus {
border-color: #f44336;
}
.has-error .input-group-addon {
color: #f44336;
background-color: #f2dede;
border-color: #f44336;
}
.has-error .form-control-feedback {
color: #f44336;
}
.has-feedback label ~ .form-control-feedback {
top: 25px;
}
.has-feedback label.sr-only ~ .form-control-feedback {
top: 0;
}
.input-group {
position: relative;
display: table;
border-collapse: separate;
}
.input-group .form-control {
position: relative;
z-index: 2;
float: left;
width: 100%;
margin-bottom: 0;
}
.input-group .form-control:focus {
z-index: 3;
}
.input-group-addon,
.input-group-btn,
.input-group .form-control {
display: table-cell;
}
.input-group-addon,
.input-group-btn {
width: 1%;
white-space: nowrap;
vertical-align: middle;
}
.input-group-addon {
padding: 6px 12px;
font-weight: normal;
line-height: 1;
color: #555;
text-align: center;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
}
.input-group-addon.input-sm {
padding: 5px 10px;
font-size: 12px;
border-radius: 3px;
}
.input-group-addon.input-lg {
padding: 10px 16px;
font-size: 18px;
border-radius: 6px;
}
.input-group-addon input[type="radio"],
.input-group-addon input[type="checkbox"] {
margin-top: 0;
}
.input-group .form-control:first-child,
.input-group-addon:first-child,
.input-group-btn:first-child > .btn,
.input-group-btn:first-child > .btn-group > .btn,
.input-group-btn:first-child > .dropdown-toggle,
.input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle),
.input-group-btn:last-child > .btn-group:not(:last-child) > .btn {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.input-group-addon:first-child {
border-right: 0;
}
.input-group .form-control:last-child,
.input-group-addon:last-child,
.input-group-btn:last-child > .btn,
.input-group-btn:last-child > .btn-group > .btn,
.input-group-btn:last-child > .dropdown-toggle,
.input-group-btn:first-child > .btn:not(:first-child),
.input-group-btn:first-child > .btn-group:not(:first-child) > .btn {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.input-group-addon:last-child {
border-left: 0;
}
label {
display: inline-block;
max-width: 100%;
font-size: 13px;
margin-bottom: 5px;
}
input:focus{
outline:none!important;
}
.form-control-feedback i{
margin-top: -5px;
}
.form-group{
margin-bottom: 10px;
}
.footer-section{
background-color: #e9ecef;
display: grid;
border-top: 1px solid #d8dadd;
grid-template-columns:1fr;
font-size: 11px;
text-align: center;
}
/* ==========================================================================
Button Scripts
========================================================================== */
.btn{
display: inline-block;
margin-bottom: 0;
font-weight: 400;
text-align: center;
vertical-align: middle;
touch-action: manipulation;
cursor: pointer;
border: 1px solid transparent;
white-space: nowrap;
padding: 3px 10px;
line-height: 1.5384616;
border-radius: 3px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none
}
.btn:focus{
outline: none;
}
.btndrk-orange{
background-color: #ec8b02;
color:#fff;
}
<div class="login-wrapper">
<div class="content">
<div class="panel">
<div class="panel-body">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="icon-user-tie"></i></span>
<input type="text" class="form-control" name="username" id="username" autocomplete="off" placeholder="Username">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="icon-lock2"></i></span>
<input type="password" class="form-control" name="password" id="password" autocomplete="off" placeholder="Password">
</div>
</div>
</div>
<div class="panel-footer text-right">
<button type="button" class="btn">LOGIN</button>
</div>
</div>
</div>
</div>
Use display flex not display table on your input group.