英文:
How can I change background color of razor syntax in cshtml
问题
我想更改cshtml内的razor代码的背景颜色,以便在滚动时更快地识别它。我想更改整个文本,不仅仅是@。
如何做到这一点?
英文:
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?
答案1
得分: 0
我终于解决了我的问题。我去到工具>选项>文本编辑器>HTML>高级,将传统剃刀编辑器更改为true。现在我得到了我想要的。
英文:
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.
答案2
得分: -1
你可以使用 JavaScript 来更改背景颜色。
@model MyViewModel
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>My Page</title>
<style>
body {
background-color: white;
}
#content {
/* 这里是您的内容样式 */
}
</style>
</head>
<body>
<div id="content">
<!-- 这里是您的动态内容 -->
</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>
使用 Razor 语法生成页面的 HTML 和 CSS,包括一个用于动态内容的 #content div。然后,我们在页面底部添加一个 JavaScript 块,监听 "scroll" 事件并相应地更新 #content div 的背景颜色。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论