изображение по центру таблицы
Здравствуйте всем! Прошу помощи. Не могу поставить изображение — ссылку посередине ячейки таблицы. Все теги уже перепробовала, она ни с места. Создана таблица, в одну из ячеек вставляю ссылку — изображение, прилипает зараза к левому краю и все тут, а мне бы по-центру и желательно внизу.
1 2 3
table class="priceVZO" cellpadding="0" cellspacing="0"> tr style="background:#31659c;color:#f5f5f5;">td>Фото/td>td>b>За единицу/b>/td>td>b>Цена с НДС, грн/b>/td>td>b>Цена без НДС, руб. РФ/b>/td>td>b>Цена без НДС, евро/b>/td>td>b>Цена без НДС, дол/b>/td>/tr> tr>td>img src="https://www.cyberforum.ru/images/gstindex2.jpg" alt="ГСТ-1000" />/td>td>b>ГСТ-1000 "Диапазон"/b>a href="gst.php">img src="https://www.cyberforum.ru/images/knopkaopisanie.png" width="80%" height="45" align="bottom" alt="переход на описание">/a>/td>td>75 000,00/td>td>300 000,00/td>td>6 850,00/td>td>9 080,00/td>/tr> .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
table.priceVZO { margin: auto; border-top: 1px solid orange; border-left: 1px solid orange; margin-bottom: 40px; } table.priceVZO td { width: 200px; padding: 3px; text-align: center; font-size: 11px; border-bottom: 1px solid orange; border-right: 1px solid orange; }
Как выровнять картинку по вертикали
Итак, у нас есть картинка и есть блок div. Как выровнять картинку по вертикали?
1. Нам не известны ни размеры картинки, ни размеры блока
Вариант 1. Картинка с абсолютным позиционированием
1 2 3
1 2 3 4 5 6 7 8 9 10 11 12
.outer { height: 100px; position: relative; } .outer img { position: absolute; margin: auto; left: 0; top: 0; bottom: 0; right: 0; }
Height введен только чтобы расширить блок, он может быть динамическим, и картинка всегда будет по центру.
Пример:
Вариант 2. Через table-cell
Верстка как и в первом примере:
1 2 3
1 2 3 4 5 6 7
.outer1 { display: table-cell; vertical-align: middle; text-align: center; width: 500px; height: 100px; }
Здесь тоже высота может быть динамической. Но есть одно НО – ширину блока уже нельзя указать в 100%, должен быть задан width.
Пример:
2. Нам известна высота блока, но не известна высота картинки
Способ через line-height. Высота картинки должна быть меньше высоты блока.
1 2 3
1 2 3 4 5 6 7 8
.outer2 { height: 100px; line-height: 100px; text-align: center; } .outer2 img { vertical-align: middle; }
Пример:
Нам известна высота картинки, но неизвестна высота блока
Способ через абсолютное позиционирование картинки
Суть этого способа заключается в добавлении картинке position: absolute, отодвигании ее сверху на 50% через свойство top, а потом добавлении отрицательного margin, равного половине высоты этой картинки. Также можно выравнивать картинку и по горизонтали (добавлением свойств top: 50% и margin-top, равного половине ширины картинки).
Верстка:
1 2 3 4 5 6 7 8 9 10 11 12
Выравнивание изображения в HTML
Уже выравниваете картинку? А уверены, что вставили ее семантически правильно? Смотрите, как добавлять изображения на сайт, чтобы это помогло Вашему SEO-продвижению «Как правильно вставить изображение в HTML».
Теперь про выравнивание. Если Вам нужно просто вставить изображение прямо в текст, например, после какого-то слова, то прямо там и пропишите тег img. Если же нет, то отдельные ситуации описаны ниже.
Картинка в отдельной строке
Если Вам нужно, чтобы картинка была в новой строке, то поместите её в тег вот так:
Тег p означает новый абзац. То есть картинка будет в новом отдельном абзаце.
Картинка по центру сайта
Если нужно при этом разместить картинку по центру, то код будет такой:
Здесь тегу p добавлен атрибут style=»text-align: center;». Это означает, что весь текст (в том числе и все изображения) внутри тега будет выровнен по центру.
Картинка слева или справа от текста
Чтобы сориентировать картинку относительно текста, нужно прописать ей align=»left» или align=»right», например, так:
left — картинка будет слева от текста, right — справа.
Добавить комментарий Отменить ответ
Этот сайт, как и все сайты, использует cookie. Продолжая использовать этот сайт, Вы даете свое согласие на обработку cookie.OK
Manage consent
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
| Cookie | Duration | Description |
|---|---|---|
| cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category «Analytics». |
| cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category «Functional». |
| cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category «Necessary». |
| cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category «Other. |
| cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category «Performance». |
| viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
