简体   繁体   中英

CSS background isn't working with nth-child selectors

I'm building a portfolio and I'd like to show one work per section in this page:

http://andreawebdesign.com.br/new/portfolio.html

I wanted to do it with this code:

.container-portfolio section:nth-child(1){
    background-image: url(../images/seu_roque.jpg);background-position: center;background-size:cover; }
}
.container-portfolio section:nth-child(2){
    background-image: url(../images/seu_roque.jpg);background-position: center;background-size:cover; }
}
.container-portfolio section:nth-child(3){
    background-image: url(../images/seu_roque.jpg);background-position: center;background-size:cover; }
}
.container-portfolio section:nth-child(4){
    background-image: url(../images/seu_roque.jpg);background-position: center;background-size:cover; }
}
.container-portfolio section:nth-child(5){
    background-image: url(../images/seu_roque.jpg);background-position: center;background-size:cover; }
}
.container-portfolio section:nth-child(6){
    background-image: url(../images/seu_roque.jpg);background-position: center;background-size:cover; }
}

Of course, the real images will be different, that was just a test. And still, for some reason, the background is shown in the first section, but not in the others. That really confuses me, because I have other codes related to the same sections that are working (just try to mouse over them). I've also tried to call the sections directly by giving each of them a class, but the same error is happening.

Any ideas? Thanks.

It looks like you have an extra closing brace ( } ) on each line that is breaking the CSS.

.container-portfolio section:nth-child(1){
    background-image: url(../images/seu_roque.jpg);background-position: center;background-size:cover; }
}

Image path is not right.

background-image: url(./images/seu_roque.jpg);

Try this it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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