我正在学习C#,并且对我正在研究的问题有要求。任务状态:
如果数组中的字符串以字母x开头,请用红色文本设置
<p>
元素的样式。
我该怎么做呢? 我了解如何设置
<div>
<p>@word</p>
@if(word.Length <4) <!--anything under 4 char will be known as a short word.-->
{
<p>@word is a short word</p>
}
@elseif(word <!--beginning with c should be red-->) <!-- I don't know if "elseif" is usable or appropriate here-->
{
<p>@word <!-- but you know, in red--></p>
}
</div>
很抱歉,如果有人问过我,我自己搜索却没有找到任何东西。
答案 0 :(得分:0)
我假设您在这里寻求一些CSS建议。样式是使用CSS https://developer.mozilla.org/en-US/docs/Web/CSS/color完成的。您可以设置内联样式,但一般而言,应该始终考虑使用CSS类。
// this normally goes into the `<head>` section of your view
<style type="text/css">
.long-word {
color: red
}
</style>
// ..........................
<div>
<p>@word</p>
@if(word.Length <4) <!--anything under 4 char will be known as a short word.-->
{
<p>@word is a short word</p>
}
@elseif(word.StartsWith("x")) <!-- this is your check-->
{
<p class="long-word">@word</p> <!-- and this is where you apply your style -->
}
</div>