put Button and text box in parallel - html

Im trying to put the following button and text box in parallel that the button in the left side and the text box in the right ,I try with span and margin but currently the text box is under the button ,how should I do that>
<span>
<input type="submit" id="Connect" style="margin-left: 195px; width: 150px;" class="btn action-but" />
<div class="form-group">
#Html.LabelFor(model => model.Service, new { #class = "col-md-2" })
<div class="col-md-10">
#Html.TextBoxFor(model => model.Service, new { #style = "width: 700px;" })
#Html.ValidationMessageFor(model => model.Service)
</div>
</div>
</span>

If i understand good you want to show something like this:
[button] [label text errors]
To do that a easy way is to add in style: display: inline-block;
The result, based on your code will be something like this
<span>
<input type="submit" id="Connect" style="display: inline-block;margin-left: 195px; width: 150px;" class="btn action-but" />
<div class="form-group" style="display: inline-block;">
#Html.LabelFor(model => model.Service, new { #class = "col-md-2" })
<div class="col-md-10">
#Html.TextBoxFor(model => model.Service, new { #style = "width: 700px;" })
#Html.ValidationMessageFor(model => model.Service)
</div>
</div>
</span>
You can find in JsFiddle a demo of this: http://jsfiddle.net/pR6Wg/

I think you are looking for vertical form. look at this example bootstrap vertical form
Razor example
<form class="form-inline" role="form">
<div class="form-group">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">#</div>
#Html.TextBoxFor(model => model.Service, new { #class="form-control", #placeholder="Enter email" })
</div>
</div>
</form>

Remove margin-left: 195px of submit button add add it inside .col-md-2 before the label.
and change <div class="col-md-10"> to <div class="col-md-8">
DEMO
CODE
<span>
<div class="form-group">
<div class="col-md-2">
<input type="submit" id="Connect" style=" width: 150px;" class="btn action-but" />
</div>
#Html.LabelFor(model => model.Service, new { #class = "col-md-2" })
<div class="col-md-8">
#Html.TextBoxFor(model => model.Service, new { #style = "width: 700px;" })
#Html.ValidationMessageFor(model => model.Service)
</div>
</div>
</span>

Why don't use a table? Or you want to do it with div's?
<table class="col-md-10">
<td>
<tr>
#Html.TextBoxFor(model => model.Service, new { #style = "width: 700px;" })
</tr>
</td>
<td>
<tr>
#Html.ValidationMessageFor(model => model.Service)
</tr>
</td>
</table>
Hope it helps! =)

Related

Disable autofill in HTML

I'm trying to disable autocomplete in two password fields but i couldn't do it. It worked fine with the "autocomplete = off" on textboxes but it didn,t work on password fields.
Thank you in advance.
<div class="form-group" autocomplete="new-password">
#Html.LabelFor(m => m.Password, new { #class = "col-md-5 control-label" })
<div class="col-md-5">
#Html.PasswordFor(m => m.Password, new { #Title = Password, #class = "form-control", #autocomplete = "new-password" })
</div>
</div>
<div class="form-group" autocomplete="new-password">
#Html.LabelFor(m => m.ConfirmPassword, new { #class = "col-md-5 control-label" })
<div class="col-md-5">
#Html.PasswordFor(m => m.ConfirmPassword, new { #class = "form-control", #autocomplete = "new-password" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-5">
<input type="submit" class="btn btn-default" value="Confirmer" />
</div>
</div>
You can try this.
Use a tag for the all html elements as a root. And use autocomplete="off" onto that tag.
Then add hidden with autocomplete="false" as a first children element of the form.
If this is not working, feel free to ask for that.
Look for a example : https://gist.github.com/niksumeiko/360164708c3b326bd1c8

How do you left align a div?

I Have tried to left align a div by using:
<div class="col-md-3 float-left">
and
<div class="col-md-3" style="text-align: left;">
nothing I try is working?
I tried the float now and the !important and still not working, so here is more of my code:
<div class="form-horizontal">
<h4>Branch</h4>
<hr />
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-group col-md-12">
<div class="col-md-2">
#Html.LabelFor(model => model.BranchName, htmlAttributes: new { #class = "control-label" })
</div>
<div class="col-md-3">
#Html.EditorFor(model => model.BranchName, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.BranchName, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group col-md-12">
<div class="col-md-2">
#Html.LabelFor(model => model.Active, htmlAttributes: new { #class = "control-label" })
</div>
<div class="col-md-3" style="float: left !important;">
#Html.EditorFor(model => model.Active)
#Html.ValidationMessageFor(model => model.Active, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class=" col-md-offset-1 col-md-2">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
And here is a pic to see what I mean. It looks terrible with the checkbox and the textbox so far from their labels.
Can't tell you much without more code or a more specific description of the problem. Regardless of that, my assumption is that you need the contents of a div left aligned? By the class names you are using, I assume you are using Bootstrap. In that case, try adding this class to your div:
text-left
If that doesn't work, try this:
style="text-align: left !important;"
If the second one works, you have CSS that is written somewhere else that is predominate, try to find this CSS and remove/change it. If you are confused about this, read up on CSS Specificity. Do not leave the !important attached for no reason; in general this is considered bad practice.
reference:
http://getbootstrap.com/css/#type-alignment
For left align of a div
<div style="float: left;"></div>
for left align of a text
<p style="text-align:left;"></p>
Try
<div class="col-md-1">
instead of
<div class="col-md-2">
on your Label Div's
The gap should come from the size of the col-md-2. If you choose col-md-1 the gap should be smaller.
You want to allign a div, and not a text. So you can use:
<div class="col-md-3" style="float:left">

