Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

How to place text over a image or shape?

I am trying to place several lines of text over each of the boxes I made. I used the <p> tag but that didn't seem to work. I also need to use several different lines of text not just one line in each box, similar to the boxes on this site-http://www.shreddedacademy.com/instagram. How do I do this? I have attached my code below HTML- div class="box white_box"> <span>IGBODYBUILDINGWORLD</span> <div class="image_holder"> <img src="igbodybuildingworld.jpg" alt="smile"> </div> <div class="bluebox"></div>

    <button>SELECT</button>
</div>

<div class="box white_box">
    <span>ABSMOTIVATION101</span>
    <div class="image_holder"> <img src="absmotivation101.jpg" alt="smile"> </div>
    <div class="bluebox"></div>
    <button>SELECT</button>
</div>

CSS- /padding and borders compensation/ div{ box-sizing: border-box; } /add wrraper for control blocks flow/ .wrapper{ position: relative; width: 1350px; margin: 0 ; text-align: left; }

/*add shared styles for all boxes*/
.box{ 
    position: relative; 
    width: 250px; 
    margin: 0 7px 15px 7px;
    padding: 25px; 
    text-align: center; 
    background: #fff; 
    display: inline-block; 
    vertical-align: top; 
}
/*add styles only for white boxes*/
.white_box{ 
    height: 550px; 
    border: 1px solid #000; 
}
    /*image holder*/
    .image_holder{                      /*instagram image*/
        position: relative; 
        width: 150px; 
        height: 150px; 
        margin:-10px 0 0 0; 
        border: 5px solid #ccc; 
        border-radius: 75px; 
        display: inline-block; 
        overflow: hidden; 
    }
        .image_holder img{ width: 100%; }

/*add styles for button*/
button{ 
    position: absolute;
    width: 200px; margin: 0 0 0 -100px; 
    left: 50%; bottom: 25px; 
    background: #847bf7; 
    border: solid 1px; 
    font-size: 36px; 
}

span{                                               /*instagram name*/
    position: absolute;
    text-align: center;

    bottom: 20px; 
    top: 205px;
    font-size: 15px; 
    font-weight: bold;
}

.bluebox{
     position: relative; 
        width: 248px; 
        height: 289px; 
        margin: 90px 40px 0px -25px; 
        background: #847bf7; 
        display: inline-block; 

}

2 Answers

Steven Parker
Steven Parker
243,656 Points

:point_right: Place your text inside the div that defines the box.

I put multiple paragraphs in the "bluebox" div's and it looked fine to me:

  <div class="bluebox">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate praesentium, voluptatum, provident dolores ab nisi officia voluptatem quos beatae aperiam perferendis voluptates.</p>
    <p>Repudiandae deserunt provident expedita vel omnis, qui ex veritatis. Quas.</p>
  </div>

While I was at it, I added a button hover effect similar to the sample:

button {
  transition: color .5s, background-color .5s;
}
button:hover {
  border-color: black;
  background-color: black;
  color: #847bf7;
}

Thanks for that. How do I position multiple paragraphs in css?