Difficulty Positioning Background Image

Asked

Viewed 44 times

0

[![insert the image description here][1][1]Gentlemen(as), I am trying to position an image to the background of my project, but when using the cover the same cuts the bottom, and when I use any other form it replicates the image and 4 squares, as attached below, could give me a light on how to adjust this problem ?

 width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
.jumbo {
	background-image: url(../Images/metaVendedores.png");
	background-size: cover;
}
.container {
  width: 90%;
  margin: 0 auto;
  box-sizing: border-box;
  border: 1px solid red;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 1rem;
}
.box {
  width: calc(50% - 2rem);
  height: 2rem;
  margin: 1.5em 1em;
  box-sizing: border-box;
  border: 1px solid black;
  display: flex;
}
.p1, .p2, .p3 {
  display: flex;
  align-items: center;
  justify-content: center;
  color: red;
  font-family: sans-serif;
  font-weight: bold;
  background-color: #ffffff;
}
.p1 {
  flex-grow: 3;
}
.p2 {
  flex-grow: 2;
  background-color: red;
  color: #fff;
  position: relative;
}
.p3 {
  flex-grow: 1;
}
.p2::after {
  content: "texto";
  width: 100%;
  height: 1.5em;
  position: absolute;
  top: -1.5em;
  left: 0;
  background-color: red;
  line-height: 1.5em;
  text-align: center;
  box-shadow: inset 0 0 0.2em rgba(0, 0, 0, 0.5);
}
<div class="jumbo">

  <div class="container">

    <div class="box">

      <div class="p1">
        <c:out value="${VN1.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN1.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN1.rows[0].ACUMULADO}" />%
      </div>
    </div>

    <div class="box">
      <div class="p1">
        <c:out value="${VN2.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN2.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN2.rows[0].ACUMULADO}" />%
      </div>
    </div>

    <div class="box">
      <div class="p1">
        <c:out value="${VN3.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN3.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN3.rows[0].ACUMULADO}" />%
      </div>
    </div>

    <div class="box">
      <div class="p1">
        <c:out value="${VN4.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN4.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN4.rows[0].ACUMULADO}" />%
      </div>
    </div>

    <div class="box">
      <div class="p1">
        <c:out value="${VN5.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN5.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN5.rows[0].ACUMULADO}" />
		</div>
      </div>
    </div>
  </div>

[![Cut image[! [][1]][2]][2]][3]

  • 1

    Gabriel on the picture repeat 4x, just vc put background-repeat: no-repeat; that solve. But about embedding the image in the container you have to use the background-size properties, here’s a link uqe will help you understand how it works https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Scaling_background_images

  • 1

    You can also try to adjust as the background-position to get better alignment, the ideal and use together with bg-size in your case. Here is a link to help you tb https://developer.mozilla.org/en-US/docs/Web/CSS/background-position

  • @hugocsl, I’ll check those papers, thank you. Referring to the image, even adding the no-repeat, it does not repeat, and is only in one of the squares, as image above that I just added.

  • 1

    Here is the documentation on Repeat, make sure you haven’t missed anything in your code: https://developer.mozilla.org/pt-PT/docs/Web/CSS/background-repeat

1 answer

1

Try the following:

.jumbo{  
  background-image: url(../Images/metaVendedores.png");  
  background-repeat: no-repeat;  <--não repete a imagem
  background-position: 0% 0%; <-- Posição da imagem
  background-size: 100% 100%; <--tamanho da imagem
}

can try that way too:

.jumbo{
    background: rgba(0, 0, 0, 0) url(../Images/metaVendedores.png") no-repeat scroll center center / cover;
}

Below follows a snippet with its changed code:

 width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

.jumbo{
    background: rgba(0, 0, 0, 0) url('https://i.stack.imgur.com/Cg2MS.png') no-repeat scroll center center / cover;
}

.container {
  width: 90%;
  margin: 0 auto;
  box-sizing: border-box;
  border: 1px solid red;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 1rem;
}
.box {
  width: calc(50% - 2rem);
  height: 2rem;
  margin: 1.5em 1em;
  box-sizing: border-box;
  border: 1px solid black;
  display: flex;
}
.p1, .p2, .p3 {
  display: flex;
  align-items: center;
  justify-content: center;
  color: red;
  font-family: sans-serif;
  font-weight: bold;
  background-color: #ffffff;
}
.p1 {
  flex-grow: 3;
}
.p2 {
  flex-grow: 2;
  background-color: red;
  color: #fff;
  position: relative;
}
.p3 {
  flex-grow: 1;
}
.p2::after {
  content: "texto";
  width: 100%;
  height: 1.5em;
  position: absolute;
  top: -1.5em;
  left: 0;
  background-color: red;
  line-height: 1.5em;
  text-align: center;
  box-shadow: inset 0 0 0.2em rgba(0, 0, 0, 0.5);
}
<div class="jumbo">

  <div class="container">

    <div class="box">

      <div class="p1">
        <c:out value="${VN1.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN1.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN1.rows[0].ACUMULADO}" />%
      </div>
    </div>

    <div class="box">
      <div class="p1">
        <c:out value="${VN2.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN2.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN2.rows[0].ACUMULADO}" />%
      </div>
    </div>

    <div class="box">
      <div class="p1">
        <c:out value="${VN3.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN3.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN3.rows[0].ACUMULADO}" />%
      </div>
    </div>

    <div class="box">
      <div class="p1">
        <c:out value="${VN4.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN4.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN4.rows[0].ACUMULADO}" />%
      </div>
    </div>

    <div class="box">
      <div class="p1">
        <c:out value="${VN5.rows[0].FUNCIONARIO}" />
      </div>
      <div class="p2">
        <fmt:formatNumber value="${VN5.rows[0].META}" type="currency" />
      </div>
      <div class="p3">
        <c:out value="${VN5.rows[0].ACUMULADO}" />
		</div>
      </div>
    </div>
  </div>

Browser other questions tagged

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