Search code examples
asp.net-corecolorsbackground-color

adding background colour to webpage


new to ASP.net core, how do I add background colour to the page using the cshtml? I am using the automatically generated page but this is invariable white with black text and it doesn't seem to like the use of inline.


Solution

  • In .net core application,there is a default layout in shared/_layout.cshtml.And each view will use the layout.And in _layout.cshtml,we often reference site.css in <head></head>.So if you want to change the background color of all the pages,you can change the style in site.css.Also, you can change the style in _layout.cshtml by.

    For example,I change the background color of body:

    In site.css:

    body {
      /* Margin bottom by footer height */
      margin-bottom: 60px;
      background-color:red;
    }
    

    In _layout.cshtml:

    <style>
        body {
        background-color:red;
        }
    </style>
    

    Result: enter image description here