There is a code

<h1><a href="site.ru" id="logo"><img src="logo.png" alt=""> Здесь должен быть текст</a></h1> 

When using this code, it turns out like this

Vertical text layout

(A triangle is a picture logo, the text is the text of the logo).

What is the question: How to make the text exactly in the center of the picture on the right. Internal perfectionist indignant.

Closed due to the fact that off-topic participants Alexey Shimansky , AK , Grundy , D-side , Pavel Parshin Jan 22, '17 at 1:26 pm .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Alexey Shimansky, AK, Grundy, D-side, Pavel Parshin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • On the left is the logo, on the right is the text, you need to make it so that the text is positioned relative to the image vertically in the center (I think clearly expressed) As for the system, I meant in general all html, in my opinion, the way the text is located is more than stupid. When you insert an image in front of the text, the text falls on the bottom of the picture. This can be seen from the screenshot clipping. (Triangle - logo. "KAAAAAK ???" - text to the logo). - Profile deleted
  • four
    Either the question shows the code as you are trying to do, or the question is about nothing - Alexey Shimansky

3 answers 3

There are an infinite number of ways to align the logo, relative to the company name, and they are limited only by our imagination.

In order to accurately answer the question, I used exactly the layout that the author provided, but if you go beyond it, then perhaps the original problem was not even there.

However, I want to note that in spite of the fact that I used the layout of the author of the question, his result may differ due to the imposition of his previously written styles.

In order to prevent this from happening, I recommend that the author of the question specify classes and identifiers for objects and be more careful in choosing selectors when drawing up CSS rules.

Negative margin

Specify a negative indent from the bottom, thereby shifting "under the line" on which the image is located.

 <h1> <a href="site.ru" id="logo"> <img src="https://i.stack.imgur.com/IvEH3.png" alt=""/> Здесь должен быть текст </a> </h1> <style> h1 img { margin-bottom: -30px; } </style> 

Result: enter image description here


vertical image alignment

Specify that the image should be aligned in the middle of the line.

 <h1> <a href="site.ru" id="logo"> <img src="https://i.stack.imgur.com/IvEH3.png" alt=""/> Здесь должен быть текст </a> </h1> <style> h1 img { vertical-align: middle; } </style> 

Result: enter image description here


logo offset using transform

more complicated here.
similar to the first option, just shift relative to the string using the trendy transform property

 <h1> <a href="site.ru" id="logo"> <img src="https://i.stack.imgur.com/IvEH3.png" alt=""/> Здесь должен быть текст </a> </h1> <style> h1 img { transform: translateY(39%); } </style> 

Result:

enter image description here


positioning + stretching

it's still harder and without doping, not everyone can figure it out
indicate that the image is absolutely positioned relative to the parent object
indicating zero distance to the borders of the parent object, stretch it to 100% of the parent height
after specifying automatic indentation at the top and bottom, the image is positioned along the center line of the parent object
because the image is positioned absolutely, it enters the text
to fix we will add an internal indent to the parent object and an external image
indentation should be equal to the width of the image

 <h1> <a href="site.ru" id="logo"> <img src="https://i.stack.imgur.com/IvEH3.png" alt=""/> Здесь должен быть текст </a> </h1> <style> h1 a { position: relative; padding-left: 200px; } h1 img { position: absolute; top: 0; bottom: 0; margin: auto 0; margin-left: -200px; } </style> 

Result:

enter image description here

You can continue indefinitely, but the sophistication of the answers will increase.
Again, I stress that if you change the layout, you could get rid of more simple techniques.
Not the point


If the methods described above do not suit you, it means that the problem lies outside the code you specified and there you did what you shouldn’t do.
And the probability of this is quite high, because You have already complained that the answers given to you previously do not suit you, despite the fact that they work perfectly in an isolated environment. So I did not get involved with the "infinite list" and decided to wait for the reaction of the author of the question.
Check and unsubscribe by result

If the answer does not fit, but you provide a sufficient amount of source data, we will always help you.

  • You are not so thank you, you just have a universal scale thanks! You helped me a lot, I did everything using the “positioning + stretching” method. Thank you very much! - Profile deleted
  • @Evgeniy, I'm glad that everything turned out :) - Mikhail Rebrov
  • Add a way with flexbox, as for me it is the most ideal in such cases. - l2banners
  • @ l2banners, thanks for the comment. As time appears, I will add it. - Mikhail Rebrov

KAAAAAK ???

 img { vertical-align: middle; } 
 <img src="http://i.smiles2k.net/big_smiles/big_smiles_74.gif" alt="">А вот так. 

  • And you know something, does not work. Obviously, I have already tried this way, and for this reason I have turned for help. s010.radikal.ru/i313/1701/96/4a0a06e77e79.jpg - Profile deleted
  • @Evgeniy, the snippet example definitely works. In the same time. It is not known for what markup did the specified screenshot, so it is not known what and how you tried. - Grundy

float: left remove from the picture ...

  • And again by. Here is the code s014.radikal.ru/i328/1701/e6/151e381c52b1.jpg As we see now, according to the logic, the text should really fall on the bottom of the picture. If we try to bind the text to css and insert vertical-align, then nothing happens. I apologize for being too emotional, but you can’t even imagine that having put most of the landing page, I was defeated by a 70 pixel picture size. This is an indescribable feeling ... - Profile deleted
  • 2
    @Evgeniy You basically will insert code with pictures? - AK
  • How else? How is it different? - Profile deleted
  • @Evgeniy, in text form in the body of the question. - Mikhail Rebrov
  • one
    @Evgeniy and where in your question css which you apply? You still do not understand how to issue a question - Alexey Shimansky