skip to Main Content

I want to change the background color of razor code inside cshtml to recognize it faster when I’m scrolling. I want to change whole text not only @.
How can I do that?
enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I finally solve my issue. I went to tools>options>Text Editor>HTML>Advanced and turn legacy razor editor to true. Now I have what I want. enter image description here


  2. You can use javascript to change the background color.

     @model MyViewModel
    
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>My Page</title>
        <style>
            body {
                background-color: white;
            }
            
            #content {
                /* your content styles here */
            }
        </style>
    </head>
    <body>
        <div id="content">
            <!-- your dynamic content here -->
        </div>
        
        <script>
            const content = document.getElementById("content");
            
            window.addEventListener("scroll", function() {
                if (window.pageYOffset > 0) {
                    content.style.backgroundColor = "lightblue";
                } else {
                    content.style.backgroundColor = "white";
                }
            });
        </script>
    </body>
    </html>
    

    use Razor syntax to generate the HTML and CSS for the page, including a #content div for our dynamic content. Then, we add a JavaScript block to the bottom of the page that listens for the "scroll" event and updates the background color of the #content div accordingly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search