0

Here is my CSS code:

.TabTop {
background-image: url("https://i.imgur.com/5qOZqaY.png");
width: 1855px;
height: 168px;
background-repeat: no-repeat;
}
.TabMid {
background-image: url("https://i.imgur.com/6uMuiY4.jpg");
width: 1855px;
height: 100%;
background-repeat: repeat-y;
}
.TabBot {
background-image: url("https://i.imgur.com/5Psk33C.png");
width: 1855px;
height: 237px;
}

And here's my HTML code:

<div class="TaTop"></div>
<div class="TabMid"></div>
<div class="TabBot"></div>

Right now it looks like this: https://i.stack.imgur.com/IKtcM.jpg

As you can see on the right there is a gap.

I would like all 3 parts of the image to be centered and resized in width according to the size of the user's computer monitor size.

I also tried background-size: cover it doesn't seem to work.

How could I do that?

2 Answers2

0

Using background-size: cover should do the trick. But it won't give you that much control.

For that you should use Media queries and some more background properties.

@media only screen and (max-width:420px) {     .TabTop {         background-position: center     } }

You could try more media query sizes to get more control on how your image should look on different device.

Here's Media queries guide for more examples.

Priyash
  • 162
  • 2
  • 12
0

you lack a 'b' in Class of 'TabTop' and if you use 100% in Height it usually does not work if the parent has some class that references that value like position:relative.

.TabTop {
background-image: url("https://i.imgur.com/5qOZqaY.png");
width: 1855px;
height: 168px;
background-repeat: no-repeat;
}
.TabMid {
background-image: url("https://i.imgur.com/6uMuiY4.jpg");
width: 1855px;
height: 100vh; /* alternative for % */
background-repeat: repeat-y;
}
.TabBot {
background-image: url("https://i.imgur.com/5Psk33C.png");
width: 1855px;
height: 237px;
}
<div class="TabTop"></div>
<div class="TabMid"></div>
<div class="TabBot"></div>