[英]Vertically align inline, inline-block, and block elements
I have dynamically rendered elements that I need to align vertically. 我有动态渲染的元素,我需要垂直对齐。 I only have editing control over the parent.
我只对父级进行编辑控制。
The elements don't have any white space or line break inbetween them. 元素之间没有任何空格或换行符。
I have tried with flex
, but the block
items contract. 我尝试过
flex
,但block
项目合同。 I have added a style attribute on the block
elements to examplify this: 我在
block
元素上添加了一个style属性来举例说明:
.parent { display: flex; flex-direction: column; align-items: flex-start; }
<div class="parent"> <span>ITEM1</span><span>ITEM2</span><div style="background:pink;">ITEM3</div><div style="background:pink;">ITEM4</div><button>ITEM5</button><button>ITEM6</button> </div>
As per Temani Afif's comment , the following is a working solution: 根据Temani Afif的评论 ,以下是一个有效的解决方案:
.parent { display: flex; flex-direction: column; align-items: flex-start; } /* Setting all common block elements to width: 100% */ .parent > div, .parent > h1, .parent > h2, .parent > h3, .parent > h4, .parent > h5, .parent > h6 .parent > ol, .parent > ul, .parent > pre, .parent > address, .parent > blockquote, .parent > dl, .parent > fieldset, .parent > form, .parent > hr, .parent > noscript, .parent > table { width:100% }
<div class="parent"> <span>ITEM1</span><span>ITEM2</span><div style="background:pink;">ITEM3</div><div style="background:pink;">ITEM4</div><button>ITEM5</button><button>ITEM6</button> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.