Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How could i display text on right side of image? Inline?
Here is my code

XML
<div id="background">

 <img class="image" src="banner.jpg"  />
<div id="text"><p>My text</p></div>

</div>


CSS
#background
{
background-color:rgb(30, 30, 30);


}
.image
{
height:140px;
background-size:cover;
background-position-x:center;
background-position-y:center;
display:block;


}

#text p
{
float:right;
width:210px;
padding:20px;
}
Posted

1 solution

Thing what you can do with your CSS is:
CSS
#background {
    background-color:rgb(30, 30, 30);
    overflow: hidden;
}

.image {
    height:140px;
    background-size:cover;
    background-position-x:center;
    background-position-y:center;
    display:block;
    float: left;
}

#text p {
    width:210px;
    padding:20px;
    float: left;
}


First set float to left to your image and paragraph.
After set background div overflow to hidden.

If you would like to move into the center your div you have to create an inner div like this with a class (in this case called center):
HTML
<div id="background">
    <div class="center">
        <div id="text">
            <p>My text</p>
        </div>
        
        <img class="image" src="banner.jpg" />
    </div>
</div>


And allow the following CSS to center class:
CSS
.center {
    width: 30%;
    margin: 0 auto;
}
 
Share this answer
 
v3
Comments
Kurac1 21-Feb-15 12:36pm    
yes its works but i want to my image and text to be centered right not it gets on left side all?
norbitrial 21-Feb-15 12:53pm    
Then use float: right in .image and #text p instead of float: left. After change the order of div and img in your body.
Kurac1 21-Feb-15 13:12pm    
its not geting centered.
Kurac1 21-Feb-15 13:18pm    
i cant center float
norbitrial 21-Feb-15 13:22pm    
I have updated my solution you can check how to center your content in background div.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900