Styling input and span as button class, slight difference - html

I want to make all buttons on my website follow a flat button class, input buttons or span buttons should be exactly the same.
I have applied the same class, removing border, adding padding, etc.. but, the buttons using the element appear slightly bigger than the ones using the form button.
Why is that? What other css property could I edit to make them look the same (aside from having a preset height for all of them?)
This is my button class:
.button{
padding: 10px;
display: inline;
border-radius: 2px;
font-family: "Arial";
border: 0;
margin: 0 10px;
background: red;
font-size: 15px;
line-height: 15px;
color: white;
width: auto;
height: auto;
box-sizing: content-box;
}
Here is the fiddle: http://jsfiddle.net/raphadko/f3293yeL/

Best solution would be to wrap the buttons inside the spans. That way, you'll total control of the button positioning. Do not use them as button inside a form!
span > .button {
padding: 10px;
display: inline;
border-radius: 2px;
font-family: "Arial";
border: 0;
margin: 0 10px;
background: red;
font-size: 15px;
line-height: 15px;
color: white;
width: auto;
height: auto;
box-sizing: content-box;
}
<form>
<span>
<input type="submit" class="button" value="Button1" />
</span>
<span>
<input type="submit" class="button" value="Button2" />
</span>
<span>
<input type="submit" class="button" value="Button3" />
</span>
</form>
Note: The spans can help you position the element easily but its not advisable to use it as button when a form is concerned.

Related

How to remove this small button next tothe actual button/styled label

I have a submit Button, which I styled with a label. For some reason, a mini button for the unstyled Button remains left to the styled Button and both are clickable. The whole thing looks like this in the Browser.
How do I get rid of it? I dont want to just make it invisible, because then the styled button won't be centered correctly.
[type="file"], [type="submit"]{
height: 0;
overflow: hidden;
width: 0;
}
[type="file"] + label, [type="submit"] +label {
background: #f15d22;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-family: 'Rubik', sans-serif;
font-size: inherit;
font-weight: 500;
margin-bottom: 1rem;
outline: none;
padding: 1rem 50px;
position: relative;
transition: all 0.3s;
vertical-align: middle;
}
[type="submit"] +label {
background: #2286f1;
}
<div align="center">
<button type="submit" id="send" [disabled]="!uploadForm.valid"></button>
<label for="send">Upload & Create</label>
</div>
Just add display:none to your button.
<button type="submit" id="send" [disabled]="!uploadForm.valid" style="display: none;"></button>
Here a short solution with inline style but you can easily add this to a CSS class.

Positioning input within div

I have a div container. Between this div i have another div named model and there is a input file type.
Now when i open up this in my mozilla firefox browser all are looks good. Problem is when i clicked Browse... then it's didn't open to upload a file, but when i clicked outside of Browse... field then it open to upload a file. Here is my html file
input{
margin-bottom: 15px;
padding: 10px;
width: 100%;
box-sizing: border-box;
border-radius: 5px;
height: 50px;
border:0px;
font-family: georgia;
font-size: 12pt;
text-align: center;
}
<div class="container">
<div class="model">
<form>
<div>
<label>Profile Picture</label>
<input type="file" name="img">
</div>
</form>
</div>
</div>
I google it but didn't find any good resource that's helpful for this problem . Sugesstion please . Thank you !
You need to change your CSS code a bit. Try this.
input {
margin-bottom: 15px;
margin-top: 15px;
box-sizing: border-box;
border-radius: 5px;
height: 50px;
border: 0px;
font-family: georgia;
font-size: 12pt;
display: block;
}
As a way to debug the area of the button, you can use the outline attribute.
You set the width: 100%, so it takes the whole line as a block.
Adding the outline attribute and you may see it.
input{
margin-bottom: 15px;
width: 85px;
box-sizing: border-box;
border-radius: 5px;
height: 40px;
border:0px;
font-family: georgia;
font-size: 12pt;
text-align: center;
outline: 1px solid #FF0000;
}
<div class="container">
<div class="model">
<form>
<div>
<label>Profile Picture</label>
<input type="file" name="img">
</div>
</form>
</div>
</div>

html search form - align submit button

