I currently have a form with 1 button, and if I try to add another button the whole css gets screwed.
This is how I want it to look like: http://prntscr.com/gfuvi8
But if add this line under the submit button <i class="fa fa-refresh"></i> Fetch Exchange
This is what I get : http://prntscr.com/gfuwka
.tablesection {
padding: 20px;
border-left: 1px solid #e4e4e4;
border-right: 1px solid #e4e4e4;
border-bottom: 1px solid #e4e4e4;
background: #ffffff;
}
.tablesection label {
width: calc(50% - 10px);
float: left;
margin: 0px 0px 10px 0px;
}
.tablesection label:nth-child(odd) {
margin: 0px 20px 10px 0px;
}
.tablesection input, .tablesection select, .tablesection textarea {
width: calc(50% - 10px);
margin: 0px 0px 20px 0px;
padding: 10px;
display: block;
float: left;
border: 1px solid #cecece;
-webkit-border-radius: 0;
border-radius: 0;
}
.tablesection textarea {
resize: vertical;
}
.tablesection input:nth-child(odd), .tablesection select:nth-child(odd) {
margin: 0px 20px 20px 0px;
}
.tablesection input {
padding: 11px 10px;
width: calc(50% - 10px);
}
.tablesection input.submit {
width: auto;
border: 0px;
margin: 0px 0px 0px 0px;
background: #54809b;
color: #ffffff;
text-decoration: none;
display: block;
float: none;
font-size: 11px;
padding: 12px 20px;
-webkit-transition: background 0.5s linear;
-moz-transition: background 0.5s linear;
-ms-transition: background 0.5s linear;
-o-transition: background 0.5s linear;
transition: background 0.5s linear;
clear: both;
}
.tablesection input.submit:hover {
background: #4d758d;
}
.tablesection input.submit::before {
display: block;
content: ' ';
clear: both;
}
<div class="tablesection">
<form action="" method="post">
<label for="usd">USD</label>
<label for="cad">CAD</label>
<input id="usd" type="text" name="usd" value="<?php echo $siteUsd; ?>" maxlength="10" required="required" />
<input id="cad" type="text" name="cad" value="<?php echo $siteCad; ?>" maxlength="10" required="required" />
<label for="gbp">GBP</label>
<label for="eur">EUR</label>
<input id="gbp" type="text" name="gbp" value="<?php echo $siteGbp; ?>" maxlength="10" required="required" />
<input id="eur" type="text" name="eur" value="<?php echo $siteEur; ?>" maxlength="10" required="required" />
<label for="aud">AUD</label>
<label for=""></label>
<input id="aud" type="text" name="aud" value="<?php echo $siteAud; ?>" maxlength="10" required="required" />
<div class="clear">
</div>
<input type="submit" class="submit" value="Update Exchange Rates" />
<i class="fa fa-refresh"></i> Fetch Exchange
</form>
</div>
.content a.button:first-of-type {
margin: 20px 0px 0px 0px;
}
.content a.button {
background: #54809b;
color: #ffffff;
text-decoration: none;
display: block;
float: left;
margin: 20px 0px 0px 16px;
font-size: 11px;
padding: 12px 20px;
-webkit-transition: background 0.5s linear;
-moz-transition: background 0.5s linear;
-ms-transition: background 0.5s linear;
-o-transition: background 0.5s linear;
transition: background 0.5s linear;
}
.content a.button:hover {
background: #4d758d;
}
.content a.button i {
margin: 0px 4px 0px 0px;
font-size: 10px;
}
when there are just 2 buttons like this :
<i class="fa fa-search"></i> Search Coupons
<i class="fa fa-plus"></i> Add Coupon
then its fine and they're near each other the problem is at form
The input.submit element isn't floated, while the a.button is. This pushes the a.button to be below the input.submit, and the margins are not consistent so they wouldn't line up if this wasn't happening. I'll suggest two ways to fix it, one minimal (only two css attributes changed), and one that I think is easier to read and maintain but changes the structure of your CSS somewhat.
For either way, I suggest changing the margins. Putting the 16px margin on the right eliminates the need for removing it from the first element with a separate rule, and margins that overflow the containing element don't matter as they aren't included when calculating width and height.
Minimal version
Step 1: set the input.submit to float: left, like the .button
Step 2: change the margin for input.submit to match the .button, or vice versa,
eg, input.submit { margin: 20px 16px 0px 0px; }`
.tablesection input.submit {
width: auto;
border: 0px;
margin: 20px 16px 0px 0px; /* copy the a.button margins */
background: #54809b;
color: #ffffff;
text-decoration: none;
display: block;
float: left; /* left instead of none keeps subsequent floats on the same line */
font-size: 11px;
padding: 12px 20px;
-webkit-transition: background 0.5s linear;
-moz-transition: background 0.5s linear;
-ms-transition: background 0.5s linear;
-o-transition: background 0.5s linear;
transition: background 0.5s linear;
clear: both;
}
That'll get them inline, after that you'll probably want to set both to a consistent height.
Better (in my opinion) version
You have a lot of shared styles between input.submit and a.button - You may consider combining these into a common .button class (note the absence of a tag in this selector, this means the rule applies to anything with the class).
Here I would set a consistent float: left; and consistent margins (eg 20px 16px 0px 0px)
If you still need to do specific styles for input.submit, you can give the element both classes and they will be applied separately.
.content .button {
background: #54809b;
color: #ffffff;
text-decoration: none;
display: block;
float: left;
margin: 20px 16px 0px 0px;
font-size: 11px;
padding: 12px 20px;
-webkit-transition: background 0.5s linear;
-moz-transition: background 0.5s linear;
-ms-transition: background 0.5s linear;
-o-transition: background 0.5s linear;
transition: background 0.5s linear;
}
.content .button:hover {
background: #4d758d;
}
.content .button i {
margin: 0px 4px 0px 0px;
font-size: 10px;
}
.tablesection input.submit {
/* Styles that are unique to input.submit */
}
<div class ="content">
<div class="tablesection">
<input type="submit" class="button submit" value="Update Exchange Rates">
<a href="?do=fetch" class="button">
<i class="fa fa-refresh"></i>
Fetch Exchange
</a>
</div>
</div>
EDIT: Both of these solutions share a flaw, which is that float elements do not affect the height of their container. To get around this, you can either place a dummy element after them to pad the container, eg: <div style="height:60px;"></div>. The important thing in this method is that the height of the dummy div be the same as the height + top margin of the floated elements.
Alternatively, you can remove the float:left altogether and set both to display:inline-block instead, which is much easier to work with than floats when doing the layout.
You can make their positions relative and add a float style:
.btn-float {
position: relative;
width: auto;
float: left;
padding-left: 15px;
}
<input class="btn-left" type="submit" class="submit" value="Update Exchange Rates" />
<a class="btn-right" href="?do=fetch" class="button"><i class="fa fa-refresh"></i> Fetch Exchange</a>
.button {
width: 23%;
display: block;
text-align: center;
line-height: 3rem;
height: 3rem;
font-size: 1.2rem;
border: 1px solid #ccc;
background: #fafafa;
}
.button-container{
margin-bottom: 20px;
width: 100%;
}
.button-container::after{
content: '';
display: block;
visibility: hidden;
clear: both;
}
.button-float{
margin-left: 2%;
float: left;
}
<div class="button-container">
<button class="button button-float">BTN-1</button>
<button class="button button-float">BTN-2</button>
</div>
<div class="button-container">
<i class="fa fa-refresh"></i> Fetch Exchange
<i class="fa fa-refresh"></i> Fetch Exchange
</div>
I think i know where is wrong.
You should wrap those two buttons in a dive or something else, and set float left, then clear the float on the DIV.
if you using bootstrap, you can just wrap those buttons in a col-md-12
The goal is to let button float, then clear the float on its father container.
added
OK, just add .button-container,.button-container::after,.button-float in your css file, and wrap your 2 btns with div with .button-container class, add .button-float class to your 2 btns, that will do.
Hope this can help you.
Related
Ok, having some weird CSS problems here trying to achieve this, having a warning thing to the right of each horizontally CENTERED input field:
Right now I have the centered inputs, but no matter what I do with float or even transform or translate on the .warning div, I can't achieve this.
.warning {
display: none;
margin-top: 10px;
}
.warning p {
color: #e85748;
display: none;
transform: translateX(105%) translateY(232%);
}
.ico-circle {
width: 40px;
position: absolute;
height: 40px;
border-radius: 50%;
transform: translateX(720%) translateY(22%);
background: #e85748;
}
textarea {
border: 2px solid #a0b3b0;
resize: vertical;
}
.field-wrap {
position: relative;
width: 50%;
float: center;
margin: auto;
margin-bottom: 9px;
}
input,
textarea {
padding: 15px 15px;
display: block;
margin: auto;
width: 200px;
/* height: 100%; */
color: #333333;
border-color: #333333;
border-radius: 15px;
-webkit-transition: border-color .25s ease, box-shadow .25s ease;
transition: border-color .25s ease, box-shadow .25s ease;
border-radius: 30px;
font-size: 16px;
font-weight: 500;
border: 4px solid #333333;
line-height: 1.3;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
text-indent: 13px;
flex: 0 0 160px;
width: 200px;
background-color: transparent;
}
input:focus {
outline: none !important;
border: 4px solid #e85748;
width: 250px;
-webkit-transition: width .25s ease;
transition: width .25s ease;
}
<div class="field-wrap">
<input id="username" type="text" placeholder="Username" required autocomplete="off">
<div class="warning" />
<p>Hello world</p>
<div class="ico-circle">
</div>
</div>
</div>
<div class="field-wrap">
<input type="password" placeholder="Password" required autocomplete="off">
<div class="warning">
<p>Hello world</p>
<div class="ico-circle">
</div>
</input>
</div>
Register
</i>Wait, take me back
What am I doing wrong here?
You can do it with flexbox but i'm not sure how you want it to present when the inputs are wider and/or have the warning beside it. Perhaps this will be sufficient to point you in the right direction:
.warning {
display: none;
}
.warning p {
color: #e85748;
}
.ico-circle {
width: 40px;
height: 40px;
border-radius: 50%;
background: #e85748;
order: -1;
}
textarea {
border: 2px solid #a0b3b0;
resize: vertical;
}
.field-wrap {
display: flex;
position: relative;
margin-bottom: 9px;
}
input,
textarea {
padding: 15px 15px;
margin: auto;
width: 200px;
/* height: 100%; */
color: #333333;
border-color: #333333;
border-radius: 15px;
-webkit-transition: border-color .25s ease, box-shadow .25s ease;
transition: border-color .25s ease, box-shadow .25s ease;
border-radius: 30px;
font-size: 16px;
font-weight: 500;
border: 4px solid #333333;
line-height: 1.3;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
text-indent: 13px;
width: 200px;
background-color: transparent;
}
input:focus {
outline: none !important;
border: 4px solid #e85748;
width: 250px;
-webkit-transition: width .25s ease;
transition: width .25s ease;
}
input:focus:invalid+.warning {
display: flex;
}
<div class="field-wrap">
<input id="username" type="text" placeholder="Username" required autocomplete="off" />
<div class="warning">
<p>Hello world</p>
<div class="ico-circle">
</div>
</div>
</div>
<div class="field-wrap">
<input type="password" placeholder="Password" required autocomplete="off" />
<div class="warning">
<p>Hello world</p>
<div class="ico-circle">
</div>
</div>
</div>
Register
</i>Wait, take me back
I have some code here that creates an animated search bar:
<html>
<head>
<style>
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
</style>
</head>
<body>
<form>
<input type="text" name="search" placeholder="Search..">
</form>
</body>
</html>
Whenever somebody clicks on it, the search bar expands and lets the user type the keyword(s). How would I make it so that when the user clicks on the search bar, it waits (e.g 1 secs) for the search bar to expand and then redirects to a URL. Do I change the input[type=text] to input[type=code] and do the same with input[type=text]:focus???? Please don't give too complicated answers and I am just a beginner. I looked up most directions to insert the code but my website does not support the site.com/?search=keywords. Please help!!
Thanks,
- Will
Maybe with JS :
<form>
<input type="text" name="search" placeholder="Search.." onClick="redirect()">
</form>
And :
<script>
function redirect() {
setTimeout(function(){
window.location.replace("http://stackoverflow.com");
}, 1000);
}
</script>
You can use the css propert for transition, "transition-delay" here is the code example. Here is a jsfiddle
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
-webkit-transition-delay: 2s; /* Safari */
transition-delay: 2s;
}
input[type=text]:focus {
width: 100%;
}
I am using following code and code work fine. but i wanna that when user click on search button then search button will also show like stackoverflow search bar has.
HTML :-
<form>
<input type="text" name="search" placeholder="Search..">
</form>
CSS
input[type=text] {
display:block;
margin: 0 0 0 auto;
width: 250px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
Follow these steps
Create a button
Place that button on the search bar
set display property of that button to none
now whenever you focus on the search bar, change display property of that button to block
try implementing this code on your own first ...
input[type=text] {
display:block;
margin: 0 0 0 auto;
width: 250px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 90%;
}
input[type=text]:focus + .but{
display: block;
}
.but{
cursor:pointer;
width: 100px;
height: 50px;
position: absolute;
right:5px;
top:5px;
display:none;
}
<form>
<input type="text" name="search" placeholder="Search.."><input class="but" type="button" value = "search">
</form>
My box is expanding to the right, how can I make it expand to the left?
input[type=text] {
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
<form>
<input type="text" name="search" placeholder="Search..">
</form>
Just align it to the right of its container element. Either change the display attribute to block and set the right and left margins to 0 and auto, or keep it as an inline element and apply text-align: right to the container block.
input[type=text] {
display:block;
margin: 0 0 0 auto;
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: white;
background-image: url('searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
width: 100%;
}
<form>
<input type="text" name="search" placeholder="Search..">
</form>
I have a responsive website, on one of the pages I have 2 buttons, they are next to each other when the screen size is wide enough to fit both buttons, when the page is made smaller (i.e for a smartphone) then the second button (right) goes below the first. This works fine.
However when the buttons are one above the other they are positioned on the left, I would like to center them.
I have based it on this: http://jsfiddle.net/erenyener/puA72/2/
Here is a JS Fiddle: https://jsfiddle.net/kg2grant/
Here is the code:
HTML
<div class="button-wrapper">
<div class="fiftyLEFT" ><button type="submit" class="submit" value="submit" name="submit_button"><span>Search</span></button></div>
<div class="fiftyRIGHT"><button onclick="location.href='https://google.com';" class="submit" style="font-size: 22px; width: 500px" value="show" name="show_button">Google</button></div>
</div>
CSS
button.submit {
border: none;
background-image: linear-gradient(-180deg, #52A1DD 50%, #53A2DE 100%);
border-radius: 100px;
max-width: 90%;
margin-right: 5%;
padding: 8px 10px;
font-size: 26px;
color: #fff;
line-height: 30px;
cursor: pointer;
-webkit-transition: all .15s ease-in-out;
-moz-transition: all .15s ease-in-out;
-o-transition: all .15s ease-in-out;
transition: all .3s ease-in-out;
margin-top: 10px;
z-index: 1;
position: relative;
}
button.submit:hover {
color: #3193e9;
background: #fff;
}
button.submit {
width: calc(.5px + 50vw);
}
button.submit img: hover {
background-color: #C37500;
opacity:0.7 !important;
filter:alpha(opacity=70) !important;
}
.button-wrapper
{
width:100%;
padding-top:10px;
padding-bottom:10px;
display:inline-block;
border: 3px solid black
}
.button-wrapper > .fiftyLEFT
{
width:50%;
float:left;
min-width:50px
}
.button-wrapper > .fiftyRIGHT
{
min-width:400px;
width:50%;
float:left;
white-space: nowrap;
}
I have tried many things to like margin 0 auto and adding another container however had no luck! Thanks in advance for your help.
You can change the display to flex and achieve what you want by using #media query.
Forked jsFiddle with the behavior needed: https://jsfiddle.net/o1gpcLcr/
You will have to remove the float left property to do the margin auto.
.button-wrapper > .fiftyLEFT {
width: 50%;
/* float: left; */
min-width: 50px;
margin-left: auto;
margin-right: auto;
}
.button-wrapper > .fiftyRIGHT {
min-width: 400px;
width: 50%;
/* float: left; */
white-space: nowrap;
margin-left: auto;
margin-right: auto;
}
Then do the float left on larger screens with #media (min-width: 768px), or wherever you want it to break.
Using float makes margin auto behave strangely because the floated element have been removed from the regular flow of content. If you remove float: left from your last two CSS rules and declare margin: auto, it should work.
Alternatively, you can remove float: left, and then add
display: flex;
flex-flow: column;
justify-content: center;
align-items: center;
to your .button-wrapper rule. Using flexbox has the same effect as margin auto, but may make other changes and additions easier later in development.
To learn more about flexbox, check out https://flexbox.io for some great video tutorials.
You'll want to use CSS media queries, with more of a 'mobile-first' approach.
Make the buttons width: 100% by default and then use #media (min-width: 768px) {...} to change the width to 50%.
I've made some changes to your code:
button.submit {
border: none;
background-image: linear-gradient(-180deg, #52A1DD 50%, #53A2DE 100%);
border-radius: 100px;
padding: 8px 10px;
margin: 5px 0;
font-size: 26px;
color: #fff;
line-height: 30px;
cursor: pointer;
-webkit-transition: all .15s ease-in-out;
-moz-transition: all .15s ease-in-out;
-o-transition: all .15s ease-in-out;
transition: all .3s ease-in-out;
z-index: 1;
position: relative;
}
button.submit:hover {
color: #3193e9;
background: #fff;
}
button.submit img: hover {
background-color: #C37500;
opacity:0.7 !important;
filter:alpha(opacity=70) !important;
}
.button-wrapper {
width:100%;
padding: 10px 0;
display:inline-block;
border: 3px solid black
}
button {
width: 100%;
}
#media (min-width: 768px) {
button {
float: left;
width: 50%;
white-space: nowrap;
}
}
<div class="button-wrapper">
<div class="button" ><button type="submit" class="submit" value="submit" name="submit_button"><span>Search</span></button></div>
<div class="button"><button onclick="location.href='https://google.com';" class="submit" value="show" name="show_button">Google</button></div>
</div>