html button is rendering below the input box - html

I have a input box for users to enter search terms in. I have a input button beside the search box. for some reason the button is rendering below the search box.
I want the button to be right beside the input box.
My html:
<div id="searchbox">
<form method="post" action="/search/test">
<div class="searchinput">
<input type="text" id="searchbox" value="" /></div>
<div class="searchbutton">
<input type="submit" id="searchboxbutton" value="Go" /></div>
</form>
</div>
CSS:
#header #searchbox
{
float:left;
width:400px;
padding:5px 0px 0px 0px;
}
#header #searchbox #searchinput
{
display:inline;
float:left;
}
#header #searchbox #searchbox
{
display:inline;
float:left;
}
#header #searchbox #searchbutton
{
display:inline;
float:left;
}

Simplify, simplify, simplify.
HTML
<form method="post" action="/search/test">
<input type="text" id="searchbox" value="" />
<input type="submit" id="searchboxbutton" value="Go" />
</form>
CSS
input {display: inline}

Your <input type="text" id="searchbox" value="" /> is matching this style (width: 400px) as well:
#header #searchbox
{
float:left;
width:400px;
padding:5px 0px 0px 0px;
}
IDs must be unique - change it or the containing element and write your styles accordingly.
http://validator.w3.org/docs/errors.html
141: ID X already defined
An "id" is a unique identifier. Each time this attribute is used in a
document it must have a different
value. If you are using this attribute
as a hook for style sheets it may be
more appropriate to use classes (which
group elements) than id (which are
used to identify exactly one element).

Just add this CSS to your CSS style sheet:
.searchinput{
display:inline-block
}
It will add your content in one row.

You have an id based selector in CSS (#searchinput) but you are using classes in markup (<div class="searchinput">). Change either of the ones and it should work.
Third, you don't need the display:inline. Just float: left will do. Also, floated elements are required to have a width. So set a width.

Probably because your #searchbox width is 400px and your input tag and button tag is more than 400 px.
Try making the #searchbox width to 600px and see what happens.
Change your css from
#header #searchbox
{
float:left;
width:400px;
padding:5px 0px 0px 0px;
}
#header #searchbox #searchinput
{
display:inline;
float:left;
}
#header #searchbox #searchbox
{
display:inline;
float:left;
}
#header #searchbox #searchbutton
{
display:inline;
float:left;
}
to
#header
{
float:left;
width:400px;
padding:5px 0px 0px 0px;
}
#searchinput, #searchbox, #searchbutton, #searchboxbutton
{
display:inline;
float:left;
}

Related

Align textarea and button without button moving down when value is inserted

I'm trying to align a text area and a button on the same line. I've successfully managed to do so, the code is in the fiddle below (though for some reason the fiddle won't align them).
Problem: Whenever I insert a value in the button, the button will go something like 30px downwards, still on the same line but just lower than the text area. This will only happen when a value is inserted within the button.
All the code is in the fiddle: https://jsfiddle.net/13qy0acp
Code:
HTML
<div id="messagebox">
<p id="headings"><textarea name="msg" style="height:40px;text-align:center" id="message" placeholder="Insert message"></textarea></p>
<p id="button"><input type="button" value="Send" onclick="submitChat()" id="innerbutton"></p>
</div>
CSS
#headings {
text-align:center;
display:inline-block;
width:70% !important;
margin-top:20px;
}
#message {
width:100%;
}
#button {
text-align:center;
display:inline-block;
width:8%;
margin-top:-30px !important;
border:solid black;
height:50px;
}
#innerbutton {
width:100%;
height:20px;
text-decoration:none;
}
If you want to horizontally align two elements, use the float property and set a width that adds to no more than 100% of the width of the parent element.
example:
textarea {
width:90%;
float: left;
}
button {
width:10%;
float: left;
}

Align Label with respect to TextField

