inline-block content shows different results in different browsers? - html

I have a responsive form element which is supposed to be inline with a title, like so:
which is fine in Firefox because this is what I'm looking for.
But when we see the same code in Chrome (edit, same results in Blisk, Yandex and maybe all webkit browsers, along with MS Edge and IE11), this is what I get:
The code:
h1,
form {
display: inline-block;
vertical-align: middle;
}
h1 {
font-size: 48px;
}
.field {
display: table-cell;
}
.field,
input {
width: 100%;
}
input,
.btn {
padding: 10px 16px;
box-sizing: border-box;
}
<h1>Inline title</h1>
<form action="">
<div class="field">
<input type="text" placeholder="Email Address" />
</div>
<div class="field">
<button class="btn">Submit</button>
</div>
</form>
Or, take a look at the code here (Codepen.io).
Does FF and Chrome handle the CSS differently? I feel that Chrome is showing the correct layout considering that the .field class has display: table-cell;, but I'm not sure about that. Is there a way to achieve what Firefox has shown in Chrome as well without removing the responsive nature of the input field?
Thanks.

Just remove the property: table-cell and make sure that everything is inline-block:
h1,
form {
display: inline-block;
vertical-align: middle;
}
h1 {
font-size: 48px;
}
.field {
display: inline-block; /* instead of table-cell > inline-block */
}
input,
.btn {
padding: 10px 16px;
}
SEE demo here: CODEPEN

There is no need to use table-cell just use float:left and remove the width from field class.
h1,
form {
display: inline-block;
vertical-align: middle;
}
h1 {
font-size: 48px;
}
.field {
float: left;/* Use floating here */
}
.field,
input {
/*width: 100%;*/
}
input,
.btn {
padding: 10px 16px;
}
<h1>Inline title</h1>
<form action="">
<div class="field">
<input type="text" placeholder="Email Address" />
</div>
<div class="field">
<button class="btn">Submit</button>
</div>
</form>

Related

Aligning 2 HTML inputs in the same line, when input[type=text] was already defined

I want to align two inputs in the same line.
I used the solutions available here:
http://jsfiddle.net/XAkXg/
http://www.java2s.com/Code/HTMLCSS/Form/inputclassidselectorandpropertyselector.htm
Aligning html inputs on same line
html form - make inputs appear on the same line
Everything would work, but in my case, the input[type=text] has been defined earlier
The CSS code looks pretty much as this:
input {
margin-left: 50px;
}
input[type=text] {
width: 75%;
min-width: 450px;
padding: 12px 20px;
box-sizing: border-box;
outline: none;
border: 1px solid #f7fbff;
background-color: #f7fbff;
}
input[type=text]:focus {
background-color: #c6e2f2;
}
input[type=number]:focus {
background-color: #c6e2f2;
}
and now I have implemented the location feature into my HTML code:
<figure class="fig" id="location">
<label>
<div class="order">1</div>
<p>Location<span class="asterisk">*</span></p>
</label>
<button class="locbtn" id="btn-geolocation">Find my location</button>
<br>
<label for="lat" class="location">Latitude</label>
<input type="text" name="latitude" class="location">
<label for="lon" class="location">Longitude</label>
<input type="text" name="longitude" class="location">
<div style="clear:both;"></div>
</figure>
and accordingly CSS:
.location {
width: 50x;
float: left;
vertical-align: top;
margin: auto;
}
.location input[type=text]{
width: 25px;
display: inline-block;
}
and the effect is, as you can see below:
the input texts don't work, since they have been defined earlier in the code (for entire form).
How can I make the input[type=text] definition also for this section considered?
Moreover, instead of display: inline-block; I tried: display: inline; and float: left; It didn't work either.

Force line break after inline-block element using CSS

I am currently trying to make a simple form. As an example, this is what I'm trying to get it to look like.
This is the current architecture for each field:
<p>
<label>First Name</label>
<input></input>
</p>
I struggle once I get to the CSS part. Here's a full example, and any help would be greatly appreciated
div {
text-align: center;
}
form p {
display: inline-block;
}
form label {
text-align: left;
display: block;
}
<div>
<form>
<p><label>Name:</label> <input type="text"></p>
<p><label>Password:</label> <input type="text"></p>
</form>
</div>
I just cannot figure out how to get a line break after the input with the current CSS.
can use float instead of inline-block
form {
max-width: max-content;
margin: auto;
}
form p {
float: left;
clear: left;
}

CSS table is combining cells into the same column in IE 11

