How to the logo remain in the same position if i modified the margin

35 views Asked by At

I have a logo behind a text and everytime i modified a margin from another div it's change the position. First is from PUG and 2nd is from css

.column(span="row")    
    h1.first-title Bmw M4 
    img(src="asset/image/M-emblem.png", alt="").icon__M 

img.icon__M{
        max-width: 80px;
        height: auto;
        position: absolute;
        z-index: 0;
        right: 107px;
        top: 177px;
    }

I used it the position absolute for icon and relative for the div and z-index to place logo behind the text

1

There are 1 answers

3
avia On

Are you looking for something like this?

I use flexbox display to center the H1 text and background-image to add the logo.

.c {
  background-image:url('https://www.gamasutra.com/db_area/images/news/2018/Jun/320213/supermario64thumb1.jpg');
    background-position:center center;
  background-repeat:no;
  background-size:cover;
    height:200px;
    width:200px;
  display:flex;align-items:center;justify-content:center;
}
<div class="c">
  <h1>BMW X4</h1>
</div>

Codepen: https://codepen.io/larrytherabbit/pen/gOMaBYy