The title of the document

How to Vertically Align a Text Next to the Image

If you want your Website to look beautiful and harmonious, then this snippet is for you. It will help you to learn how to align text next to an image vertically. Let’s dive in and learn to do it together!

Create HTML

html> html>   body> div div img src="https://i.pinimg.com/originals/26/ea/fc/26eafc0b14488fea03fa8fa9751203ff.jpg">
">

Paris is one of the most beautiful cities in France.

Add CSS

  • Put the display property and choose the «flex» value. It will represent the element as a block-level-flex container.
  • Use the align-items property with the «center» value to place the items at the center of the container.
  • Set the justify-content property to «center».
  • Put the image’s maximum width to 100% with the max-width property.
  • Set the flex-basis property of the «image» class to specify the initial main size of your image.
  • Choose the font size of your text with the help of the font-size property.
  • Use the padding-left property to set the padding space on the text’s left side.
.container < display: flex; align-items: center; justify-content: center > img < max-width: 100% > .image < flex-basis: 40% > .text < font-size: 20px; padding-left: 20px; >

You can style the text with other properties, such as color, text-alignment, text-decoration, text-transform, text-shadow and so on.

Читайте также:  Вложенные словари рекурсия python

Now let’s put the code parts together and see the result.

Example of vertically aligning a text next to the image:

html> html> head> title>The title of the document title> style> .container < display: flex; align-items: center; justify-content: center > img < max-width: 100% > .image < flex-basis: 40% > .text < font-size: 20px; padding-left: 20px; > style> head> body> div class="container"> div class="image"> img src="https://i.pinimg.com/originals/26/ea/fc/26eafc0b14488fea03fa8fa9751203ff.jpg"> div> div class="text"> h1>Paris is one of the most beautiful cities in France. h1> div> div> body> html>

Result

Paris

Paris is one of the most beautiful cities in France.

You can style the text with other properties, such as font, color, text-decoration, text-shadow and so on.

Example of styling a vertically aligned text:

html> html> head> title>The title of the document title> style> .container < display: flex; align-items: center; justify-content: center > img < max-width: 100% > .image < flex-basis: 70%; order: 2; > .text < color: #CD5C5C; padding-left: 20px; font: italic 10px "Fira Sans", serif; > style> head> body> div class="container"> div class="image"> img src="https://cdn.londonandpartners.com/visit/general-london/areas/river/76709-640x360-houses-of-parliament-and-london-eye-on-thames-from-above-640.jpg"> div> div class="text"> h1>London is the capital and largest city of England. h1> div> div> body> html>

Источник

How to put image and text side-by-side in HTML?

One of the common tasks that web developers face is how to put image and text side-by-side in HTML without them overlapping each other. In most cases, you can simply paste the image or video into your document and type out the text around it.

Читайте также:  Средства разработки язык программирования php

However, if the text or image is too long for the space you have available on the page, you may have to redesign your layout or position the image elsewhere on your page.

This can be a little tricky to do, but there are some simple techniques that you can use.

In this tutorial, we’ll demonstrate how to put an image and text side by side in your HTML project. We will use the and tags to do this. The text will be placed directly below the image using CSS properties. So let’s get going!

Select the ideal picture and text

First, locate an image that you wish to use. If you already have one, great! If not, you can look for images on the internet in a variety of places. Once you have the image that you want to use, you just need to copy its URL and then paste it into your project.

Next, write the text that will appear next to your image. You can write your text in any text editor (like Microsoft Word) and then copy and paste it into an HTML document.

How to display image and text side by side using grid method?

If you want to put text and an image side-by-side in your HTML document, there are a few simple steps you can follow.

  • First, Open the HTML editor on your pc.
  • You must create a div> element and assign it the necessary attributes. The element is used to group related elements together and it is often used to display content on a page such as images and text.
  • Next, you need to add the image to the element. To do this, use the tag and specify the source attribute. This attribute identifies the URL of the image file you would like to display on the page. For example, if you wanted to display an image from the “www.google.com” website, you would enter “https://www.google.com” in the source attribute.
  • Finally, add the
    tags between the element and the image using the

    tag to wrap the element around the image.

  • You can use CSS to style your webpage and give your divs certain properties, but you don’t need to worry about this just yet as we’ll be creating an example webpage using the default styles that HTML provides for us. The first step is to create a web page that displays an image alongside a block of text.

A webpage with the appearance shown below will be created using the code below:

html> html> head> title>Pretty Paris title> head> body> div class="container"> div class="image"> img src="https://i.pinimg.com/564x/59/32/29/593229739184504afd9507cc42a9cb86.jpg"> div> div class="text"> h1>This is a beautiful picture. h1> div> div> body> html>
Code language: HTML, XML (xml)

As you can see, the image is displayed at the top-left corner of the page and the text is displayed below it.

beautiful-picture

Include CSS

The next step is to add some styling so that the text is bigger and bolder than the rest of the image. To do this, use CSS to specify the size of the element and ensure that the text is beside the image.

The following code will display the image and set it to be the same size as the text:

