Jump to content

align image and text within a div

Recommended Posts

Site URL: http://https%3Atracytredoux.com/code-test

image.thumb.png.494cc9ccce97468b989e6c3a808948f5.png

Hi, I'm trying to create a series of coloured blocks that contain an icon, a title and some text. This is the closest I have been able to get and as you can see from the code below, it's a bit messy. I have had to position the icon and the text manually, and the icon does not stay vertically centred as the screen is resized.

If anyone has a suggestion how I could code this more effectively I would be very grateful.

<style>
  
  .heading{
  font-size:1.2em;
  }
  
  .text{
  margin-left:60px}
  
  .imageplace{
   position:absolute;
   top:30px
   }
  
  .green{
  background-color:#c4e5c0;
  padding:20px 40px 20px 40px;
  border-radius:0px 20px 0px 20px;
  max-width: max-content;
  text-align:center;
  }
  
  </style>
  
  <div class="green">
  <div class="imageplace"><img src="https://images.squarespace-cdn.com/content/v1/58762023893fc0d94810ba05/1663759321108-63ZII831I0JURY7W4V9T/guide.png?format=500w" alt="Cinque Terre" width="60" height="60"></div><div class="text"><span class="heading">At a Glance</span> – this is your daily protocol for phases 2 and 3 of the program, recipes included and some more test text to see how it resizes as i change the size of the viewport.</div>
</div><br>

 

Link to comment
  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

1 hour ago, Phobic78 said:

Site URL: http://https%3Atracytredoux.com/code-test

image.thumb.png.494cc9ccce97468b989e6c3a808948f5.png

Hi, I'm trying to create a series of coloured blocks that contain an icon, a title and some text. This is the closest I have been able to get and as you can see from the code below, it's a bit messy. I have had to position the icon and the text manually, and the icon does not stay vertically centred as the screen is resized.

If anyone has a suggestion how I could code this more effectively I would be very grateful.

<style>
  
  .heading{
  font-size:1.2em;
  }
  
  .text{
  margin-left:60px}
  
  .imageplace{
   position:absolute;
   top:30px
   }
  
  .green{
  background-color:#c4e5c0;
  padding:20px 40px 20px 40px;
  border-radius:0px 20px 0px 20px;
  max-width: max-content;
  text-align:center;
  }
  
  </style>
  
  <div class="green">
  <div class="imageplace"><img src="https://images.squarespace-cdn.com/content/v1/58762023893fc0d94810ba05/1663759321108-63ZII831I0JURY7W4V9T/guide.png?format=500w" alt="Cinque Terre" width="60" height="60"></div><div class="text"><span class="heading">At a Glance</span> – this is your daily protocol for phases 2 and 3 of the program, recipes included and some more test text to see how it resizes as i change the size of the viewport.</div>
</div><br>

 

Can you check your link again? I can not access it now

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment

Try adding to Home > Design > Custom Css

.green {
  display: flex;
  align-items: center;
}

.green .imageplace {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  top: 0;
  width: 10%; /*increase size of image*/
}
.green .text {
  margin-left: 0;
}

Support me by pressing 👍 if this useful for you

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment

My testing

image.png.52783ecdd10e1f073ae884b15ad3a194.png

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
4 hours ago, bangank36 said:

Try adding to Home > Design > Custom Css

.green {
  display: flex;
  align-items: center;
}

.green .imageplace {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  top: 0;
  width: 10%; /*increase size of image*/
}
.green .text {
  margin-left: 0;
}

Support me by pressing 👍 if this useful for you

Thanks for your answer, @bangank36. It kind of works, but when the screen width gets smaller, the image becomes tiny. I'm attaching a screenshot:

 

image.thumb.png.b757835d4007cd29d089c5456a7f2d90.png

Link to comment
On 9/22/2022 at 1:25 AM, Phobic78 said:

Thanks for your answer, It kind of works, but when the screen width gets smaller, the image becomes tiny. I'm attaching a screenshot:

 

image.thumb.png.b757835d4007cd29d089c5456a7f2d90.png

It looks fine to me. Which screen size/or device do you see problem?

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
13 minutes ago, tuanphan said:

It looks fine to me. Which screen size/or device do you see problem?

Thanks, @tuanphan and @bangank36, it does seem to work now. I'm not sure why the image was resizing for me before. I cleared my browser cache and restarted the laptop and it works now. The only thing is that the image aligns to the top of the container (see the screenshot). Is there any way that I can vertically align it to the centre?

image.thumb.png.5500e38847dc9113a95fbc65cf9092f9.png

Link to comment
23 hours ago, Phobic78 said:

t does seem to work now. I'm not sure why the image was resizing for me before. I cleared my browser cache and restarted the laptop and it works now. The only thing is that the image aligns to the top of the container (see the screenshot). Is there any way that I can vertically align it to the centre?

image.thumb.png.5500e38847dc9113a95fbc65cf9092f9.png

Try adding this to Design > Custom CSS

.imageplace {
    top: 50%;
    transform: translateY(-50%);
}

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.