- vertical-align
- Try it
- Syntax
- Values for inline elements
- Parent-relative values
- Line-relative values
- Values for table cells
- Formal definition
- Formal syntax
- Examples
- Basic example
- HTML
- CSS
- Result
- Vertical alignment in a line box
- HTML
- Result
- Vertical alignment in a table cell
- HTML
- CSS
- Result
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- Is There a Vr (Vertical Rule) in HTML
- How to make a vertical line in HTML
- How do I make a tag go vertically
- Vertical hr tag
- Vertical rule (as opposed to ) in CSS
- basically
- hr elements vertically between buttons?
- vertical divider between two columns in bootstrap
- How to place a vertical hr line beside two images in html
- Codre Blog
- Выравнивание с помощью таблицы
vertical-align
The vertical-align CSS property sets vertical alignment of an inline, inline-block or table-cell box.
Try it
The vertical-align property can be used in two contexts:
- To vertically align an inline-level element’s box inside its containing line box. For example, it could be used to vertically position an image in a line of text.
- To vertically align the content of a cell in a table.
Note that vertical-align only applies to inline, inline-block and table-cell elements: you can’t use it to vertically align block-level elements.
Syntax
/* Keyword values */ vertical-align: baseline; vertical-align: sub; vertical-align: super; vertical-align: text-top; vertical-align: text-bottom; vertical-align: middle; vertical-align: top; vertical-align: bottom; /* values */ vertical-align: 10em; vertical-align: 4px; /* values */ vertical-align: 20%; /* Global values */ vertical-align: inherit; vertical-align: initial; vertical-align: revert; vertical-align: revert-layer; vertical-align: unset;
The vertical-align property is specified as one of the values listed below.
Values for inline elements
Parent-relative values
These values vertically align the element relative to its parent element:
Aligns the baseline of the element with the subscript-baseline of its parent.
Aligns the baseline of the element with the superscript-baseline of its parent.
Aligns the top of the element with the top of the parent element’s font.
Aligns the bottom of the element with the bottom of the parent element’s font.
Aligns the middle of the element with the baseline plus half the x-height of the parent.
Aligns the baseline of the element to the given length above the baseline of its parent. A negative value is allowed.
Aligns the baseline of the element to the given percentage above the baseline of its parent, with the value being a percentage of the line-height property. A negative value is allowed.
Line-relative values
The following values vertically align the element relative to the entire line:
Aligns the top of the element and its descendants with the top of the entire line.
Aligns the bottom of the element and its descendants with the bottom of the entire line.
For elements that do not have a baseline, the bottom margin edge is used instead.
Values for table cells
baseline (and sub , super , text-top , text-bottom ,
Aligns the baseline of the cell with the baseline of all other cells in the row that are baseline-aligned.
Aligns the top padding edge of the cell with the top of the row.
Centers the padding box of the cell within the row.
Aligns the bottom padding edge of the cell with the bottom of the row.
Negative values are allowed.
Formal definition
Initial value | baseline |
---|---|
Applies to | inline-level and table-cell elements. It also applies to ::first-letter and ::first-line . |
Inherited | no |
Percentages | refer to the line-height of the element itself |
Computed value | for percentage and length values, the absolute length, otherwise the keyword as specified |
Animation type | a length |
Formal syntax
Examples
Basic example
HTML
div> An img src="frame_image.svg" alt="link" width="32" height="32" /> image with a default alignment. div> div> An img class="top" src="frame_image.svg" alt="link" width="32" height="32" /> image with a text-top alignment. div> div> An img class="bottom" src="frame_image.svg" alt="link" width="32" height="32" /> image with a text-bottom alignment. div> div> An img class="middle" src="frame_image.svg" alt="link" width="32" height="32" /> image with a middle alignment. div>
CSS
img.top vertical-align: text-top; > img.bottom vertical-align: text-bottom; > img.middle vertical-align: middle; >
Result
Vertical alignment in a line box
HTML
p> top: img style="vertical-align: top" src="star.png" alt="star"/> middle: img style="vertical-align: middle" src="star.png" alt="star"/> bottom: img style="vertical-align: bottom" src="star.png" alt="star"/> super: img style="vertical-align: super" src="star.png" alt="star"/> sub: img style="vertical-align: sub" src="star.png" alt="star"/> p> p> text-top: img style="vertical-align: text-top" src="star.png" alt="star"/> text-bottom: img style="vertical-align: text-bottom" src="star.png" alt="star"/> 0.2em: img style="vertical-align: 0.2em" src="star.png" alt="star"/> -1em: img style="vertical-align: -1em" src="star.png" alt="star"/> 20%: img style="vertical-align: 20%" src="star.png" alt="star"/> -100%: img style="vertical-align: -100%" src="star.png" alt="star"/> p>
#* box-sizing: border-box; > img margin-right: 0.5em; > p height: 3em; padding: 0 0.5em; font-family: monospace; text-decoration: underline overline; margin-left: auto; margin-right: auto; width: 80%; >
Result
Vertical alignment in a table cell
HTML
table> tr> td style="vertical-align: baseline">baselinetd> td style="vertical-align: top">toptd> td style="vertical-align: middle">middletd> td style="vertical-align: bottom">bottomtd> td> p> There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable. p> p> There is another theory which states that this has already happened. p> td> tr> table>
CSS
table margin-left: auto; margin-right: auto; width: 80%; > table, th, td border: 1px solid black; > td padding: 0.5em; font-family: monospace; >
Result
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jul 18, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.
Is There a Vr (Vertical Rule) in HTML
EDIT: It’s 2021 (twelve years after I answered this question), and I no longer think my original explanation is true:
(original explanation)
It does not make logical sense to have one. HTML is parsed
sequentially, meaning you lay out your HTML code from top to bottom,
left to right how you want it to appear from top to bottom, left to
right (generally)
A vr tag does not follow that paradigm.
I’m not sure why a VR tag was never introduced, but it’s likely not because of the way HTML is parsed — there are many different layout modes in HTML/CSS now that do not follow this «paradigm».
If I were to now speculate as to why there is no VR tag, I might look at MDN’s definition of the HR tag as a clue:
The HTML
element represents a thematic break between
paragraph-level elements: for example, a change of scene in a story,
or a shift of topic within a section.
In practice, however, the
tag often ends up used for things other than it’s semantic meaning. Although it may seem based on it’s real world use that there should be a tag, it probably would not resemble anything related to the semantic definition of the
tag. It was probably never thought to be introduced.
My hunch is that the creators would suggest that the domain of the solution for this problem lies in CSS, not HTML (and most of the answers to this SO question reflect that).
Nixinova’s solution looks like the most elegant and modern solution to this problem.
(The rest of my old answer follows below):
This is easy to do using CSS, however. Ex:
Note that you need to specify a height or fill the container with content.
How to make a vertical line in HTML
Put a around the markup where you want the line to appear to next, and use CSS to style it:
How do I make a
tag go vertically
This will require changes to more than just the hr. the element above and below it must be floated. the effect can be achieved with a solid border:
.section1 <
float: left;
width: 200px;
border-right: 1px solid #333;
>
.section2 <
float: left;
width: 200px;
>
Edit: see also this answer
Vertical hr tag
There is no «Vertical» hr tag. You can use «border-left» and «border-right» css properties to get such an effect.
Vertical rule (as opposed to
) in CSS
for this you basically need to setup a place to put it and a div statement works.
this could also be referenced:
.hr // in your css file/script
You can change the position and have it going up/down or left/right with css placement and z-index
.hr // in your css file/script
basically
width = how wide you want it
height = how tall you want it
background-color = is the color you want it to be
position = absolute, relative, float - basically if it stays in one place or moves with page content
top = where to place in reference to top of page - could be margin-top
left = where to place in reference to left of page - could be margin-left
hr elements vertically between buttons?
Not sure if this was the solution that you were looking for but I made a pen with the hr ‘joining the two buttons’.
The easiest way is to use absolute positioning as that allows the buttons to be dynamic, like this:
hr position: absolute;
width: 100%;
top: 0;
z-index: -1;
>
Hope this solves your problem!
vertical divider between two columns in bootstrap
If your code looks like this:
Then I’d assume you’re using additional DIVS within the «span6» DIVS for holding/styling your content? So.
So you could simply add some CSS to the «mycontent-left» class to create your divider.
.mycontent-left border-right: 1px dashed #333;
>
How to place a vertical hr line beside two images in html
I replaced your hr with a div , and adjusted the widths of the images so that the div would fit.
Also the border solution didn’t work here due to your percentage widths, which would get more than 100% size and push the second image down.
.img1 < min-width: 100%; >
.bikeimg < width: 49.9%; height: 350px; margin-top: -8px; margin-left: 0px; float: left; >
.bike < text-align: center; >
.coins < width: 49.9%; height: 350px; display:inline-block; float: right; margin-top: -8px; >
.title < text-align: center; font-size: 80px; font-family: 'Oswald', sans-serif; margin-top: -320px; text-decoration: underline; >
.vertical-hr < margin-top: -8px; width:0.2%; height: 350px; float:left; background-color:black;>.hr_first < margin-top: 200px;>
Codre Blog
Я думаю, многие из вас, кому приходилось заниматься версткой, сталкивались с необходимостью выравнивать элементы по вертикали и знают, какие сложности возникают при выравнивании элемента по центру.
Да, для вертикального выравнивания в CSS есть специальное свойство vertical-align с множеством значений. Однако на практике оно работает совсем не так, как ожидается. Давайте попробуем в этом разобраться.
Сравним следующие подходы. Выравнивание с помощью:
- таблицы,
- отступов,
- line-height ,
- растягивания,
- отрицательного margin ,
- transform ,
- псевдоэлемента,
- flexbox .
В качестве иллюстрации рассмотрим следующий пример.
Есть два элемента div , при этом один из них вложен в другой. Дадим им соответствующие классы − outer и inner .
Задача состоит в том, чтобы выровнять внутренний элемент по центру внешнего элемента.
Для начала рассмотрим случай, когда размеры внешнего и внутреннего блока известны. Добавим внутреннему элементу правило display: inline-block , а внешнему − text-align: center и vertical-align: middle .
Нпомню, что выравнивание применяется только к элементам, которые имеют режим отображения inline или inline-block .
Зададим блокам размеры, а также фоновые цвета, чтобы видеть их границы.
После применения стилей мы увидим, что внутренний блок выровнялся по горизонтали, а по вертикали нет:
http://jsfiddle.net/c1bgfffq/
Почему так произошло? Дело в том, что свойство vertical-align влияет на выравнивание самого элемента, а не его содержимого(кроме случаев, когда оно применяется к ячейкам таблицы). Поэтому применение данного свойства к внешнему элементу ничего не дало. Более того, применение этого свойства к внутреннему элементу также ничего не даст, поскольку строчные блоки ( inline-block ) выравниваются по вертикали относительно соседних блоков, а в нашем случае у нас один строчный блок.
Для решения данной проблемы существует несколько техник. Ниже подробнее рассмотрим каждую из них.
Выравнивание с помощью таблицы
Первое приходящее на ум решение − заменить внешний блок таблицей из одной ячейки. В этом случае выравнивание будет применяться к содержимому ячейки, то есть к внутреннему блоку.