Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to make a wrapper with image on the left and text on the right. I want to add space between the text and the image that will work properly for both mobile and computer screens.
Thank you.

What I have tried:

html :
HTML
<div Id="wrapper">
                <section class="p">
                    <ul id="a">
                      <li>
                          <img src="boy1.jpg" alt="" width=180px class="pic">
                          <p class="pa">info</p>
                        
                      </li>
                    </ul>
                  </section>
          
                     </div>  

CSS
#a, #g {
  background-color: #4158D0;
  background-image: linear-gradient(43deg, #4158D0 0%, #C850C0 46%, #FFCC70 100%);
  ;
}

.pic {
  float: left;
}

#wrapper {
max-width: 1200px;
margin: 0 auto;
padding: 0 5%;
list-style-type: none;
text-decoration: none;
}

ul li:hover{
  cursor: default;
  color: white;
}
Posted
Updated 4-Nov-21 3:18am

1 solution

You haven't shown us what you've tried, or what's wrong with it.

If you just want space between the image and the text, then flexbox should work:
CSS
#a > li:first-child {
    display: flex;
}
#a .pa {
    margin-left: auto;
}
Demo[^]
A Complete Guide to Flexbox | CSS-Tricks[^]
CSS Flexible Box Layout - CSS: Cascading Style Sheets | MDN[^]
 
Share this answer
 
Comments
Keerat Singh _ 9H 5-Nov-21 7:51am    
Hi thank you. Can you also tell how to make the text-align to center and if I increase the size of image will it work? Thanks
Richard Deeming 5-Nov-21 9:33am    
Increasing the size of the image will work.

I don't know what you mean by setting the text align to center? Do you want the text aligned to the center, or do you want it aligned to the right?
Keerat Singh _ 9H 7-Nov-21 3:42am    
Center
Richard Deeming 9-Nov-21 3:44am    
Then add margin-right:auto to the #a .pa rule.
Demo[^]
Keerat Singh _ 9H 6-Nov-21 7:32am    
Center

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