Skip to content

Instantly share code, notes, and snippets.

@vxhviet
Last active January 24, 2019 07:32
Show Gist options
  • Save vxhviet/f9e524470319fa5b35bfd8056c5f2609 to your computer and use it in GitHub Desktop.
Save vxhviet/f9e524470319fa5b35bfd8056c5f2609 to your computer and use it in GitHub Desktop.

How to Change Position of background-color

SOURCE, SOURCE, SOURCE

Actually you can't change the position of a background-color, instead we need to use a trick to create a background-image with solid gradient and position that instead.

Here is the example of a div that have color background fill up and leave around 100px at the bottom unfilled.

<div class="jio-block">
    ...
</div>
<img id="background-bottom" src="{{cdn_url}}assets/images/meet-doctors-background-bottom.svg"/>
.jio-block {
    background-image: linear-gradient(#F3F8FF, #F3F8FF);
    background-position: 0 -100px;
    background-repeat: no-repeat;
}

// Extra, use another div with image to cover for that 100px space
#background-bottom {
    width: 100%;
    height: 150px;
    margin-top: -100px;
    position: relative;
    z-index: -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment