The width isnt setting for the textarea control. It sets for the other controls. Could somebody tell me why isnt the width applying for text area
For example
Setting border to solid for col-md-6
<div class="form-group">
#Html.LabelFor(model => model.ProjectName, htmlAttributes: new { #class = "control-label col-md-5" })
<div class="col-md-6">
#Html.EditorFor(model => model.ProjectName, new { htmlAttributes = new { #class = "form-control", style = "width:100%" } })
#Html.ValidationMessageFor(model => model.ProjectName, "", new { #class = "text-danger" })
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
#Html.LabelFor(model => model.ProjectSummary, htmlAttributes: new { #class = "control-label col-md-5" })
<div class="col-md-6">
#Html.TextAreaFor(model => model.ProjectSummary, new { htmlAttributes = new { #class = "form-control", rows = "3", style = "max-width:100%" } })
#Html.ValidationMessageFor(model => model.ProjectSummary, "", new { #class = "text-danger" })
</div>
</div>
The real width is the width the textarea has. The col-md-6 will make it that wide. The problem is that the container you're applying the border to does not actually constrain the textarea. If I understand you correctly that you're applying the border to the div with the col-md-6 class, that could very well be your issue. The grid classes that Boostrap employ various width, margin and padding settings to construct a grid that is as close to cross browser as possible, and applying actual visible style to them almost always causes weirdness like this. Instead, wrap your textarea with another div and apply the border to that:
<div class="col-md-6">
<div class="my-awesome-border">
#Html.TextAreaFor(model => model.ProjectSummary, new { htmlAttributes = new { #class = "form-control", rows = "3", style = "max-width:100%" } })
#Html.ValidationMessageFor(model => model.ProjectSummary, "", new { #class = "text-danger" })
</div>
</div>
Long and short, you should always avoid adding additional style to anything with Bootstrap's grid classes (col-*, row, etc.).
Related
I have a navigation bar that displays properly until a user logs in.
Before logging in:
After logging in:
I'm having trouble figuring out why the Log Out fontawesome icon is wrapping onto the next line, when it's the same size (I attempted making it slightly smaller even) than the avatar icon to login. The problem isn't the width of the parent div, because I attempted adding another <li><a>Test Item</a></li> and it didn't wrap to the next line.
HTML:
<ul class="nav navbar-nav navbar-right">
<li><a class="active" href="../../">Home</a></li>
<li>Build A Box</li>
<li>FAQ</li>
<li>Contact Us</li>
#if (User.Identity.IsAuthenticated)
{
<li>My Account</li>
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" }))
{
#Html.AntiForgeryToken()
<li></li>
}
}
else
{
<li class="nav-item dropdown">
<div class="dropdown-menu" aria-labelledby="LoginDropdownLink">
#using (Html.BeginForm("Login", "Account", new { ReturnUrl = "../../Home/Account" }, FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
#Html.TextBoxFor(m => m.Email, new { #class = "input-text", #placeholder="Email Address"})
#Html.ValidationMessageFor(m => m.Email, "", new { #class = "text-danger" })
#Html.PasswordFor(m => m.Password, new { #class = "input-text", #placeholder="Password" })
#Html.ValidationMessageFor(m => m.Password, "", new { #class = "text-danger" })
#Html.CheckBoxFor(m => m.RememberMe)
#Html.LabelFor(m => m.RememberMe)
<input type="submit" value="Log in" class="btn btn-default" />
}
</div>
</li>
}
</ul>
It's hard to say without the CSS but try to remove nav-link in the class attribute of the logout link (l.14 in your code).
So the line will be:
<li></li>
Because the other links do not have this class so I suspect it to be the cause of your trouble.
I am new to ASP MVC,CSS and html.
Here is what i want to do:
1. Right after an Editorfor("Type" filed in my example), i need a button to display all available options in the database. I have already achieved this by using JQuery UI autocomplete.
2. Validation on this required field. I need to display validation message below the editor box. My code is not working.
<div class="form-group">
#Html.LabelFor(model => model.Description, htmlAttributes: new { #class = "control-label col-md-2 required" })
<div class="col-md-10">
#Html.EditorFor(model => model.Description, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.Description, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
#Html.LabelFor(model => model.TestType, htmlAttributes: new { #class = "control-label col-md-2 required" })
<div class="col-md-10">
#Html.EditorFor(model => model.TestType, new { htmlAttributes = new { #class = "form-control" } })
<button id="ShowAllType" class="ui-button ui-widget ui-corner-all" title="Show all existing test types">
<span class="ui-icon ui-icon-triangle-1-s"></span>
</button>
#Html.ValidationMessageFor(model => model.TestType, "", new { #class = "text-danger" })
</div>
</div>
Here is before post.
Here is after post.
As the picture shows, "Description" field is OK. I need help to fix the alignment on "Type" field to display same as Description field. Thanks in advance.
Add CSS and JS:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="~/Scripts/jquery-3.1.1.js"></script>
<script src="~/Scripts/jquery-ui-1.12.1.js"></script>
<style>
.ui-autocomplete-loading {
background: white url("../images/ui-anim_basic_16x16.gif") right center no-repeat;
}
.ui-autocomplete {
max-height: 300px;
overflow-y: auto;
/* prevent horizontal scrollbar */
overflow-x: hidden;
/* add padding to account for vertical scrollbar */
padding-right: 20px;
}
#ShowAllType {
position: absolute;
top: 0;
bottom: 0;
margin-left: -1px;
padding: 0;
}
#TestType {
position: relative;
display: inline-block;
}
.required:after
{
content: "*";
font-weight: bold;
color: red;
vertical-align:sub;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
$("#TestType").autocomplete({
source: function (request, response) {
$.ajax({
//url: "/EndEffectors/AutoCompleteType",
url: "#Url.Action("AutoCompleteType", "EndEffectors")",
type: "GET",
dataType: "json",
data: { Prefix: request.term },
success: function (data) {
$("#TestType").removeClass("ui-autocomplete-loading");
response(data);
}
})
},
complete: function () {
$("#TestType").removeClass("ui-autocomplete-loading")
},
minLength: 0,
messages: {
noResults: "", results: ""
}
});
$("#ShowAllType").on("click", function () {
$("#TestType").autocomplete("search", "");
return false;
});
}
)
</script>
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
Edit 2: I tried add <br/> after the button, here is the result. Button size is not right.
Tab Focus for following elements not working in Mozilla:
<div class="editor-field">
<div>
<%: Html.TextBox(model => model.AddressLine1, new { maxLength = 30, style = "width:300px", tabindex = "0" })%>
</div>
<div class="editor-field">
<div>
<%: Html.TextBox(model => model.AddressLine2, new { maxLength = 30, style = "width:300px", tabindex = "0" })%>
</div>
<div class="editor-field">
<div>
<%: Html.TextBox(model => model.AddressLine3, new { maxLength = 30, style = "width:300px", tabindex = "0" })%>
</div>
My CSS is:
editor-field > div > input:focus
{
outline: 1px dotted red !important;
}
May I know where I am wrong. Default Tab Navigation is not working in Mozilla Firefox. Working fine in Chrome and IE. Please assist me to fix this issue.
You have to use Jquery or Javascript to set focus like:-
$(document).ready(function() {
$('.editor-field').first().children().children('input').focus();
});
Given the code below I am trying to figure out the correct way to display the form fields wider then they do. i.e. The first two rows display roughly two bootstrap columns wide but I would expect the third row to display at the full width.
<div class="well">
<div class="row">
<div class="col-xs-4">
#Html.LabelFor(m => m.To)
#Html.EditorFor(m => m.To)
</div>
</div>
<br />
<div class="row">
<div class="col-xs-4">
#Html.LabelFor(m => m.Subject)
#Html.EditorFor(m => m.Subject)
</div>
</div>
<div class="row">
<div class="col-md-10">
#Html.LabelFor(m => m.Body)
#Html.EditorFor(m => m.Body)
</div>
</div>
******* Update ********
Changed one of the fields to this
<div class="row">
<div class="col-md-12">
#Html.TextBoxFor(m => m.Body, new { #class = "form-control", placeholder = "Body" })
</div>
</div>
You need to apply the form-control class to your inputs as this sets the input width to be 100% which means they will completely fill the column. Unfortunately EditorFor doesn't let you do that. However, TextBoxFor does:
#Html.TextBoxFor(m => m.To, new { #class = "form-control" })
I am using Twitter bootstrap 3.0 and razor views.
How can I align the image in the below div to the immediate right of the artist text box ?
<div id="artist"class="form-group">
#Html.LabelFor(m => m.Artists, new { #class = "col-lg-2 control-label" })
<div class="container">
#Html.TextBoxFor(m => m.Artists, new { placeholder = "Artist name",#class="form-control", id="artistinput"})
<img onclick="AddArtist()" id="plusartist" src="\Content\bootstrap\img\plus-button.png" class="img-thumbnail"/>
#Html.ValidationMessageFor(m => m.Artists)
</div>
</div>