0

I have a quote that I would like to integrate into my website. enter image description here I've tried to place the quote picture before, but as soon as I zoomed out, the quote picture didn't stay in the same place. enter image description here I used the position : absolute.

This is my script :

div#quote-layer {
    background-color: rgba(255,255,255,0.25);
    margin-top: 0px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 0px;
    padding : 25px;
    width: 450px;
}

div#open-quote {position: absolute;
    left: 666px;
    top: 600px;
}

div#quote-layer p {
    text-align: center;
}
    <div id="quote-layer">
        <div id="open-quote">
            <img src="img/quotes.svg" width="100" height="100">
        </div>
        <p>
            my extremely beautiful quote !
        </p>
    </div>

I would find a better way to do it ! Thanks !

2 Answers2

0

This is how we do such things in CSS:

div#quote-layer {
    position: relative; // this is important change here
}

div#open-quote {
    position: absolute;
    left: -30px;
    top: -30px;
}

You can safely tweak the pixels to fit your needs. You could also remove the <div> wrapping the <img> and give the #open-quote id directly to the <img> instead, because that div does nothing for you in this example. If you want to understand how these things work, I would recommend this article: https://internetingishard.com/html-and-css/advanced-positioning/

ajobi
  • 2,996
  • 3
  • 13
  • 28
0

Also I would use ::before selector.

div#quote-layer {
    background-color: rgba(255,255,255,0.25);
    margin-top: 0px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 0px;
    padding : 25px;
    width: 450px;
}

div#quote-layer p {
    text-align: center;
}

div#quote-layer p::before {
    background-image: url("https://cdn2.iconfinder.com/data/icons/web-kit-2/64/web_quote-512.png");
    background-repeat: no-repeat;
    background-size: 20px 20px;
    display: inline-block;
    width: 20px; 
    height: 20px;
    content:"";    
}
<div id="quote-layer">
  <p>
    my extremely beautiful quote !
  </p>
</div>
Void Spirit
  • 879
  • 6
  • 18