I have html search form - input and button.
Also I have Search title - h2 . But if I remove h2 title I have problem with button vertical-align.
html:
<h2 class="widget-title">Search</h2>
<form role="search" method="get" id="searchform" action="#">
<input type="text" placeholder="Search..." value="" >
<button type="submit" id="searchsubmit" value="">
<i class="fa fa-search"></i>
</button>
</form>
Css:
.widget-title {
margin-bottom: 40px;
font-size: 22px;
line-height: 18px;
}
#searchform input {
display: block;
max-width: 100%;
padding: 5px 10px;
border: 1px solid #ccc;
}
#searchsubmit {
position: absolute;
top: 59px;
right: 15px;
display: inline-block;
width: 50px !important;
height: 43px;
padding: 0;
border: none;
margin-bottom: 0;
vertical-align: middle;
background-color: transparent;
}
Is it possible to align button with and without search title (h2) ?
You don't need to use absolute positioning here, relative will be OK. position: relative and display: inline will solve the problem. And here is the working
js fiddle.
The markup is OK with <h2 class="widget-title">Search</h2> and without.

Vertically center a checkbox within a div

I have a checkbox within a div that is appearing higher than the text I want it to be aligned with.
Here's how it appears in Firefox:
As you can see, the checkbox is just a few pixels higher than the text. I have tried applying various padding / margins, including negative values, but to no avail.
HTML:
<div id="read-confirm-box">
I Have read the above
<input type="checkbox" id="checkbox" />
</div>
CSS:
#read-confirm-box
{
color: #FFF;
width: 180px;
font-size: 12px;
background-color: #333;
border-radius: 3px;
padding: 6px 11px;
margin: auto;
float: left;
}
#checkbox
{
/* Empty */
}
check this jsFiddle
HTML
<div id="read-confirm-box">
I Have read the above
<input type="checkbox" id="checkbox" />
</div>
CSS
#read-confirm-box
{
color: #FFF;
width: 180px;
font-size: 12px;
background-color: #333;
border-radius: 3px;
padding: 6px 11px;
margin: auto;
float: left;
}
#checkbox
{
position: relative;
top: 3px;
}
You can wrap both text and input into a div, It's a good practice.
To align both the divs containing text and control accordingly, use display properties
Try:
HTML
<div id="read-confirm-box">
<div class="inline">I Have read the above </div>
<div class="inline"><input type="checkbox" id="checkbox" /></div>
</div>
<label for="checkbox">I Have read the above </label>
<input type="checkbox" id="checkbox" />
<span>I Have read the above </span>
<span><input type="checkbox" id="checkbox" /></span>
CSS
.inline{
display:inline-block;
vertical-align:middle;
}
Fiddle Example
Updated
Try to use following css.
#checkbox {
vertical-align: middle;
}
The checkbox is likely higher for lack of a reset.css (browsers apply their own defaults).
For usability, you should use the label element, rather than wrapping the input and text in extra divs.
Give the input and label the same margin and voila!
HTML
<div id="read-confirm-box">
<input type="checkbox" id="checkbox" />
<label for="checkbox">I Have read the above </label>
</div>
CSS
#read-confirm-box {
color: #FFF;
width: 180px;
font-size: 12px;
background-color: #333;
border-radius: 3px;
padding: 6px 11px;
margin: auto;
float: left;
}
input {
margin: 3px;
}
label {
float:left;
margin: 3px;
}
http://jsfiddle.net/djungle/x6EUp/1/
Pretty easy fix.
CSS:
#checkbox {
vertical-align:middle;
}
Or as an alternative, forking that fiddle: Fiddle
#checkbox
{
vertical-align:-2px;
}

Button not aligned with input (due to padding of input)

The button below is not aligning with the input.
The input has to be on the same height as the button, though the padding of the input seems to have a influence on the alignment! The difference between padding-top and padding-bottom creates this shift of the button.
I made a fiddle: http://jsfiddle.net/3RMhm/10/ to show what I mean.
CSS:
.button {
font-size: 15px;
padding: 9px 23px;
border:0;
}
.form {
width: 290px;
background-color: #F9F9F9;
font-size: 18px;
color: #333;
height: 25px;
border:1px solid darkgray;
padding-top: 15px; <--- This padding
padding-bottom: 0px; <--- And this padding
}
HTML:
<input name="name" class="form" />
<input class="button" type="submit">
Just add vertical-align: middle to both elements (button and input).
http://jsfiddle.net/3RMhm/3/
Use:
vertical-align:middle;
margin-top: -5px;
http://jsfiddle.net/Hive7/3RMhm/2/
In your .form class,just change padding-top and padding-bottom values to :
.form {
padding-right: 4px;
padding-bottom: 8px;
}