简体   繁体   English

元素'div'不能嵌套在元素'ul'中

[英]Element 'div' cannot be nested within element 'ul'

 <ul>
           <div style="float:left">
                   <asp:LinkButton ID="lbtnFirst" runat="server" CausesValidation="false" OnClick="lbtnFirst_Click">İlk</asp:LinkButton></div> 
           <div style="float:left"><asp:LinkButton ID="lbtnPrevious" runat="server" CausesValidation="false" OnClick="lbtnPrevious_Click"> << </asp:LinkButton></div>
</ul>

In my Asp.net project I get this Warning : 在我的Asp.net项目中,我收到此警告:

Validation (XHTML 1.0 Transitional): Element 'div' cannot be nested within element 'ul'. 验证(XHTML 1.0 Transitional):元素'div'不能嵌套在元素'ul'中。

But when I click F5 everthing woks great. 但是,当我点击F5外翻炒锅时很棒。 Now I am working on localhost in Visual Studio 2013 (Code side is C#) I want to ask can this make problem for my site in future ? 现在我正在使用Visual Studio 2013中的localhost(代码端是C#)我想问这可能会在将来为我的网站带来问题吗?

The warning is, well, a warning. 警告是一个警告。 Your page is displayed correctly only because the browser is not too strict on the HTML rules, but that may change in the future. 您的页面显示正确只是因为浏览器对HTML规则不是太严格,但将来可能会更改。 For that reason, you should try to keep your HTML compliant and take the warnings seriously. 因此,您应该尝试保持HTML兼容并严肃对待警告。 In this case, I would suggest to replace the <div> with <li> tags and style them to prevent the margins and bullets (I assume that's why you're using <div> instead of <li> in the first place). 在这种情况下,我建议用<li>标签替换<div>并设置它们以防止边距和子弹(我假设这就是为什么你首先使用<div>而不是<li> )。

To achieve what you want, apply this CSS style to your list: 要实现您的目标,请将此CSS样式应用于您的列表:

.your-ul {
    list-style: none;
}

.your-ul li {
    position:relative;
    margin-left: 0;
    display: inline-block;
}

Your HTML/ASPX code would look like this: 您的HTML / ASPX代码如下所示:

<ul class="your-ul">
    <li><asp:LinkButton ID="lbtnFirst" runat="server" CausesValidation="false" OnClick="lbtnFirst_Click">Ilk</asp:LinkButton></li> 
    <li><asp:LinkButton ID="lbtnPrevious" runat="server" CausesValidation="false" OnClick="lbtnPrevious_Click"> << </asp:LinkButton></li>
</ul>

Normally one would expect a ul element to contain li elements. 通常人们会期望ul元素包含li元素。 It may make sense for the li elements to contain div s but it doesn't make a lot of sense to have div s (or anything else) as immediate children of a ul . li元素包含div可能是有意义的,但将div (或其他任何东西)作为ul直接子ul并没有多大意义。 You could change your div s to li s, perhaps that's what you're looking for? 你可以将你的div改为li s,也许这就是你要找的东西?

You can still use your div tag, it just needs to be wrapped in a li element. 您仍然可以使用div标签,它只需要包含在li元素中。

<ul>
<li>
    <div style="float:left">
        <asp:LinkButton ID="lbtnFirst" runat="server" CausesValidation="false" onClick="lbtnFirst_Click">İlk</asp:LinkButton>
    </div>
    <div style="float:left">
        <asp:LinkButton ID="lbtnPrevious" runat="server" CausesValidation="false" OnClick="lbtnPrevious_Click"> << </asp:LinkButton>
    </div>
</li>

Although, as others have said, you can also just apply the styles directly to li element. 虽然,正如其他人所说,您也可以直接将样式应用于li元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决:“元素div不能嵌套在元素&#39;updatepanel&#39;中” - How to solve : “the element div cannot be nested within the element 'updatepanel' ” 验证(HTML 4.01):元素“样式”不能嵌套在元素“ div”内 - Validation (HTML 4.01): Element 'style' cannot be nested within element 'div' 验证(XHTML 1.0 Transitional):元素&#39;html&#39;不能嵌套在元素&#39;div&#39;中 - Validation (XHTML 1.0 Transitional): Element 'html' cannot be nested within element 'div' Validation(HTML5)元素我不能嵌套在元素按钮内 - Validation(HTML5) The element i cannot be nested within the element button asp.net错误表单不能嵌套在元素表单中? - asp.net error form cannot be nested within element form? ASP.NET RadioButtonList:元素&#39;br&#39;不能嵌套在元素&#39;listitem&#39;中 - ASP.NET RadioButtonList: the element 'br' cannot be nested within the element 'listitem' 单击ImageButton时如何展开/折叠嵌入div元素中的嵌套GridView? - How does one expand/collapse a nested GridView embedded within div element while clicking an ImageButton? <div> 里面的元素 <ul> 元素,IE,ASP.NET Repeater控件中的层次结构已更改 - <div> element inside <ul> element, hierarchy is changed in IE, ASP.NET Repeater control 某个div中的JQuery元素,但结尾为 - JQuery element within a certain div but ending with 无法向包含 SimpleContent 列的表添加嵌套关系或元素列 - Cannot add a nested relation or an element column to a table containing a SimpleContent column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM