nth-child(单数)不起作用

时间:2016-03-09 13:32:15

标签: css twitter-bootstrap-3 parent-child

我试图为html中的每个第二个元素创建一些背景颜色,使其与 nth-child(odd)颜色不同,但不知何故它不能正常工作,因为每个孩子都有背景颜色。

这是工作小提琴看到我的问题,因为它有很多HTMl要粘贴:)

https://jsfiddle.net/7xwgszwg/8/

public class IdentityConfig
{
     public void Configuration(IAppBuilder app)
    {
        app.CreatePerOwinContext<AppDBContext>(AppDBContext.Create);
        app.CreatePerOwinContext<AppUserManager>(AppUserManager.Create);
        app.CreatePerOwinContext<AppRoleManager>(AppRoleManager.Create);
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<AppUserManager, AppUser>(
                    validateInterval: TimeSpan.FromMinutes(15),
                    regenerateIdentity: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie))
            },
            CookieName = "MyCookie",
            //CookieDomain = "www.example.com",
            //CookieHttpOnly = true,
            //CookieSecure = CookieSecureOption.Always,
            ExpireTimeSpan = TimeSpan.FromMinutes(double.Parse(ConfigurationManager.AppSettings["app:SessionTimeout"])),
            SlidingExpiration = true
        });
    }
}

2 个答案:

答案 0 :(得分:2)

除了h中缺少nt-child应该是nth-child )之外,问题是.acccesories-description元素不是兄弟姐妹,而且nth-child区分兄弟元素。

您很可能希望将nth-child应用于.accesories-box-main,然后将.acccesories-description定位为着色

.accesories-box-main:nth-child(odd) .acccesories-description{
  background-color:red;
}

https://jsfiddle.net/gaby/7xwgszwg/9/

演示

答案 1 :(得分:0)

你有拼写错误,nth-child()你遗忘了hhttps://jsfiddle.net/7xwgszwg/4/