I want my firstLabel to be just right side of the textfield on the same line.
//css
input[type="text"]{
display:block;
margin-bottom:10px;
width: 50px;
text-align:center;
float:center;
}
label {
float: right;
text-align:right;
color: white;
font:12;
}
//html
<label for="first">First Value</label>
<input type="text" value="93" id="firstTF"/><br/>
http://jsfiddle.net/x3gb6gcw/2/
html
<input type="text" value="93" id="firstTF"/>
<label for="first">First Value</label>
css
input[type="text"]{
display:block;
margin-bottom:10px;
width: 50px;
text-align:center;
display:inline-block;
}
label {
text-align:left;
color: #000;
font:12;
display:inline-block;
}
Try this-
CSS Code-
input[type="text"]{
display:inline;
margin-bottom:10px;
width: 50px;
text-align:center;
float:left;
}
label {
display: inline;
text-align:right;
color: white;
font:12;
}
Fiddle - http://jsfiddle.net/Ashish_developer/gjamenoy/
In fiddle, I have changed the color of label since fiddle's background is white, so giving white color to label will not show it. Just to show it in fiddle I have given color black to it.
Form controls are inline elements so if you just put your label tag after the textbox input control then they'll line up on their own(unless you set the width of the parent element too narrow for them both to fit naturally.
<input type="text" id="myText"/><label for="myText">My Label</label>
No need for CSS to position them this way, they float left by default.

Search text field and button height / position (CSS)

I have a problem with my search box. I'm trying to make the text field and button the same height, but I can't get it right in all browsers. Here is the code: http://codepen.io/anon/pen/ygCFz . This method works fine in Firefox, but not in Chrome.
So what would be the best method to have an equal height and position for both the text field and button?
Thanks!
//edit: because someone asked for the code for further reference, here it is:
HTML
<form id="search" action="" method="get">
<input type="text" name="search" class="sfield" value="search and go"/>
<input type="submit" value="Search" class="sbutton"/>
</form>
CSS
input.sfield{
background-color:#fff;
border-color:#cecece;
border-style:solid;
border-width:1px 0 1px 1px;
font-size:0.9em;
line-height:1em;
height:26px;
}
input.sbutton{
background-color:#d91515;
height:inherit;
border:none;
color:#fff;
position:relative;
left:-6px;
bottom:-1px;
height:28px;
}
Use padding instead height on input elements. Line-height should be exactly the same as font-size for Firefox. So if you want you font-size to 16px, put your line-height to 16px and add padding at top and bottom. For your submit button, use absolute positionning to be sure it will be at top:0 and bottom:0. Just add padding-left for submit button width equivalent on input and it's all done !
#search {
position:relative;
display:inline-block;
}
input.sfield{
background-color:#fff;
border-color:#cecece;
border-style:solid;
border-width:1px 0 1px 1px;
font-size:0.9em;
line-height:1;
padding:5px;
display:inline-block;
padding-right:50px;
}
input.sbutton{
background-color:#d91515;
border:none;
color:#fff;
position:absolute;
top:0px;right:0px;bottom:0px;
width:50px;
}
You can either set a definite height property for both elements or you can simply tell Sbutton to inherit the styles from Sfield.
<input type="submit" value="Search" class="sfield sbutton"/>
I also adding a bit of padding to make it even.
http://codepen.io/anon/pen/zBlwD
HTML:
<form id="search" action="" method="get">
<input type="text" name="search" class="sfield" value="search and go"/><input type="submit" value="Search" class="sbutton"/>
</form>
CSS:
input.sfield{
background-color:#fff;
border-color:#cecece;
border-style:solid;
border-width:1px 0 1px 1px;
font-size:0.9em;
line-height:0.9em;
height:26px;
margin: 0;
}
input.sbutton{
background-color:#d91515;
height:inherit;
border: 1px solid #d91515;
color:#fff;
position:relative;
margin: 0;
height:30px;
}
Well, I hope the solution isn't this simple, but you have height defined twice in your rule for the sbutton class:
input.sfield{
background-color:#fff;
border-color:#cecece;
border-style:solid;
border-width:1px 0 1px 1px;
font-size:0.9em;
line-height:1em;
height:26px;
}
input.sbutton{
background-color:#d91515;
height:inherit; //that's one
border:none;
color:#fff;
position:relative;
left:-6px;
bottom:-1px;
height:28px; //that's two
}
See what happens when you get rid of one. It should work. Also take a look at the line-height rule for your textbox. If the font size is different than the line height, that would explain why the sizes are different. Firefox and Chrome use different conversions from ems to pixels and vice versa.

Left margin is different in all browsers?

Using CSS3 I am trying to display search box with glass image. I am doing it basically by placing a image on text box and setting its left-margin. My code is here:
<body>
<form id="header-search">
<input type="text" class="searchbox" /><input type="submit" class="button" value="" />
</form>
</body>
#header-search{overflow:auto;}
#header-search input.searchbox
{
border-bottom-left-radius:5px;
-webkit-border-bottom-left-radius:5px;
-moz-border-bottom-left-radius:5px;
border-top-left-radius:5px;
-webkit-top-left-radius:5px;
-moz-left-radius:5px;
border:1px solid #8e8e8e;
background-color:white;
height:16px;
padding:4px;
padding-left:28px;
padding-right:10px;
color:#4a4a4a;
float:left;
}
#header-search input.button{
border:0px dashed red;
padding:0;
margin:0 0 0 -185px;
width:24px;
height:24px;
background:transparent url(../images/SearchImage.png) center center no-repeat;
float:left;
}
UPDATE
I am not using em rather px
I have tried different css reset.
please see image for details difference.
I have done this code in new css/ html file where there is no other line of code.
Using position:absolute seems to be a more reliable approach for this kind of thing.
HTML
<form id="header-search">
<div class='relative'>
<input type="text" class="searchbox" /><input type="submit" class="button" value="" />
</div>
</form>
CSS
.relative {
position:relative;
}
.relative .button {
position:absolute;
left: 20px;
z-index:1;
}
You may want to make this css more specific to this search input rather than all .button's etc
Its because you are not specifying a width of your search input box.
If you do that, you method will work.
Else, of course, the better way is to use position:absolute to position your button.
This will ensure the layout across all browsers.
If you want to place image for search input box , you can try this http://jsfiddle.net/HmKZQ/1/
If you need the button for click then you can try this
http://jsfiddle.net/HmKZQ/3/

How to put web form elements on a new line?

How to place "input" elements on new lines? In the above example all elements are placed sequentially, ie lable->input->lable->input, etc.
/* ----------- My Form ----------- */
.myform{
margin:0 auto;
padding:14px;
}
#stylized{
border-width:1px;
border-style:solid;
border-color:#b7ddf2;
background:#ebf4fb;
}
#stylized h1 {
font-size:14px;
font-weight:bold;
margin-bottom:8px;
border-width:1px;
border-style:solid;
border-color:#b7ddf2;
padding-bottom:10px;
}
#stylized label{
display:block;
font-size:11px;
font-weight:bold;
text-align:right;
float:left;
}
#stylized input{
float:left;
font-size:11px;
padding:4px 2px;
border:solid 1px #aacfe4;
width:70px;
margin:2px 0 20px 10px;
}
/* --------- End of Form --------- */
<div id="stylized" class="myform">
<form id="form" name="form" method="post" action="index.html">
<h1>Data</h1>
<label>Name: </label>
<input type="text" name="name" id="name"/>
<label>Email: </label>
<input type="text" name="email" id="email"/>
<label>Password: </label>
<input type="text" name="password" id="password"/>
</form>
</div>
#stylized input{
display: block;
font-size:11px;
padding:4px 2px;
border:solid 1px #aacfe4;
width:70px;
margin:2px 0 20px 10px;
}
This will put every input on a new line.
- Removed "float: left", added "display: block".
I put them under list tags and it worked without changing styles and using a break tag is obsolete
<ul>
<li><input type = "text" name = "selection" value = "text1" /> Text1</li>
<li><input type = "text" name = "selection" value = "text2" /> Text2</li>
</ul>
Have you tried anything as simple as
<label>Name: </label><br>
<input type="text" name="name" id="name"/>
<label>Email: </label><br>
<input type="text" name="email" id="email"/>
My guess is user1359163's anwswer will help, though you might care to know why: using float effectively removes the element out of the document's normal flow, a bit like changing the z-index, allowing the element to flow over div borders, labels, spans and... 'ignore' clear styles.
The element behaves as if it floats over the other elements, so in that respect, it stays clear of the left and right of all other elements that don't float.
I'm no CSS expert, but this way of looking at it has helped me a lot in solving issues with mangled layouts I've encountered when using the float, clear and z-index styles.
You prevent new lines when selecting a floating layout with enough room for all elements.
Try this:
Sample
http://jsfiddle.net/8yZff/
#stylized label{
font-size:11px;
font-weight:bold;
text-align:right;
}
#stylized input{
font-size:11px;
padding:4px 2px;
border:solid 1px #aacfe4;
width:70px;
margin:2px 0 20px 10px;
display: block;
}
Here is JsFiddle for that...
Edit :
#stylized label{
font-size:11px;
font-weight:bold;
text-align:right;
}
#stylized input{
display:block;
font-size:11px;
padding:4px 2px;
border:solid 1px #aacfe4;
width:70px;
margin:2px 0 20px 10px;
}​
For tabular data, such as an array of label/field pairs, use a table. You will find styling much easier, and nonstyled appearance much better.