htmlcssresponsivestylingcascade

How do i nudge an image up to show center of image in div?


To whom who can help,

I used this answer here (Get div to shrink with image inside of it) originally to figure out the main issue, but now I want to be abke to nudge the image up to show the center of the image. I was doing this originally with my original code by using bottom: 100px, but the SO answer i found does not allow bottom to work. I have also tried margin bottom to see if that would work, but no luck. Can anyone help?

.recentWorkContent div {

    display: inline-block;
    overflow: hidden;
    max-width: 1100px;
    max-height: 300px;
}
.recentWorkContent img {

    position: relative;
    display: block;
    top: 0;
    left: 0;
    width: 100%;
}

HTML

// IMGS:
import capeCod from '../../imgs/morningMode.png'
import CBMediaLogo from '../../imgs/CBMedia_White.png'

// CSS:
import styles from './RecentWork.module.css'

// SKILLS: 
export default function RecentWork() {
    return (
        <div>
            <div className={styles.recentWorkHeaderBox}>
                <h1>Recent Work</h1> 
            </div>

            <section className={styles.recentWorkMain}>
                <div className={styles.recentWorkContent}> 
                    <div>
                        <img src={capeCod} alt="" srcset="" />
                        <div className={styles.imageOverlay}>
                            <div>
                                <div>
                                    <h2>Title</h2>
                                    <p>this is the text.</p>
                                    
                                </div>
                                <div>
                                    <img className={styles.logo} src={CBMediaLogo} alt="" srcset="" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div>
                        <img src={capeCod} alt="" srcset="" />
                    </div>
                    <div>
                        <img src={capeCod} alt="" srcset="" />
                    </div>
                </div>
                <button>View More</button>
            </section>

        </div>
    )
}


Solution

  • If I understood correctly and you are trying to move the image upwards then you can use transfrom:translate(x,y) in the css file.

    So your code might look something like:

    .recentWorkContent img {
        position: relative;
        transform: translate(0px, -10px);
        display: block;
        width: 100%;
    }
    

    this will move the image 10 pixels upwards. Hope this helps.