- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在下面的 anchor 标记水平列表中得到了额外的空白字符。这对我来说是一个主要的 CSS 样式问题。
我知道就 C# 解决方法而言,这个问题已得到解决 (asp.net mvc razor extra space),但有人可以帮我解决 VB 解决方法吗?我没有花括号的优势来消除单行 If 条件中的所有空格。
我现在已经设法通过编写一个 HtmlHelper 扩展方法来解决这个问题,但是这个动态代码只用在一个地方(主布局页面)。在我看来,这确实应该在 .vbhtml 页面中完成。也欢迎任何反对此意见的论点。
这是错误的代码,以及已注释掉的解决方法。目标是创建一个基于站点地图的“同级”页面的水平列表,当前页面的链接和它之前的链接的样式略有不同。
@If Not (SiteMap.CurrentNode Is Nothing OrElse SiteMap.CurrentNode.ParentNode Is Nothing OrElse SiteMap.CurrentNode.ParentNode.ChildNodes.Count = 0) Then
@<div id="contentPageMenu">
@For Each childNode As SiteMapNode In SiteMap.CurrentNode.ParentNode.ChildNodes
@* GENERATES AN EXTRA SPACE BETWEEN EVERY a TAG! *@
If childNode Is SiteMap.CurrentNode Then
@<a class="top_menu_button top_menu_button_selected" href="@childNode.Url">@Trim(childNode.Title)</a>
ElseIf childNode.NextSibling Is SiteMap.CurrentNode Then
@<a class="top_menu_button top_menu_button_before_selected" href="@childNode.Url">@Trim(childNode.Title)</a>
Else
@<a class="top_menu_button" href="@childNode.Url">@Trim(childNode.Title)</a>
End If
@*
STILL GENERATES EXTRA WHITESPACE!
If childNode Is SiteMap.CurrentNode Then @<a class="top_menu_button top_menu_button_selected" href="@childNode.Url">@Trim(childNode.Title)</a>ElseIf childNode.NextSibling Is SiteMap.CurrentNode Then @<a class="top_menu_button top_menu_button_pre_selected" href="@childNode.Url">@Trim(childNode.Title)</a>Else @<a class="top_menu_button" href="@childNode.Url">@Trim(childNode.Title)</a>End If
*@
@*
CAN'T PARSE a OR If STATEMENTS!
@<a class=@If childNode Is SiteMap.CurrentNode Then @<text>"top_menu_button top_menu_button_selected"</text> ElseIf childNode.NextSibling Is SiteMap.CurrentNode Then @<text>"top_menu_button top_menu_button_pre_selected"</text> Else @<text>"top_menu_button"</text> End If@<text> href="</text>@childNode.Url@<text>"></text>@Trim(childNode.Title)@</a>
*@
Next
</div>
End If
附言- 我知道我仍然需要处理 MVC 的“规范 URL”问题,但这超出了这个问题的范围。
这是问题的可视化示例。箭头是位于右上角的背景图片。
这是用于设置这些按钮样式的 CSS:
a.top_menu_button
{
background: url(../Images/top_menu_separator.gif) no-repeat right top #01376a;
color: #ffffff;
display: inline-block;
font-family: inherit;
font-size: 1.0em;
font-weight: bolder;
height: 20px;
margin: 0;
padding: 2px 15px 2px 10px;
position: relative;
text-decoration: none;
top: 0;
white-space: nowrap;
}
a.top_menu_button:hover
{
font-family: inherit;
font-style: italic;
}
a.top_menu_button_before_selected
{
background: url(../Images/top_menu_separator_before_selected.gif) no-repeat right top #01376a;
}
a.top_menu_button_selected
{
background: url(../Images/top_menu_separator_after_selected.gif) no-repeat right top #b9aa64;
color: #01376a;
font-family: inherit;
font-style: italic;
}
最佳答案
尝试将@Code/@End 代码块与@: 转义符一起使用。此外,如果您为使用 If/Then/Else 逻辑确定的事物创建一个变量,它可能更具可读性。
@Code
If Not (SiteMap.CurrentNode Is Nothing OrElse SiteMap.CurrentNode.ParentNode Is Nothing OrElse SiteMap.CurrentNode.ParentNode.ChildNodes.Count = 0) Then
@:<div id="contentPageMenu">
For Each childNode As SiteMapNode In SiteMap.CurrentNode.ParentNode.ChildNodes
Dim aClassValue As String = ""
If childNode Is SiteMap.CurrentNode Then
aClassValue = "top_menu_button top_menu_button_selected"
ElseIf childNode.NextSibling Is SiteMap.CurrentNode Then
aClassValue = "top_menu_button top_menu_button_before_selected"
Else
aClassValue = "top_menu_button"
End If
@:<a class="@aClassValue" href="@childNode.Url">@childNode.Title.Trim()</a>
Next
@:</div>
End If
@End Code
顺便说一下,这是 HTML - 空格应该无关紧要。您确定这真的给您带来了问题吗?
-- 编辑--
现在我看到了您的 CSS,问题就很清楚了。您正在使用 inline-block
,这意味着空白在渲染中很重要,这就是您所发现的。您可以通过多种方式解决此问题,既可以通过 CSS,也可以不在您的 Razor 中。
float: left;
到你的a.top_menu_button
类,这将解决问题。或者……<div id="contentPageMenu">
并给它一个样式 style="word-spacing: -1em"
.然后,添加 word-spacing: 0;
到你的a.top_menu_button
类,这也将解决问题。尝试使用谷歌搜索“显示内联 block 空白”,您将获得多个关于问题和样式解决方法的点击。 This one和 this one两者都对问题和一些解决方法进行了清晰简洁的描述。
关于css - VB - ASP.NET MVC 3 Razor 呈现额外的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6629200/
我有几个问题。我是 Visual Basic 这个领域的新手,所以不要取笑我。 1.) VB.NET之间有什么区别和 VB ? 2.) 我需要为 Windows 开发基本的应用程序。(如记事本)我应该
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我是框架 3.5 的新手。我注意到,在创建 Web 内容表单时,除了 aspx.vb 页面之外,它还会创建一个 aspx.designer.vb 页面。谁能向我解释一下它们之间的区别以及它们的用途吗?
我只是想知道 VB.NET 和 VB 2010 是否相同。 我只是想知道。 最佳答案 VB 2010 是 VB.Net 的最新版本。 Microsoft 在 VB 2005 版本中删除了 VB 的“.
我是框架 3.5 的新手。我注意到,在创建 Web 内容表单时,除了 aspx.vb 页面之外,它还会创建一个 aspx.designer.vb 页面。谁能向我解释一下它们之间的区别以及它们的用途吗?
我正在尝试将 VB 函数移植到 VB.NET,但我无法使该函数正常工作并正确更新。 rFormat = Format(Format(Value, fmt), String$(Len(fmt), "@"
如何在VB中注释多行代码/代码块? 最佳答案 VB 在语言级别上没有这样的构造。它有使用撇号字符的单行注释: ' hello world ' this is a comment Rem this is
我正在使用我在 VB2005 中创建的表单在按下按钮时打开程序,然后在文本字段中显示进程 ID(再次按下按钮时)。当我运行它时,表单将打开程序 (Notepad.exe) 但当我单击按钮查看进程 ID
我正在尝试添加一个从 vb.net 创建的 dll,并且想将其导入到现有的 vb 6 项目中,但它给了我错误“无法添加对指定文件的引用”。 。有人知道如何解决这个问题吗? 最佳答案 需要遵循以下步骤:
我有一个数据 GridView 。右键单击它会显示一个上下文菜单,但它始终位于右上角。我想要它,以便菜单出现在用户右键单击的单元格上。它可能是单元格 1 或单元格 2 或其他。 谢谢福尔坎 最佳答案
我只是在 Visual Studio 2010 中使用 Visual Basic。有人知道我将如何制作“浏览文件夹(或文件)”按钮吗?我对 VB 真的很陌生,我只是在寻找一些简单的帮助:) 最佳答案
这次感到困惑... 最简单的代码行有时可能起作用,有时却没有。首先,我认为问题在于我试图读取DWORD的值,但是由于我可以从某些键读取DWORD值,所以这一定不是问题。现在的问题似乎是,如果 key
我的代码中有此方法: Private Sub Display() Received.AppendText(" - " & RXArray) End Sub 这两个调用之间有什么区别:
我正在创建一个宏程序来记录和回放鼠标和键盘输入。录制效果很好,鼠标播放也一样,但是我在播放键盘输入时遇到了麻烦——特别是在释放之前按住一个键几秒钟。这不等同于重复按键。这是我尝试过的: 技巧 1:Me
我最近刚刚了解了 VB.NET 中静态局部变量的使用,并想知道它在延迟加载属性中的潜在用途。 考虑以下示例代码。 Public Class Foo Implements IFoo End Clas
VB 有一个 C# 没有的特性,在项目级别导入命名空间(我的项目>引用>导入命名空间)。当新人在源代码控制之外检查项目时,我们的自定义导入不包括在内。这个 VB 特定的导入命名空间存储在哪里? 最佳答
我已将我的问题缩小到这个简单的案例,但似乎无法找到发生了什么: 我有两个表单,一个只有一个按钮,另一个是空的。 单击按钮时,form1 隐藏和显示 form2 出现时,form2隐藏,form1再次显
为什么下面的简单代码会失败?无论我使用 LinearGradientMode 的哪个值,这段代码总是用从左到右的渐变填充路径。 graphPath 是在别处创建的 GraphicPath 对象(基本上
我可以多快替换字符串中的字符? 所以这个问题的背景是这样的:我们有几个应用程序通过套接字相互通信并与客户端的应用程序通信。这些套接字消息包含不可打印的字符(例如 chr(0)),需要用预定的字符串(例
如何从任何文件中读取原始字节数组... Dim bytes() as Byte ..然后将该字节数组写回新文件? 我需要它作为一个字节数组来做一些处理。 我目前正在使用: 阅读 Dim fInfo
我是一名优秀的程序员,十分优秀!