I have a problem with a CSS background image that will not show, can anyone se why it will not show the image? i cant figure it out myself.
<!-- Section: services -->
<section id="service" class="home-section text-center bg-gray">
<div class="heading-about">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="wow bounceInDown" data-wow-delay="0.4s">
<div class="section-heading">
<h2>SCHEMA!</h2>
<i class="fa fa-2x fa-angle-down"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<br>TEST<br>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- /Section: services -->
.service {
width:100%;
position:relative;
background: url(../img/bg2.jpg) no-repeat top center;
}
emmanuel
9,61310 gold badges27 silver badges38 bronze badges
3 Answers 3
You want to use #service when referring to ID's of elements.
#service {
width:100%;
position:relative;
background: url(../img/bg2.jpg) no-repeat top center;
}
A good guide on css selectors can be found here.
answered Feb 16, 2015 at 21:26
user2010925
Sign up to request clarification or add additional context in comments.
3 Comments
arkascha
There are better sources than w3schools of all things (also called "w3fools" for a purpose), but your answer is better than mine because of adding a link. Well done!
arkascha
Oh, that is no hatred! It is just that they are imprecise and outdated sometimes which can lead to great confusion. I would recommend MDN instead: developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/… Well written, precise and cross browser.
You define the top level element as:
<section id="service" class="home-section text-center bg-gray">
So you give it the id "service", not the class.
Therefore your css should be:
#service {
width:100%;
position:relative;
background: url(../img/bg2.jpg) no-repeat top center;
}
Note the leading # instead of the ..
answered Feb 16, 2015 at 21:26
arkascha
43.2k8 gold badges61 silver badges97 bronze badges
Comments
In my opinion in your CSS you refer to class ".service{..." instead of a id of section element. So you have to use "#service{..." instead of ".service {..."
Comments
lang-html
.servicemust be#servicesince service is an ID not a classname