I have a form that is styled with CSS as a table. However the two input elements are shown to be on top of each other and not side by side. How can I get them to be side by side?
As noted in the comments this might be browser related. I am running it on IE 11.0.14393.0 on Windows 10.
div,
a {
font-family: Segoe, "Segoe UI", sans-serif
}
.FormContainer form {
display: table;
}
.FormContainer form div {
display: table-row;
}
.FormContainer form div label,
.FormContainer form div input {
display: table-cell;
margin: 5px 0px;
}
.FormContainer form div label {
vertical-align: middle;
padding-right: 10px;
}
.FormContainer form div input[type=text] {
min-width: 200px;
}
<body>
<div>
<p><font size="6"><u><strong>Search Users</strong></u></font></p>
<p>Search for...</p>
</div>
<div class="FormContainer">
<form action="SearchNewestUsers.php" method="post">
<div>
<label for="UserCount">Newest users</label>
<input type="text" name="UserCount" id="UserCount" placeholder="Enter number of users...">
<input type="submit" name="SearchButton" id="SearchButton" value="Search">
</div>
</form>
</div>
</body>
The snippet above produces the following output for me:
So the fault is with IE, and it doesn't seem to like the display: table-cell that you have. The solution I've found is to change to inline-block for the two inputs.
div,
a {
font-family: Segoe, "Segoe UI", sans-serif
}
.FormContainer form {
display: table;
}
.FormContainer form div {
display: table-row;
}
.FormContainer form div label,
.FormContainer form div input {
display: table-cell;
margin: 5px 0px;
}
.FormContainer form div input {
display: inline-block!important;
margin: 5px 0px;
}
.FormContainer form div label {
vertical-align: middle;
padding-right: 10px;
}
.FormContainer form div input[type=text] {
min-width: 200px;
}
<body>
<div>
<p><font size="6"><u><strong>Search Users</strong></u></font>
</p>
<p>Search for...</p>
</div>
<div class="FormContainer">
<form action="SearchNewestUsers.php" method="post">
<div>
<label for="UserCount">Newest users</label>
<input type="text" name="UserCount" id="UserCount" placeholder="Enter number of users...">
<input type="submit" name="SearchButton" id="SearchButton" value="Search">
</div>
</form>
</div>
</body>

css - align label & textbox at right side of page

I have created 4 column grid in my html form. i want to have last label and textbox field to be align right side of the page.
I have tried using float:right property but it doesn't seem to work
In fiddle example it is not in single line.
.row {
margin: 10px;
}
.elements {
padding: 10px;
margin-left: 50px;
margin-top: 10px;
border-bottom: ridge;
border-bottom-color: #1f6a9a;
padding-left: 0;
}
.field {
font-size: 15px;
color: #b6d6ed;
}
label {
display: inline-block;
}
input {
background-color: transparent;
border: 0px solid;
height: 25px;
width: 60px;
color: #b6d6ed;
text-align: center;
}
/* I Tried Below Line to Right Align */
.row > .elements:nth-child(2) {
float:right;
}
<div class="row">
<span class="elements">
<label class="field" for="Title">Title</label>
<input id="Title" name="Title" type="text">
</span>
<span class="elements">
<label class="field" for="DateOfBirth">Date of Birth</label>
<input id="DateOfBirth" name="DateOfBirth" type="text" value="" class="hasDatepicker">
</span>
</div>
jsfiddle
Float the first span to the left:
.row > .elements:first-child {
float: left;
}
See it here: http://jsfiddle.net/3DtqB/2/
You have to put the elements class into a <div class=".."></div> and add an CSS command
.elements {
float: right;
margin-top: -[x]px
}
Also you should use two id's instead of a class elements like left_box and right_box and add the commands to the right box.
Simple fix, just add white-space:nowrap; to the .elements class.

how to arrange the input text/file in a line

I am designing a web page with multi line Label name & input type file. i tried very hard to arrange in same line sequence but failed to do. Is there any idea about it?
please take a look enter link description here , it looks very ugly and
I am not really sure what you are looking for, but check out the jsfiddle changes I had made. I modified both CSS classes a little bit.
Have a look at this tutorial: http://www.websiteoptimization.com/speed/tweak/forms/
You can check this fiddle with the following modifications:
removing deprecated attributes align from div and moving inlined CSS style (style attribute) to the CSS file
same for b element used for the text of the label: span is better, and it's already bold as its parent. Or font-weight: bold; would be added in CSS
display: inline-block; is used instead of floats. No need to clear them afterward. IE7 and 6 need a fix (in comment) if you support them. This allow you to give the element a width (like you could do with any block element) and still get them on the same horizontal line (like you could do with any inline element). You'll have 4px due to whitespace in your HTML code, because whitespace shows up in inline element like two span separated by a space but there's a fix.
HTML code
<div id="divid1">
<p>
<label class="labelname"> <span> select Image* :</span>
<input type="file" name="file1" class="hide-file" />
</label>
</p>
<p>
<label class="labelname"> <span>XML File* :</span>
<input type="file" name="file2" class="hide-file" />
</label>
</p>
</div>
CSS
#divid1 {
padding: 50px;
}
.labelname {
width: 100%; /* or at least approx. 380px */
min-height: 30px;
display: block;
background: lightgreen;
font-weight: bold;
margin-bottom: 2px;
}
/* Only for IE7 */
/*.labelname span,
.hide-file {
display: inline;
zoom: 1;
}
*/
.labelname span {
display: inline-block;
width: 140px;
text-align: right;
background-color: lightblue;
}
.hide-file {
display: inline-block;
opacity:0.5;
}
now it looks good :)
html
<div id="divid1" align="center" style="padding:50px;">
<div class="formrow">
<label class="labelname" for="hide-file">Select Image* :</label>
<input type="file" name="file1" class="hide-file" />
</div>
<div class="formrow">
<label class="labelname" for="hide-file">XML File* :</label>
<input type="file" name="file2" class="hide-file" />
</div>
</div>
css
.labelname {
background: green;
font: bold 2px;
margin-bottom: 2px;
font-weight: bold;
float: left
}
.hide-file {
position: relative;
opacity: 0.5;
float: right
}
.formrow {
width: 400px
}