Tehreem Zafar
Tehreem Zafar

Reputation: 9

Aligning an image to the right of text

I want to align this image to the right side of the text but I am unable to do this. All the ways I have tried but in the end, the image appears below the text contrary to what I want actually.

In my assumption, I have written the correct code.

Please see the image here.

image

Here is what I have in my code:

    <!--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>

And here is the 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;
}

Please let me know where is my error. Thanks!

Upvotes: 0

Views: 68

Answers (1)

Manjuboyz
Manjuboyz

Reputation: 7066

use flex for 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>

Upvotes: 1

Related Questions