I want to add a background image to various sections in my site I am reskinning..
Problem is, the background images are zoomed in.
See below.
Is it better and faster to just create a new css div.. Can someone please advise on the syntax?
// Sections backgrounds
var pageSection = $(".home-section, .page-section, .small-section, .split-section");
pageSection.each(function(indx){
if ($(this).attr("data-background")){
$(this).css("background-image", "url(" + $(this).data("background") + ")");
}
});
css
background-size: cover
or
background-size: 100%
should be your solution.
You can tweak your javascript a bit to class the sections.
var pageSection = $(".home-section, .page-section, .small-section, .split-section");
pageSection.each(function(){
if ($(this).attr("data-background")){
$(this).css("background-image", "url(" + $(this).data("background") + ")");
$(this).addClass('full-background'); //adds the class
}
});
And then style it properly with CSS
.full-background {
background-size: cover;
}
However this is a CSS3 style so be careful of IE8
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.