.container < display: grid; align-items: center; grid-template-columns: 1fr 1fr 1fr; column-gap: 5px; > img < max-width: 100%; max-height:100%; > .text < font-size: 70px; >
Code language: CSS (css)

picture2

Using flexbox method

If you’re looking to embed text and an image side-by-side in HTML, then you can use the flexbox layout module. Here’s how:

  • In your HTML, create a container element for your text and image. For example, you can nest a
    inside a
    like this:
  • The CSS property selector may be used to change the container’s display property to”flex”. For instance, you could put the following in your CSS file: .text-wrapper
  • Next, define some properties for the container’s children – the image and the text. To do this, create individual CSS rules for each element using the property selector (in this case, the > symbol).
  • For example, you might add the following rules to the HTML file:
html> html> head> title>Pretty Paris title> head> style> .container < display: flex; align-items: center; justify-content: center > img < max-width: 100%; max-height:100%; > .text < font-size: 20px; padding-left: 20px; > style> body> div class="container"> div class="image"> img src="https://i.pinimg.com/564x/59/32/29/593229739184504afd9507cc42a9cb86.jpg"> div> div class="text"> h1>Paris is one of the most magnificient cities in France. h1> div> div> body> html>
Code language: HTML, XML (xml)

With these rules in place, your container should now look something like this:

flexbox method

Using Float text

Floating text is a great way to create an image that stands out from the surrounding text.

We’ll show you how to do it with the float property

  • The first thing we need to do is add the image to our HTML document. We can do this by using the img element, like this:
  • Now that we’ve added the image, we need to style it so that the text will surround it instead of underneath it. we’re going to use the float property to accomplish this. The float property allows you to control where an element is positioned in a page.
  • There are three different values for this property that you can use: left, right, and center. You can combine these values to create custom positioning of your elements. To display the text alongside the image, we’re going to set our image to float: left; This will position the image to the left and allow us to place the text on the right instead.
  • Once we’ve added our text and set the image to float: left; we can wrap our content with the tag and place the image inside of it. Next, we can use the align property of the tag to align the text in the center of the . The picture may then be placed within the div> tag, right next to the text.
html> html> head> title>Pretty flower title> head> style> .container < align-items: center; justify-content: center; > img < max-width: 25%; max-height:15%; float: left; > .text < font-size: 20px; padding-left: 20px; padding-top: 20%; float: left; > style> body> div class="container"> div class="image"> img src="https://i.pinimg.com/564x/48/bf/c9/48bfc9ae0a10418849a3f50d57c08897.jpg"> div> div class="text"> h1>This is a beautiful garden. h1> div> div> body> html>
Code language: HTML, XML (xml)

This will place the image right next to your text so that you can see both of them at the same time. Easy, right?

garden

Image on the left – HTML code on the right 🙂

Conclusion

Putting images and text side-by-side in HTML is a great way to create a visually appealing web page. There are a few different ways to do this by using but the easiest way is to use the ‘align’ attribute. With a little bit of code, you can have your images and text aligned perfectly on your web page. Thanks for reading!

Sharing is caring

Did you like what Vanshika wrote? Thank them for their work by sharing it on social media.

Источник

In CSS Aling Images And Text In Same Line

HTML Tutorials

In this tutorial, you will learn to align text and image in the same line using CSS in HTML.

Using the float property of CSS will allow you to place an image and text on the same line without breaking the line break. Or Alternatively, you should use the flexbox method of CSS that uses the flex property to make sure that images and lines are aligned in the same line.

Using the method outlined above will ensure that your images and text are both aligned on the same line of text. Let’s take a look at an example of code below.

How To Align Image and Text In Same Line In HTML Using CSS

In general, there are two ways to make sure everything is arranged up in a line. But I think the second method is better because it works in all situations.

1. Using Float Property Of CSS

Now let us see how the float property of the CSS can help us achieve this to get the images and text in the same line.

    body < background-color: black; >img  
The Text That you want to aling long in a line.

Aling Images And Text In Same Line

As you can see in the above output, I was able to align the image and text in a single line by utilizing the float:left alignment in the style section of the image.

Although the above method has one disadvantage, when you try to resize the screen, the image and text will no longer be aligned in a single line and will instead stack up. In order to overcome this disadvantage, you will need to use the flexbox technique.

2. Using Flexbox in CSS

So, when you use the above solution and try to change the size of the screen, the text and image will no longer be on the same line. To solve this problem, I will be using the flexbox. This will make sure that both images and text are always in line, no matter how big the screen is.

Aling Images And Text In Same Line

As you can see in the above image, flexbox makes sure that the image and text stay in one line, no matter how big or small the screen is. You can see this in the picture above.

Wrap Up

I hope you learned how to put images and text in the same line with CSS and HTML. I’ve given you two ways to solve this problem, but I’d rather you use the second one because it’s the most up-to-date method in the field.

Make sure to tell me if you know of another way to do this that I haven’t talked about above. I’ll add it here if I can find the time.

Источник

Оцените статью