簡體   English   中英

將圖像與文本右側對齊

[英]Aligning an image to the right of text

我想將此圖像與文本的右側對齊,但我無法做到這一點。 我嘗試了所有方法,但最后,圖像出現在文本下方,與我實際想要的相反。

在我的假設中,我編寫了正確的代碼。

請在此處查看圖片。

圖片

這是我的代碼中的內容:

    <!--Intro Page start-->

        <section id="intro">
            <div class="wrapper">

                <div class="intro-left">
                    <h1>Creative Insights to Grow your Business</h1>
                    <p>The world's most widely deployed real-time content recomendations engine. Brought to you by Pulse Analytics.</p>
                    <a href="#" class="intro-cta">
                        Try it for Free
                    </a>
                </div>

                <div class="intro-right">
                    <img src="images/undraw_growth_analytics_8btt.png" alt="">
                </div>
            </div>
        </section>

這是 CSS:

#intro{
    position: absolute;
    overflow: hidden;
    min-height: 600px;
    padding-top: 9em;
}

#intro .intro-left{
    display: inline-block;
    width: 100%;
    max-width: 400px;
    padding: 3em 0;
}

#intro .intro-left h1{
    font-size: 2.5em;
    color: #241b57;
    line-height: 1.5em;
    position: relative;
    margin-bottom: 1em;
}

#intro .intro-left h1::after{
    bottom: -24px;
    left: 0;
    width: 50px;
    height: 4px;
    content: '';
    border-radius: 5px;
    background: #ec4357;
    opacity: 0.4;
    position: absolute;
}

#intro .intro-left p{
    font-size: 1.125em;
    line-height: 1.75em;
}

#intro .intro-left a.intro-cta{
    font-weight: 500;
    display: block;
    width: 100%;
    max-width: 180px;
    margin-top: 2em;
    text-align: center;
    color: #ffffff;
    border-radius: 3px;
    background-color: #ec4357;
    padding: 1em;
}

#intro .intro-right{
    position: relative;
    display: inline-block;
    margin-left: 6em;
}

#intro .intro-right img{
    max-width: 600px;
}

請讓我知道我的錯誤在哪里。 謝謝!

使用flex wrapper class:

 #intro { position: absolute; overflow: hidden; min-height: 600px; padding-top: 9em; }.wrapper { display: flex; } #intro.intro-left { display: inline-block; width: 100%; max-width: 400px; padding: 3em 0; } #intro.intro-left h1 { font-size: 2.5em; color: #241b57; line-height: 1.5em; position: relative; margin-bottom: 1em; } #intro.intro-left h1::after { bottom: -24px; left: 0; width: 50px; height: 4px; content: ''; border-radius: 5px; background: #ec4357; opacity: 0.4; position: absolute; } #intro.intro-left p { font-size: 1.125em; line-height: 1.75em; } #intro.intro-left a.intro-cta { font-weight: 500; display: block; width: 100%; max-width: 180px; margin-top: 2em; text-align: center; color: #ffffff; border-radius: 3px; background-color: #ec4357; padding: 1em; } #intro.intro-right { position: relative; display: inline-block; margin-left: 6em; } #intro.intro-right img { max-width: 600px; }
 <section id="intro"> <div class="wrapper"> <div class="intro-left"> <h1>Creative Insights to Grow your Business</h1> <p>The world's most widely deployed real-time content recomendations engine. Brought to you by Pulse Analytics.</p> <a href="#" class="intro-cta"> Try it for Free </a> </div> <div class="intro-right"> <img src="http://placekitten.com/301/301" alt=""> </div> </div> </section>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM