На первый взгляд может показаться, что решение вынесенной в заголовок задачи тривиально: устанавливаем CSS-атрибут vertical-align:middle - и все дела. Но не так все просто. Принцип компоновки элементов традиционно основан на масштабировании по ширине, в высоту же содержимое растягивается или сжимается в соответствии с шириной. vertical-align удобно использовать в таблицах для центрирования содержимого ячеек, равно как и в блоках DIV с атрибутом display:table-cell. Ожидаемого поведения при вертикальном центрировании контента можно также достичь для элементов нормального потока страницы - блоков с атрибутом display:inline-block. Во всех же прочих случаях этот подход неприменим, поскольку большинство современных браузеров просто использует значение атрибута vertical-align для наследования дочерними inline-элементами блока. Здесь потребуется другая методика, описанию которой и посвящена эта статья.

Сразу оговорюсь: использование этой техники подразумевает два предположения:

  • Вы можете определить фиксированную высоту внутреннего блока.
  • Можно присвоить внутреннему блоку абсолютное позиционирование. Как правило, это не проблема, поскольку контейнер может оставаться в общем потоке.

Если эти условия соблюдены, делаем следующее:

  1. В стиле контейнера определяем атрибут position как relative или absolute.
  2. Задаем фиксированную высоту дочернего блока.
  3. Устанавливаем в стиле дочернего блока position:absolute и top:50%, совместив тем самым его верхнюю границу с серединой родительского блока.
  4. Присваиваем атрибуту margin-top дочернего блока значение, равное половине его высоты, что сдвинет дочерний блок вверх до совпадения его середины с серединой контейнера.

Пример:

<div style="position: relative;">
  Контейнер
  <div style="position:absolute; top:50%; height:8em; margin-top:-4em;">
    Отцентрированный по вертикали дочерний блок
  </div>
</div>

Вот как это выглядит в браузере:

Контейнер
Отцентрированный по вертикали дочерний блок

Пример практического использования данного метода при вписывании имиджа в контейнер вы можете найти в следующей статье.

Комментарии  

biggaming
0 # biggaming 17.05.2023 04:03
Look at my homepage ... biggaming
Ответить | Ответить с цитатой | Цитировать
sport betting
0 # sport betting 17.05.2023 19:44
eplsg.net is your go-to source for the latest news, information, and insights on the Premier League.
With top-notch content and cutting-edge analysis, you'll
never miss a beat! Get ready for an exciting season

Feel free to visit my website sport betting
Ответить | Ответить с цитатой | Цитировать
evolution gaming bet
0 # evolution gaming bet 18.05.2023 01:59
My blog post :: evolution gaming bet
Ответить | Ответить с цитатой | Цитировать
คาสิโนออนไลน์ 168
0 # คาสิโนออนไลน์ 168 18.05.2023 14:20
ก้าวเข้าสู่ Cherry Casino และสำรวจโลกแห่งเกมสำหรับผู้ใหญ่ ด้วยสล็อตและเกมมากกว่า 1,
000 รายการ คุณจะสามารถค้นหาสิ่งที่เหมาะกับรสนิยมของคุณ นอกจากนี้ ด้วยโบนัสและโปรโมชันมากมาย คุณจะได้รับผลตอบแทนที่มากขึ้น มา

Feel free to surf to my website ... คาสิโนออนไลน์ 168
Ответить | Ответить с цитатой | Цитировать
baccarat stone x2
0 # baccarat stone x2 18.05.2023 20:19
Enjoy the ultimate online Baccarat experience at Baccaratsg.com.
Our site offers an exciting range of real-time games and features, as well as a secure and safe environment to
play in. Test your luck today with our exclusive

My blog; baccarat stone
x2
Ответить | Ответить с цитатой | Цитировать
sagame 168vip
0 # sagame 168vip 19.05.2023 01:35
สัมผัสความตื่นเต้นของเกมออนไลน์กับ Sagame
เลือกจากสล็อต เกมบนโต๊ะ และตัวเลือกการเดิมพันกีฬาที่น่าตื่นเต้นหลายร้อยราย การ ด้วยโบนัส โปรโมชัน และโปรแกรม VIP ที่หลากหลาย Sagame มีบางสิ่งสำหรับทุกคน มาร่วมสนุกได้แล้ววันนี้!


my homepage - sagame 168vip
Ответить | Ответить с цитатой | Цитировать
spade gaming adalah
0 # spade gaming adalah 19.05.2023 07:14
my web-site - spade gaming adalah
Ответить | Ответить с цитатой | Цитировать
slots
0 # slots 19.05.2023 14:39
Experience the thrill of casino games with CasinosG!
We have all your favorites from slots and table games, to live dealer options.
Play for real money or just for fun - the choice is yours!

Join today to get your welcome bonus and start
Ответить | Ответить с цитатой | Цитировать
king855 casino
0 # king855 casino 20.05.2023 07:54
Are you looking for an exciting online casino experience?
Look no further than king855
casino
. That is one of the most popular online casino
sites around and offers a wide range of games and promotions.

At king855, you can play classic slots, video slots, table games, poker, baccarat, and other specialty games.

Also you can enjoy sports betting on popular sports
such as for example football, basketball, and tennis.
The casino offers great bonuses and promotions like welcome bonuses, deposit bonuses,
and free spins. There is also a loyalty program where you can earn points and redeem them for rewards such as for example cashback and free spins.

It is possible to access king855 online casino on any device ?
desktop, laptop, mobile, or tablet. The website is also secure and safe, so you can be sure that your computer data is safe.

Go through the thrill of online casino gaming with king855 today!
Ответить | Ответить с цитатой | Цитировать
sexy baccarat
0 # sexy baccarat 20.05.2023 15:03
เล่น Sexy Baccarat และเกมคาสิโนออนไลน์อื่นๆ
กับเรา ที่ Sexy
Baccarat
Thai เรามีตัวเลือกเกมออนไลน์ที่หลากหลายเพื่อตอบสนองความ คาดหวังของผู้เล่น เลือกจากเกมการพนันที่น่าตื่นเต้นมากมายและเริ่มชนะท ันที!
Ответить | Ответить с цитатой | Цитировать
pgslot vegas
0 # pgslot vegas 20.05.2023 15:46
My homepage :: pgslot vegas
Ответить | Ответить с цитатой | Цитировать
bitcoin casino malta
0 # bitcoin casino malta 20.05.2023 16:23
Also visit my webpage ... bitcoin casino
malta
Ответить | Ответить с цитатой | Цитировать
สล็อต66
0 # สล็อต66 21.05.2023 05:51
พร้อมเป็นผู้โชคดีหรือยัง?

4Jokers Casino คือประสบการณ์การเล่นเกมออนไลน์ที่ดีที่สุด!
เตรียมตัวให้พร้อมสำหรับชัยชนะครั้งใหญ่ในเกมสล็อต
แจ็คพอต และเกมคาสิโนคลาสสิกที่หลากหลายของเรา เข้าร่วมตอนนี้และเตรียมพร้อมสำหรับความตื่นเต้นของชีวิต

Here is my web-site สล็อต66
Ответить | Ответить с цитатой | Цитировать
sa gaming บาคาร่า
0 # sa gaming บาคาร่า 21.05.2023 05:55
เล่นเกมคาสิโนออนไลน์ที่คุณชื่นชอบและรับรางวัลใหญ่ท ี่ sa919.net!
ด้วยโบนัส โปรโมชั่น และอื่นๆ อีกมากมาย คุณสามารถเพลิดเพลินกับเกมสล็อต รูเล็ต แบล็กแจ็ก และบาคาร่าที่คุณโปรดปรานจากที่บ้านได้อย่างสะดวกสบาย

My blog post - sa gaming บาคาร่า
Ответить | Ответить с цитатой | Цитировать
king855 casino
0 # king855 casino 21.05.2023 07:31
Are you looking for a thrilling online casino experience?
Look no further than king855 casino.

This is probably the most popular online casino sites around and will be
offering a wide range of games and promotions.
At king855, it is possible to play classic slots, video slots,
table games, poker, baccarat, and other specialty games.
Also you can enjoy sports betting on popular sports such as for example football, basketball, and
tennis.
The casino offers great bonuses and promotions like welcome bonuses,
deposit bonuses, and free spins. There is also
a loyalty program where you can earn points and
redeem them for rewards such as for example cashback and free spins.

