Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Trying to have a space between text and image

anuraa

Legendary Coder
Hello friends:

I am trying to have a space between the text and image border. It doesn't happen with my padding. When I remove, border CSS, I can have space between space between text and image.
Thanks for helps.
HTML:
<!DOCTYPE html>
<html>
<head>
    <title>Learning Example</title>
    <style>
    .container1{
    margin: 11px 10px 10px 10px;
    width: 98%;
    padding: 8px 8px 8px 8px;
    }
    .wtexta{
    float: right;
    width: 60%;
    height: auto;
    padding: 10px 10px 10px 10px;
    border-style: outset;
    border-width: 5px;
    border-color: gold;
    }
    .texta{
    text-align: justify;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    padding: 10px 10px 10px 10px;
    }
    </style>
</head>
<body>
    <div class="container1">
        <img class="wtexta" src="nangi.webp" >
        <div class="texta">
          Her Name is Mrs. D…….  Fernando de Silva.  <br><br>
         She was born to a wealthy Buddhist family in Panadura.
          Educated at Panadura Balika Vidyalaya.<br><br> Her parents
          are the late Mr. sss Fernando and the late Mrs. Leela Fernando.
           She has only one brother the late Mr. Tissa
           Fernando who had passed away. <br><br>
            D…. is always interested in music, literature,
            sports since she was very little with the guidance
            from her mother, father and older brother. <br>
        </div>
      </div>
</body>
</html>
 

Attachments

  • nangif.jpg
    nangif.jpg
    149.9 KB · Views: 2
Solution
D
If you with to retain the text wrap that float gives you, then to add space, use margin like so:
CSS:
.wtexta{
  float: right;
  width: 60%;
  height: auto;
  padding: 10px 10px 10px 10px;
  margin: 10px;     /* I added this */
  border-style: outset;
  border-width: 5px;
  border-color: gold;
}
Consider flex:

CSS:
.container1{
  display: flex;
  gap: 30px;
}
.wtexta{
  flex: 60%;
  order: 2;
  border-color: gold;
}
.texta{
  flex:40%;
  order: 1;
  padding: 10px;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
}

Change the gap and padding as desired.
You can also switch the img and div elements to get them in the correct Left/Right order, but instead I added the order property to show how powerful flex is.
It is a nice picture, by the way.
 
If you with to retain the text wrap that float gives you, then to add space, use margin like so:
CSS:
.wtexta{
  float: right;
  width: 60%;
  height: auto;
  padding: 10px 10px 10px 10px;
  margin: 10px;     /* I added this */
  border-style: outset;
  border-width: 5px;
  border-color: gold;
}
 
Solution

Buy us a coffee!

Back
Top Bottom