在CSS中动态设置div高度

时间:2019-08-05 14:27:48

标签: html css

我的CSS中包含以下代码:

[HttpPost]
        public async Task<ActionResult> Comments(string email, string captcha, string regarding, string comment)
        {
            var clientIp = Request.UserHostAddress;
            var token = captcha;
            var secret = "xxxxxxxxx";
            var captchaApi = new ReCaptchaService();
            var results = await captchaApi.Verify3Async(token, clientIp, secret);

            if (IsValidEmail(email) && (!results.IsSuccess || results.Score < 0.5 || results.Action != "xxxxxx"))
            {
                ErrorViewModel eVm = new ErrorViewModel
                {
                    message = "\"" + email + "\" is not a valid email address.",
                    bShowBackButton = true
                };
                return View("Error", eVm);
            }

是否可以动态设置,这样,如果我将类System.ArgumentException: The client response must not be null or empty Parameter name: siteSecret at BitArmory.ReCaptcha.ReCaptchaService.<Verify3Async>d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at BootstrappingMVC.Controllers.SiteController.<Comments>d__37.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) 放在div中,它现在具有高度150px


一种实现此目的的方法是为每个可能的高度值创建一个类,但是我想知道是否有更好的方法。

感谢您的关注。

1 个答案:

答案 0 :(得分:2)

您可以尝试使用scss / sass来创建函数来为您生成类:

div{
  @for $j from 1 through 200 {
        &.h#{$j}{
            height: ($j + px);
        }
    }
 }