Search code examples
htmlimagecontainersalignmentdivide

How to align my image half way outside of div container?


is it possible to have my image positioned half-way out of div edge? (similar to the right-side in example code). And needs to be done, with only html align function?

body {
    background-color: #6B6B6B;
    margin: 50px;
    
    font-family: Arial;
    color: white;
    font-size: 14px;
}
<div align="left" style="height:50px;width:70px;background:rgba(0, 0, 0, .4);"><img src="http://wizzfree.com/pix/smiley2.png" width="32"></div><p></p>
<div style="height:50px;width:70px;background:rgba(0, 0, 0, .4);"><img src="http://wizzfree.com/pix/button6.png" width="90"></div>

<p>button outside to right abit<p>need to create similar effect on leftside</p>of simley icon above!

enter image description hereHow can I possibly get this to work?? any suggestions or ideas would be very helpful to me. Thx yummi


Solution

  • Step: 1

    Just add margin-left to your image

    body {
        background-color: #6B6B6B;
        margin: 50px;
        
        font-family: Arial;
        color: white;
        font-size: 14px;
    }
    <div align="left" style="height:50px;width:70px;background:rgba(0, 0, 0, .4);"><img src="http://wizzfree.com/pix/smiley2.png" style="    margin-left: -38px;" width="38"></div><p></p>
    <div style="height:50px;width:70px;background:rgba(0, 0, 0, .4);"><img src="http://wizzfree.com/pix/button6.png" width="90"></div>
    
    <p>button outside to right abit<p>need to create similar effect on leftside</p>

    Step: 2

    You can put that div and image into a mother div, and in that mother div you can add display flex

    body {
            background-color: #6B6B6B;
            margin: 50px;
            
            font-family: Arial;
            color: white;
            font-size: 14px;
        }
    <div style="display: flex">
          <img src="http://wizzfree.com/pix/smiley2.png" style="    margin-left: -38px;" width="38">
          <div align="left" style="height:50px;width:70px;background:rgba(0, 0, 0, .4);"></div>
    </div>