How to place a button beside a select List

I am coding an MVC 5 view, and I want to place a button next to a select list. My current code places the button under the select list.
Here is my code:
<div class="form-group">
#Html.LabelFor(model => model.userName, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.DropDownListFor(m => m.userName, Model.userNames, htmlAttributes: new { #class = "form-control" })
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Select" class="btn btn-default" />
</div>
</div>
</div>
Here is an image showing the button placement:
Even if I have the following code, the button is under the select list:
<p>
#Html.LabelFor(model => model.userName, htmlAttributes: new { #class = "control-label col-md-2" })
#Html.DropDownListFor(m => m.userName, Model.userNames, htmlAttributes: new { #class = "form-control" }) <input type="submit" value="Select" class="btn btn-default" />
</p>
Don't put the submit button in a div.
A div is display: block by default.
<div class="input-group">
#Html.DropDownListFor(m => m.userName, Model.userNames, htmlAttributes: new { #class = "form-control" })
<span class="input-group-btn">
<input type="submit" value="Select" class="input-group-addon btn btn-default" />
</span>
</div>
By using the classes input-group on the div, input-group-btn on the span and input-group-addon on the select button , you can place dropdownlist and button on the same line.
Refer to this article :
https://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-input-groups.php

Create view put table on the right side of the screen

I having MVC project with User entity which have one to many relationship with address,
I use code first and by scaffolding generate the view . in the create operation I see in the left side of the screen the fields from userid until working at .what I need is very simple,in the right side of the screen create table on the create view which is currently empty with one column that user can add to address,how should I do that?
Im very new to MVC and didn't find any documentation on how to add control like table in the right side of the create vied.
I try something like this without success
the table is in the bottom of the screen
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>User</h4>
<hr />
#Html.ValidationSummary(true)
<div class="form-group">
#Html.LabelFor(model => model.UserId, new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.UserId)
#Html.ValidationMessageFor(model => model.UserId)
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.WorkingAt, new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.WorkingAt)
#Html.ValidationMessageFor(model => model.WorkingAt)
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
//This is the table which I want to be in the right side of the screen
<table class="table">
<tr>
<th>
#Html.EditorFor(model => model.Adress)
</th>
</table>
<div>
#Html.ActionLink("Back to List", "Index")
</div>
#section Scripts {
#Scripts.Render("~/bundles/jqueryval")
}
Try this:
<table class="table col-md-offset-11 col-md-10">
<tr>
<th>
#Html.EditorFor(model => model.Address)
</th>
</table>

Line two divs side by side inside a fieldset

I am trying to place these two divs side by side with each other but no matter what attempt I make, even if it's worked on another page, I get a results that looks like this:
Here's the HTML (It's an MVC site so I'm using Razor):
<fieldset id="AgentTypeFields" style="width: 400px;" >
<legend>Producer Info</legend>
<div id="BasicsContainer" style="clear:both;">
<div id="BasicsLeft" style="float: left;">
<div class="M-editor-label" >
#Html.LabelFor(model => model.ReferenceNumberType)
</div>
<div class="M-editor-label">
#Html.LabelFor(model => model.FormattedReferenceNumber)
</div>
<div class="M-editor-label">
#Html.LabelFor(model => model.ProducerType)<span class="req">*</span>
</div>
<div class="M-editor-label">
#Html.LabelFor(model => model.EffectiveDate)<span class="req">*</span>
</div>
<div class="M-editor-label">
#Html.LabelFor(model => model.JIT)
#Html.CheckBoxFor(x => x.JIT)
</div>
<span id="ExternalRepId">
<div class="M-editor-label">
#Html.LabelFor(model => model.ExtRepID)
</div>
</span>
</div>
<div id="BasicsRight" style="float:right;">
<div class="M-editor-field" style="margin-right: 120px;" >
#Html.RadioButtonFor(model => model.ReferenceNumberType, "S") SSN
#Html.RadioButtonFor(model => model.ReferenceNumberType, "E") EIN
</div>
<div class="M-editor-field" id="refNumber" style="margin-right:138px;">
#if (ViewBag.FullSSN)
{
#Html.DisplayFor(model => model.FormattedReferenceNumber)
}
else
{
#Html.Raw("xxx-xx-")#Html.DisplayFor(model => model.displayLastFour)
}
</div>
<div class="M-editor-field" style="margin-right:82px;">
#Html.DropDownListFor(x => x.ProducerType, (SelectList)ViewBag.ProducerChoices, new { id = "drpProducerType" })
</div>
<div class="M-editor-field">
#Html.TextBoxFor(model => model.EffectiveDate, new { maxlength = 10 })
#Html.ValidationMessageFor(model => model.EffectiveDate)
</div>
<div class="M-editor-field">
#Html.LabelFor(model => model.HoldBool)
#Html.CheckBoxFor(x => x.HoldBool)
</div>
<span id="ExternalRepId">
<div class="M-editor-field">
#Html.TextBoxFor(model => model.ExtRepID, new { maxlength = 40 })
</div>
</span>
</div>
</div>
</fieldset>
You need to specify the width on your floating divs, preferably to 50%.
Another solution is to use html tables or flex boxes
Try setting Css display: inline-block; for child divs. one more issue is as width for your fieldset is 400px both divs cannot be fitted inside it. Try setting it to 100%
<fieldset id="AgentTypeFields" style="width: 100%;" >
<legend>Producer Info</legend>
<div id="BasicsContainer" style="clear:both;">
<div id="BasicsLeft" style="display:inline-block;">
....
....
</div>
<div id="BasicsRight" style="display:inline-block;">
....
....
</div>
</div>
</fieldset>
FIDDLE