skip to Main Content

On this little project i can’t place paragraph on the right of the photo properly. There is big a mount of space between them.

I used display:flex to place them horizontally. And width: 50% to make them get half of the screen, but there is still field in the center….

Can someone help with solving this ?

enter image description here

What should i get:
enter image description here

I tried changing width 33%, I’ve also tried adding padding and margin.

.center {
  display: flex;
  padding: 10px 10px;
  background-color: #c2e7f0;
  margin-top: 15px
}

.all {
  display: flex;
  padding: 20px;
}

.center img {
  width: 60%;
  float: left;
}

.text {
  width: 50%;
  font-weight: 100;
}
<div class="center">
  <div class="all">
    <div class="center_img">
      <img src="g1.png">
    </div>

    <div class="text">
      <h2>Khvicha Kvaratskhelia relishes ‘best day’ in Georgians’ lives</h2>
      <p>Georgia is the lowest-ranked team at this year’s European Championship and few gave the nation a chance of progressing out of the group stages in what is its debut appearance at a major tournament.</p>
      <p>But against all odds, the Crusaders produced a memorable performance to secure a deserved 2-0 Group F win against Portugal, thanks to a second-minute goal from Kvaratskhelia and a second-half penalty from Georges Mikautadze.</p>
      <p>The coach, a vital cog in manager Willy Sagnol’s team, said the squad had been “calm” ahead of the crunch tie and managed to execute the game plan to perfection.Webb, known for his ability to motivate players on a more personal level, said he had
        delivered a presentation before the tournament which focused on self belief.He said his speech drew on motivation from smaller nations, such as Wales and Iceland, which had punched above their weight at previous European Championships – Wales
        reached the semifinals and Iceland the quarterfinals at Euro 2016.</p>
    </div>
  </div>
</div>

2

Answers


  1. I noticed you had an extra <div> element surrounding the <img>, causing the <img> to be 60% of the width of the parent div. Because of this, the image was not large enough to fit the entire box and thus there is extra space around it.

    To fix this, you could either remove the outer div, resulting in your HTML to be:

    <div class="center">
      <div class="all">
        <img src="https://picsum.photos/600/400">
    
        <div class="text">
          <h2>Khvicha Kvaratskhelia relishes ‘best day’ in Georgians’ lives</h2>
          <p>Georgia is the lowest-ranked team at this year’s European Championship and few gave the nation a chance of progressing out of the group stages in what is its debut appearance at a major tournament.</p>
    
    ...
    

    or you could change the CSS to style the div to be 60%, whereas the image within to be 100% width, like below:

    .all div {
      width: 60%;
    }
    
    .center img {
      width: 100%;
    }
    
    Login or Signup to reply.
  2. To place the paragraph on right side of the photo properly without any extra space between them, you can adjust the flex properties and ensure the widths of the elements are set correctly.

    Please read the article – https://css-tricks.com/snippets/css/a-guide-to-flexbox/

    https://www.w3schools.com/css/css3_flexbox.asp

    Because flexbox understanding is good to do like this type of html arrangements.

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <style>
        .center {
          display: flex;
          padding: 10px;
          background-color: #c2e7f0;
          margin-top: 15px;
          justify-content: center;
        }
    
        .all {
          display: flex;
          padding: 20px;
          align-items: center;
        }
    
        .all img {
          max-width: 100%;
          height: auto;
        }
    
        .image-container {
          flex: 1;
          padding-right: 10px;
        }
    
        .text {
          flex: 1;
          font-weight: 100;
        }
      </style>
    </head>
    <body>
      <div class="center">
        <div class="all">
          <div class="image-container">
            <img src="https://picsum.photos/600/400" alt="Sample Image">
          </div>
          <div class="text">
            <h2>Khvicha Kvaratskhelia relishes ‘best day’ in Georgians’ lives</h2>
            <p>Georgia is the lowest-ranked team at this year’s European Championship and few gave the nation a chance of progressing out of the group stages in what is its debut appearance at a major tournament.</p>
          </div>
        </div>
      </div>
    </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search