简体   繁体   English

div内的css标题

[英]css headings inside a div

New to css. css 的新手。 I have a div element, in which there are multiple links in it, now I like to apply css to all of the elements inside the div like below:我有一个 div 元素,其中有多个链接,现在我喜欢将 css 应用于 div 内的所有元素,如下所示:

#menu {
    top: 150px;
    left: 650px;
    position: absolute;
    color: #151B54;
    font: 10pt;
    font-family: Arial;
}

However this doesn't seem to be working.但是,这似乎不起作用。

Here is the div:这是div:

    <div id="menu">
        <asp:HyperLink ID="lnk_Home" runat="server"  
        NavigateUrl="~/Default.aspx">  Home  </asp:HyperLink>
    </span>
    &nbsp;&nbsp;<asp:HyperLink ID="HyperLink14" runat="server" NavigateUrl="~/About/About.aspx" 
    Target="_blank">  About  </asp:HyperLink>
&nbsp;
<asp:HyperLink ID="HyperLink16" runat="server" 
    NavigateUrl="~/About/ContactUs.aspx" Target="_blank">  Contact Us  </asp:HyperLink>
<asp:HyperLink ID="HyperLink17" runat="server" 
    NavigateUrl="~/About/FAQ.aspx" Target="_blank">  FAQ  </asp:HyperLink>
    </div>

None of your CSS styles anything inside of the #menu div.The right way would be like this: #menu div 中没有任何 CSS styles 任何东西。正确的方法是这样的:

div#menu {
    position: absolute;
    top: 150px;
    left: 650px;
}

/* "<asp>" isn't a valid HTML element, but I assume that
 * <asp:Hyperlink> actually generates an HTML anchor */

/* Links also have pseudo-elements that represent their
 * valid statuses.*/
div#menu a,
div#menu a:visited,
div#menu a:hover,
div#menu a:active,
div#menu a:focus {
    color: #151B54;
    font: 10pt;
    font-family: Arial;
}

More information about the pseudo-classes mentioned can be found here: http://www.w3.org/TR/CSS21/selector.html#link-pseudo-classes关于所提到的伪类的更多信息可以在这里找到: http://www.w3.org/TR/CSS21/selector.html#link-pseudo-classes

I think you are looking for something like我想你正在寻找类似的东西

#menu asp {
  ...styles...
}

This will target all <asp> tags inside the #menu element.这将针对#menu元素内的所有<asp>标记。 Your current style only targets the #menu element, not any of its children.您当前的样式仅针对#menu元素,而不是它的任何子元素。

(Although the <asp> tag is non-valid, you could substitute any type of element and the concept still applies.) (虽然<asp>标记无效,但您可以替换任何类型的元素,并且该概念仍然适用。)


Also, there's a rogue <span> element in your code, and a lot of &nbsp;此外,您的代码中有一个流氓<span>元素,还有很多&nbsp; where CSS can do the job. CSS 可以完成这项工作。 It should maybe look like this:它应该看起来像这样:

<div id="menu">
  <asp:HyperLink ID="lnk_Home" runat="server" NavigateUrl="~/Default.aspx">
    Home</asp:HyperLink>

  <asp:HyperLink ID="HyperLink14" runat="server" NavigateUrl="~/About/About.aspx" Target="_blank">  
    About</asp:HyperLink>

  <asp:HyperLink ID="HyperLink16" runat="server" NavigateUrl="~/About/ContactUs.aspx" Target="_blank">  
    Contact Us</asp:HyperLink>

  <asp:HyperLink ID="HyperLink17" runat="server" NavigateUrl="~/About/FAQ.aspx" Target="_blank">
    FAQ</asp:HyperLink>
</div>

Not exactly sure what you're asking, as you provided ASP.NET code, but to select elements inside of elements via CSS, you can do it like this:不完全确定您在问什么,因为您提供了 ASP.NET 代码,但是对于通过 CSS 的元素内部的 select 元素,您可以这样做:

#menu your_link {
  /* Styles */
}

If you could provide the generated HTML, that would be nice.如果你能提供生成的 HTML,那就太好了。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM