在Asp.Net MVC4中为Razor控件应用CSS

时间:2015-06-04 09:00:44

标签: asp.net-mvc-4 razor

如何在mvc4中将宽度应用于剃刀控件@Html.RadioButtonFor

UserModel.cs

public string Emp_Gender{get; set;}

index.cshtml

@model MvcApplication.Model.UserModel

@using (Html.BeingForm())
{
@Html.RadioButtonFor(m=>m.Emp_Gender,"Male")Male
@Html.RadioButtonFor(m=>m.Emp_Gender,"Female")Female
}

1 个答案:

答案 0 :(得分:0)

剃刀:

@Html.RadioButtonFor(m=>m.Emp_Gender,"Male", new { @class = "male"})Male
@Html.RadioButtonFor(m=>m.Emp_Gender,"Female", new { @class = "female"})Female

的CSS:

input[type=radio].male {
   width: 150px;
}

input[type=radio].female {
   width: 300px;
}

但是,请记住,浏览器对于单选按钮的样式可能有点挑剔 请查看此链接以获取有关可能的信息:
http://www.456bereastreet.com/lab/styling-form-controls-revisited/radio-button/
(有点过时,但仍然相关)