I'm trying to create an input with an icon indicating its purpose, but it's not rendering how I like:
I want the input at the same level as the icon, however, dispite my best efforts:
.field
{
margin: auto;
border-radius: 10px;
width: 67%;
white-space: nowrap;
overflow-x: auto;
}
.field input, .field label
{
display: inline-block !important;
margin: 0;
padding: 0;
}
<div class = 'field w3-bar w3-center w3-border w3-border-green'>
<label class='w3-bar-item w3-left w3-border-right w3-border-green fas fa-user' for='username'></label>
<input class="w3-bar-item w3-right w3-input w3-border-green w3-hover-border-green no-box" id="username" name="username" required type="text" value="">
</div>
— it still renders on a new line! Note that I'm using w3.css and font-awesome. Is there something I'm missing? Thank you.
How about like this?
.custom-input{
display:inline-block;
margin-left:12px;
}
.input-component{
border:3px solid teal;
padding:8px;
padding-left:30px;
}
.input-icon{
color:teal;
position:absolute;
margin-right:-30px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<div class="custom-input">
<span class="glyphicon glyphicon-user input-icon"></span>
<input class="input-component" placeholder="username...">
</div>
<div class="custom-input">
<span class="glyphicon glyphicon-calendar input-icon"></span>
<input class="input-component" type="date">
</div>
<br>
<br>
<div class="custom-input">
<span class="glyphicon glyphicon-lock input-icon"></span>
<input class="input-component" type="password" placeholder="password"/>
</div>
You can minimize the code to something like this:
<div style="width: 67%;display:flex; align-items:center;" class ="w3-padding w3-margin w3-border w3-border-green w3-round-large">
<label style="width:10%" class="w3-center w3-border-right w3-border-green fa fa-user" for="username"></label>
<input style="width:80% " class="w3-input" id="username" name="username" required type="text" value="">
</div>
And you don't need define the class "field" and the others.
Related
The line should be beside the button and before the search bar
.vertline{
border-right:4px solid black;
height:200px;
}
<div class="vertline">
<button class="hin"></button>
<label>Home</label>
<span><input type="text" placeholder="search videos" name="search"></span>
<span><input type="submit" value="" class="tel"></span>
</div>
If I understand you correctly, just put the the vertline class to the the span with the input field. Heres an example:
.vertline {
border-right: 4px solid black;
padding-right: 5px;
display: inline-block;
}
<div>
<button class="hin"></button>
<label>Home</label>
<span class="vertline"><input type="text" placeholder="search videos" name="search"></span>
<span><input type="submit" value="" class="tel"></span>
</div>
.line{
border-left:4px solid;
padding-left:5px;
}
<div class="vertline">
<button class="hin"></button>
<label>Home</label>
<span><input type="text" placeholder="search videos" name="search"></span>
<span class="line"><input type="submit" value="" class="tel"></span>
</div>
so I am working to create this really simple website, but the problem of that I put for example to elements in one and I cant make them fit their places for example:
.Form {
border: 2px solid black;
background-color: white;
margin: 1px;
float: left;
width: 50%;
white-space: nowrap;
padding: 0;
}
.Member {
width: 40%;
}
.Not_member {
width: 50%;
text-align: center;
}
fieldset {
margin: 0;
float: left;
}
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<div class="Form">
<form action="/action_page.php" method="post">
<fieldset class="Member">
<legend>Sign In</legend>
Sign in today for more experience <br><br>
<b>Email:</b> <br>
<input type="text" name="email" placeholder="Enter Email">
<br><br>
<b>Password:</b> <br>
<input type="password" name="password" placeholder="Password">
<br><br>
<input type="checkbox" name="remember" value="yes">remember me
<input type="submit" value="Log in">
</fieldset>
</form>
<fieldset class="Not_member">
<legend>Not a member ?</legend>
You can create an account:<br>
<i class="fa fa-sign-in" style="font-size:500%;color: grey;"></i>
</fieldset>
</div>
what i want to do is:
make each one fit half the container vertically and horizontally
make them stay horizontal and shrink with the container, so what i mean that when the window becomes smaller they become vertical, how can I stop that?
thanks in advance
.Form {
border: 2px solid black;
background-color: white;
margin: 1px;
float: left;
width: 100%;
white-space: nowrap;
padding: 0;
}
form{
width:55%;
}
.Member{
width:40%;
}
.Not_member {
width: 45%;
text-align: center;
padding:0;
margin:0;
}
fieldset {
margin: 0;
float: left;
}
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<div class="Form">
<form action="/action_page.php" method="post">
<fieldset class="Member">
<legend>Sign In</legend>
Sign in today for more experience <br><br>
<b>Email:</b> <br>
<input type="text" name="email" placeholder="Enter Email">
<br><br>
<b>Password:</b> <br>
<input type="password" name="password" placeholder="Password">
<br><br>
<input type="checkbox" name="remember" value="yes">remember me
<input type="submit" value="Log in">
</fieldset>
</form>
<fieldset class="Not_member">
<legend>Not a member ?</legend>
You can create an account:<br>
<i class="fa fa-sign-in" style="font-size:500%;color: grey;"></i>
</fieldset>
</div>
is there any way to achieve something like this:
I've tried options that I found here in stack (with using span) but even if i made it work it is impossible for me to do that white line on the right from icon, can someone help me?
My current code looks like that:
<form>
<input type="text" name="firstname" placeholder="Name">
<input type="text" name="firstname" placeholder="e-mail">
<input type="text" name="firstname" placeholder="website">
</form>
I've also tried adding that icon in container with borders to achieve effect:
<form>
<span class="form_frame"><i class="fa fa-user-circle-o" aria-hidden="true"></i>
</span>
<input type="text" name="firstname" placeholder="Name">
And css:
.form_frame {
height: 60px;
border-width: 1px solid;
border-color: white;
width: 100%;
background-color: #2b2b2b;
But no succes
Thank's for any help.
Add the icon and the input inside a span. You can then add a border to the whole span if you want to our you can put a border on just the icon or input box.
.fa-address-book-o {
border: solid;
border-color: red;
}
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<span><i class="fa fa-address-book-o" aria-hidden="true"></i><input type="text"/></span>
You can use Labels
I thinks this is a good start.
.wr{border:2px solid black;padding:12px;}
<form>
<diV class="wr">
<label for="user"> <i class="fa fa-camera-retro">(icon_img)</i></label><input type="text" name="user" placeholder="Username"/> </diV>
<div class="wr">
<label for="pass"> <i class="fa fa-futbol-o">(icon_img)</i></label><input type="password" name="password" placeholder="Password"/> </div>
</form>
I have a situation where I cannot change the HTML and everything has to be done with CSS.**** In the image below you can see there are text on either side of the input box. I need to have all text to be on left side. The span containing the text has a fixed width of 30 pixels. And I need the input box to have a fluid width so that it will fill the rest of the container. I just added a background color to the first container for illustration purposes.
<div class="input-group input-prepend">
<input name="monthlyBudget" class="form-control" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget" type="text">
<span class="input-group-addon add-on">$</span>
</div>
Entire HTML for the form:
<form class="calculators-form-inputs no-submit" id="form-calculator-affordability" name="calculator-affordability" data-parsley-validate="">
<div class="calculators-info-text">
<h2>How Much Car Can I Afford?</h2>
<p>Great question. Fill in the boxes below to help with the answer and determine what price you can afford to pay for a car.</p>
</div>
<div class="calculators-form-field credit-amount">
<div class="calculators-labels">
<label>Your monthly budget <i class="label-tooltip icon-info-sign glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip"></i>
<a class="calculators-helper-link" href="#" data-toggle="modal" data-target="#budgetCalModal">(Help me)</a>
</label>
</div>
<div class="calculators-sliders">
<input type="range" value="0" min="50" max="5000" step="50" tabindex="-1" data-bind="value: monthlyBudget">
</div>
<div class="calculators-inputs">
<div class="input-group input-prepend">
<span class="input-group-addon add-on">$</span>
<input name="monthlyBudget" class="form-control" type="text" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget">
</div>
</div>
<div class="calculators-inputs-error" id="affordabilityCalErrorBudget"></div>
</div>
<div class="calculators-form-field credit-term">
<div class="calculators-labels">
<label>Loan term<i class="label-tooltip icon-info-sign glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip"></i>
</label>
</div>
<div class="calculators-sliders">
<input type="range" value="0" min="12" max="84" step="12" tabindex="-1" data-bind="value: loanTerm">
</div>
<div class="calculators-inputs">
<div class="input-group input-append">
<input name="loanTerm" class="form-control" type="text" placeholder="0" required="" data-bind="number, live: loanTerm" data-parsley-min="12" data-parsley-max="84" data-parsley-type="digits" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-pattern="^(12|24|36|48|60|72|84)$" data-parsley-errors-container="#affordabilityCalErrorTerm">
<span class="input-group-addon add-on">mo</span>
</div>
</div>
<div class="calculators-inputs-error" id="affordabilityCalErrorTerm"></div>
</div>
<div class="calculators-form-field credit-apr">
<div class="calculators-labels">
<label>APR*<i class="label-tooltip icon-info-sign glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip"></i>
</label>
</div>
<div class="calculators-sliders">
<input type="range" value="0" min="0" max="30" step="0.1" tabindex="-1" data-bind="value: interestRate">
</div>
<div class="calculators-inputs">
<div class="input-group input-append">
<input name="interestRate" class="form-control" type="text" placeholder="0" required="" data-bind="number, live: interestRate" data-parsley-min="0" data-parsley-max="30" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-pattern="^[0-9]\d*(\.\d+)?$" data-parsley-maxlength="5" data-parsley-errors-container="#affordabilityCalErrorApr">
<span class="input-group-addon add-on">%</span>
</div>
</div>
<div class="calculators-inputs-error" id="affordabilityCalErrorApr"></div>
</div>
<div class="calculators-form-field credit-reduction">
<div class="calculators-labels">
<label>Down payment<i class="label-tooltip icon-info-sign glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip"></i>
</label>
</div>
<div class="calculators-sliders">
<input type="range" value="0" min="0" max="20000" step="100" tabindex="-1" data-bind="value: dPayment">
</div>
<div class="calculators-inputs">
<div class="input-group input-prepend">
<span class="input-group-addon add-on">$</span>
<input name="downPayment" class="form-control" type="text" placeholder="0" data-bind="number, live: dPayment" data-parsley-min="0" data-parsley-max="20000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorDown">
</div>
</div>
<div class="calculators-inputs-error" id="affordabilityCalErrorDown"></div>
</div>
<div class="calculators-actions">
<div class="calculators-buttons">
<input type="submit" value="Calculate">
</div>
</div>
</form>
What I have now:
This is what I need:
The original table and table-cell solution - http://jsfiddle.net/0jvnryhx/1/
New solution due to the updates from #ChaniLastnamé http://jsfiddle.net/8pq6thr7/
.input-group {
margin-bottom: 20px;
position: relative;
overflow: hidden;
clear: both;
}
.add-on {
width: 30px;
position: absolute;
left: 0;
top: 0;
}
.form-control {
margin-left: 30px;
}
Then you can manually adjust the width of the input the boxes to make them fit the container (visually full width), everything needs to be fixed width though.
Should be simple enough to do with just a calc().
.form-control{
width: calc(100% - 30px);
}
Here is a CodePen
Can you support flexbox? If so this is your solution:
.input-group {
display: -webkit-flex;
display: flex;
-webkit-align-items: baseline;
align-items: baseline;
/* make it pretty */
background: lightgrey;
/* whatever width you want */
width: 300px;
}
.input-prepend span {
/* that width you said needed to be there */
width: 30px;
/* align the $ against the input */
text-align: end;
}
.input-prepend input {
/* use all the space */
width: 100%;
/* make the input after the $ in layout */
-webkit-order: 2;
order: 2;
}
<div class="input-group input-prepend">
<input name="monthlyBudget" class="form-control" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget" type="text">
<span class="input-group-addon add-on">$</span>
</div>
If the browsers you need do not support flexbox. There are a few options. First I really really hope you’re able to render the span before the input instead of after the way it is in the code you posted. You also need to ensure there are no spaces in your HTML as that will cause this issue. If this HTML comes from a pre-rendered output you probably won’t have that issue.
If you can make those tweaks to the HTML this is your solution:
.input-group {
/* make it pretty */
background: lightgrey;
/* whatever width you want */
width: 300px;
}
.input-prepend span {
/* can’t set width properly while inline */
display: inline-block;
/* that width you said needed to be there */
width: 30px;
/* align the $ against the input */
text-align: end;
}
.input-prepend input {
/* use all the space minus the 30px from above */
width: calc(100% - 30px);
/* change the way width is calculated */
box-sizing: border-box;
}
<div class="input-group input-prepend"><span class="input-group-addon add-on">$</span><input name="monthlyBudget" class="form-control" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget" type="text"></div>
Finally if you really seriously can’t touch your markup AND you can’t support flexbox. You can do this which is a bit hacky but in the scheme of things not horrible:
.input-group {
/* make it pretty */
background: lightgrey;
/* whatever width you want */
width: 300px;
position: relative;
}
.input-group span {
/* can’t set width properly while inline */
display: inline-block;
/* that width you said needed to be there */
width: 30px;
/* align the $ against the input */
text-align: end;
/* pull this out of flow */
position: absolute;
/* vertically align with input */
top: 2px;
}
.input-group input {
/* use all the space */
width: 100%;
/* allow space for $ */
margin-left: 34px;
}
<div class="input-group input-prepend">
<input name="monthlyBudget" class="form-control" placeholder="0" required="" data-bind="number, live: monthlyBudget" data-parsley-min="50" data-parsley-max="5000" data-parsley-validation-threshold="1" data-parsley-trigger="keyup" data-parsley-errors-container="#affordabilityCalErrorBudget" type="text">
<span class="input-group-addon add-on">$</span>
</div>
Hope that helps!
I am using external CSS for some style ,
my link tag is as follow ,
<link href="<%=request.getContextPath()%>/css2/form.css" rel="stylsheet" TYPE="text/css">
the CSS file has following content
#CHARSET "ISO-8859-1";
legend {
padding: 0;
margin-top:-20px;
margin-left: -20px;
margin-right:-40px;
margin-bottom: -9px;
border: 0;
color: #999999;
background-color: #918D8D;
}
.input-group{
margin-left:15px;
}
and I used these classes in jsp as follow,
<div class="form-group">
<label for="dob" class="control-label col-xs-4">Date Of
Birth(DOB) :</label>
<div class="col-xs-8">
<div class="col-lg-8 input-group date form_date1" data-date-format="dd MM yyyy" data-link-format="yyyy-mm-dd">
<input type="text" class="form-control " size="10" name="dob" id="date" ">
<span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
why it is not working , here i am trying to add margine to text box.
Not sure which css you want to apply to your textbox. But if you want to apply input-group to your textbox then update your input tag as mentioned below :
<input type="text" class="form-control input-group" size="10" name="dob" id="date" ">
and apply !important to the margin of css input-group as mentioned below :
.input-group{
margin-left:15px !important;
}