How do I place a background in a container in Bootstrap?

Asked

Viewed 31,765 times

1

I’m trying to put a Background in a Container someone knows how to put or some other solution? I did not put in Body because the image needs to be Responsive.

3 answers

5

You can reference the class container and apply the prowess backgroundin it, for example:

.container {
 background: #DDD;
}

In addition to color, you can apply responsive images, as in the example below:

.container{
background-image: url(caminho da imagem);
background-repeat: no-repeat;
background-size: 100%;
}

Stick to the priority order of your CSS. Usually I work with the raw bootstrap file and an additional CSS. With this, I keep the bootstrap in the original form and I make the changes in another style sheet which I import later the bootstrap. In short, my header looks something like this:

 <link rel="stylesheet" href="~/Content/css/bootstrap.min.css">
 <link rel="stylesheet" href="~/Content/css/Estilo.css">

If you don’t exactly have a CSS organization, the add-on !important, applied post declaration of a property and its value, may come to help. In case, your code could look like this:

.container {
 background: #DDD !important;
}
  • Great explanation but I followed your example and lost all equal image responsiveness happens with the property img-Responsive

  • Too bad! Try with background-size:cover;

2

try like this:
.container { background-image: url(img/sua_imagem.png); background-repeat: repeat; }

in this case it would be a bg of a uniform tone, if it is an image ex: photograph, engraving, landscape no longer serve. tbm don’t forget the ! value at the end of the attributes

  • what the ! Important does ?

  • ! Important overrides the value set for the same property elsewhere in the code. That is, if in div class you test the color is red and then in div class you test elsewhere in the code the color is blue, you can define with ! Which of the two will be the priority value for the property in question

  • it enforces the rule, so that it is accepted in the interpretation of the browser

1

try it:

background-image: url("caminho da imagem"); 
background-repeat: no-repeat;
background-size: cover;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.