My CSS disappears when using an ASP.Net MVC form

Unable to find any similar issue on Google... seeking some assistance.

When I apply CSS formatting to style my form as desired, it displays correctly on the page without any issues.

However...

When I place the actual form within the following code snippet, it loses its CSS styling.

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <FORM HTML HERE>
}

Does anyone have an idea of what might be causing this issue?

Appreciate the help in advance.

HTML :

  <form class="form-signin">
    <h2 class="form-signin-heading">Please sign in</h2>
    <input type="text" class="input-block-level" placeholder="Email address">
    <input type="password" class="input-block-level" placeholder="Password">
    <label class="checkbox">
      <input type="checkbox" value="remember-me"> Remember me
    </label>
    <button class="btn btn-large btn-primary" type="submit">Sign in</button>
  </form>

CSS :

.form-signin {
    max-width: 300px;
    padding: 19px 29px 29px;
    margin: 0 auto 20px;
    background-color: #fff;
    border: 1px solid #e5e5e5;
    -webkit-border-radius: 5px;
       -moz-border-radius: 5px;
            border-radius: 5px;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
       -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
            box-shadow: 0 1px 2px rgba(0,0,0,.05);
  }
  .form-signin .form-signin-heading,
  .form-signin .checkbox {
    margin-bottom: 10px;
  }
  .form-signin input[type="text"],
  .form-signin input[type="password"] {
    font-size: 16px;
    height: auto;
    margin-bottom: 15px;
    padding: 7px 9px;
  }

Answer №1

@using (Html.BeginForm()) generates a <form> tag on the page.

In case you are attempting to nest one form within another, the second <form> will be disregarded by the browser (refer to this thread: https://example.com/a/123456).

To include your desired class while creating the form, you can do so like this:

@Html.BeginForm({Action}, {controller}, FormMethod.Post, new { @class = "YourClass" })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that all elements are consistently kept within a DIV container

In my experience with web development, one recurring challenge is ensuring that everything stays contained within a div element. I often encounter situations where multiple nested divs and content cause styling nightmares when elements bleed out of their d ...

Canvg | Is there a way to customize canvas elements while converting from SVG?

Recently, I encountered an issue with styling SVG graphics dynamically generated from data. The SVG graphic appears like this: https://i.sstatic.net/xvIpE.png To address the problem, I turned to Canvg in hopes of converting the SVG into an image or PDF us ...

Dynamic row height in MUI DataGrid

I'm currently utilizing the MUI DataGrid component, and I have a specific behavior in mind that I'd like to achieve: When there is a small number of rows present, I want the table to only occupy the necessary space for those rows. On the other h ...

Scrolling to the complete height of a div using scrollTop

Experience an automated scroll to the bottom of the div, followed by a smooth upward motion over 5 seconds, all while looping seamlessly. A small issue arises where the code only recognizes the standard height set for the div, not its actual scrollable he ...

Centralized and secure masthead

Currently, I am focusing on showcasing my portfolio at www.bbellmedia.com/mywork The specific requirement I have is to center the text 'Bryan Bell' and ensure that it remains fixed even when the user scrolls. Can anyone suggest the most effecti ...

presentation banner that doesn't rely on flash technology

Looking to create a dynamic slideshow banner for my website inspired by the design on play.com. This banner will feature 5 different slides that transition automatically after a set time, while also allowing users to manually navigate using numbered button ...

JavaScript encountered a problem when trying to call the inline function

I created a function called controls that adds HTML elements dynamically into the specified div. function controls() { var block = $('#controls'); block.html(''); block.append('<button type="button" onClick="f ...

Harness the power of multiple backgrounds with just one CSS style!

I'm exploring a way to incorporate multiple images as backgrounds into my website design. For instance, having a car image on the index page and a notepad image on the about me page. My attempt involved using the following code: body { back ...

Why @font-face doesn't display on older versions of Internet Explorer like IE 7 and IE

Our website has the following CSS code. The use of a smiley face is to ensure compatibility with IE 7 and IE 8. However, while the site's fonts display correctly on IE 9, Chrome, Firefox, etc., there seems to be an issue with IE 7 and 8. @font-face { ...

How can I set up a cycling image background for the main div and a floating menu?

I was wondering how I could keep a cycling image background stationary behind the main content while scrolling through the page. You can check out the project itself by following this link. Feel free to use any of the code, including the fixed header menu, ...

Unable to display favicon when using the include function

How can I add the favicon link to my website? In my header.php, I have added the link for my ico favicon, but when I try to include it in my index file, the favicon does not show up. I attempted to insert the favicon code directly into the index.php file, ...

Update the database with the new values and display them in an HTML table

I am working with a table that looks like the one below: <script> $("#edit").hide(); // Initially hide the edit table $("#update").click(function() { $("#edit").toggle(); $("#shown").toggle(); ...

Can AngularJS routes be defined with templateUrl paths that are completely independent of the IIS app's folder structure?

I have been conducting research both here and in general, but so far, I haven't found a suitable way to implement this. Our web application uses MVC/WebAPI2/AngularJS. The goal I'm aiming for is to be able to place my app anywhere within the II ...

View the picture directly on this page

Currently, I am in the process of creating a gallery and I would like the images to open on top of everything in their original size when clicked by the user. My expertise lies in HTML and CSS at the moment, but I am open to learning JavaScript and jQuery ...

The presence of Null is detected during the HTML parsing process

I'm in the process of developing dynamic HTML pages using JSON data. Each time the application encounters a special identifier like #@, it gets replaced by a specific value. However, upon loading my page, I noticed that a null is being printed at the ...

Experience the feeling of releasing momentum by click and dragging the scroll

One feature I am looking for is the ability to control the scroll speed when dragging, and have the scroll continue moving slightly after release instead of stopping instantly. CodePen: https://codepen.io/rKaiser/pen/qGomdR I can adjust the speed adequat ...

Data is nowhere to be found despite using the post method, but the URL still contains valuable information

Recently, I've delved into the world of PHP and have been experimenting with HTML forms. Initially, I used the method GET which worked perfectly fine. However, when I switched to using the method POST, I encountered an issue where I couldn't retr ...

Using Ajax to implement a content slider with lightSlider

Seeking assistance in developing a dynamic content slider utilizing the LightSlider plugin. Currently, I have a script that fetches content from a database table (outputting JSON to HTML) and displays 6 div's of content per slide. However, I aim to di ...

Are there any tools you rely on for speeding up the process of developing html/css?

Have you heard of zen-coding? It's a script that generates markup based on a css-esque selector like this: div#foo > p*6 This code would generate: <div id="foo"> <p></p> <p></p> <p></p> & ...

When floating a heading 4 (h4) and two divs to the left, and a single div to the right,

When floating a h4 and 2 divs to the left, and another div to the right, how can I place a block inside the remaining space that perfectly fills it? The background color of this space should not spread outside. [h4][div][div][remaining space][div] Thank ...