You can access king855 online casino on any device ? desktop, laptop,
mobile, or tablet. The web site can be secure and safe, so you can be sure that your data is safe.

Go through the thrill of online casino gaming with king855 today!
Ответить | Ответить с цитатой | Цитировать
918kiss
0 # 918kiss 21.05.2023 21:17
Get ready for the ultimate gaming experience with 918kiss.

Spin and win on classic casino favorites such as Roulette, Blackjack, Slots, Poker and more.
Enjoy thrilling bonuses and special promotions to boost
your bankroll and make playing even more
Ответить | Ответить с цитатой | Цитировать
คาสิโนออนไลน์1688
0 # คาสิโนออนไลน์1688 21.05.2023 23:32
รับประสบการณ์การเล่นเกมขั้นสุดยอดกับ Win4RealCasino.net!

เรานำเสนอเกมที่หลากหลายตั้งแต่สล็อตไปจนถึงแบล็คแจ็ค พร้อมโปรโมชั่นและโบนัสที่น่าตื่นเต้น เข้าร่วมกับเราวันนี้และค้นหาว่าทำไมเราถึงเป็นคาสิโนออนไลน์ที่ดีที่สุดสำหรับการชนะด้วยเงินจริง

Here is my web site; คาสิโนออนไลน์1688
Ответить | Ответить с цитатой | Цитировать
เว็บ เซ็กซี่บาคาร่า
0 # เว็บ เซ็กซี่บาคาร่า 22.05.2023 12:58 Ответить | Ответить с цитатой | Цитировать
caishen wins
0 # caishen wins 22.05.2023 16:05
พร้อมที่จะชนะรางวัลใหญ่?
เล่นสล็อตคาสิโนออนไลน์และเกมบนโต๊ะที่คุณชื่นชอบที่
CaishenWins ด้วยเกมที่มีให้เลือกมากกว่า 500 เกม คุณจะพบกับชุดค่าผสมที่ชนะได้อย่างแน่นอน ตรวจสอบโปรโมชั่นและโบนัสที่ยอดเยี่ยมของเราเพื่อโอกาสที่มากขึ้น

Feel free to surf to my blog - caishen wins
Ответить | Ответить с цитатой | Цитировать
slot roma
0 # slot roma 23.05.2023 04:25
Slotroma Casino offers the best online casino gaming experience.
With hundreds of slots and table games, you can enjoy a thrilling gaming experience with top-notch graphics and sound effects.
Get ready for the ultimate casino adventure with Slotroma!


Also visit my webpage :: slot roma
Ответить | Ответить с цитатой | Цитировать
crypto casino no kyc
0 # crypto casino no kyc 23.05.2023 07:54
Also visit my web site :: crypto casino
no kyc
Ответить | Ответить с цитатой | Цитировать
budtrader.com
0 # budtrader.com 29.05.2023 04:41
Play the latest online casino games at mega888 and win big.
Experience fun, thrilling, and exhilarating playing options with
a number of the newest gaming titles in the industry.
Try your luck today!

Join mega888 and experience the ultimate online casino gaming experience.
Having an extensive selection of games, entertaining features and generous
bonuses, mega888 offers a one-of-a-kind gaming experience for
all forms of players. Register now and allow good

Play top-rated online casino game mega888 and win amazing prizes.
Like a wide selection of the most recent and greatest video slots
from leading developers. With free bonuses, daily challenges
and VIP programs, mega888 brings the best gaming experience to your

Play your favorite online casino games at Mega888 and also have an unforgettable
gaming experience! Enjoy hundreds of slots, live casino tables, and more with bonus points
and in-game rewards. Go through the thrill of winning now!


Play all of your favorite online casino games at mega888.

Like a wide range of slots, jackpot games, live dealer games and much more.
Start playing today and become in with the opportunity to win real money prizes!


Play mega888 (budtrader.com)
online with secure Malaysian online gaming!
We offer the very best gaming experience with a host of amazing promotions and
bonuses, and also top-notch customer service.

Download now and enjoy a distinctive casino gaming adventure without needing to travel!
Ответить | Ответить с цитатой | Цитировать

Добавить комментарий


Работая с этим сайтом, вы даете свое согласие на использование файлов cookie, необходимых для сохранения выбранных вами настроек, а также для нормального функционирования сервисов Google.