2017-09-21 28 views
0

另一個DIV一個div我有標記,像這樣:下面放置使用Flexbox的

HTML:

<ListElementRoot> 
    <ListElementText> 
    {children} 
    </ListElementText> 
    <ListElementDescription> 
    {description} 
    </ListElementDescription> 
</ListElementRoot> 

//platform.web.js

export const ListElementRoot = div(style.root) 
export const ListElementIcon = div(style.icon) 
export const ListElementText = div(style.text) 
export const ListElementDescription = div(style.description) 

// CSS

.root { 
    display: flex; 
    width: 100%; 
    height: 56px; 
    align-items: center; 
    border-top: 1px solid var(--color-gray2); 
    padding: 0; 
} 

.icon { 
    position: absolute; 
    width: 28px; 
    height: 28px; 
    align-items: center; 
    padding-left: 18px; 
} 

.text { 
    color: #000; 
    font-size: calc(var(--font-size-body)/10)rem; 
    padding-left: 64px; 
} 

.description { 
    color: #000; 
    font-size: calc(var(--font-size-body)/12.3)rem; 
    padding-left: 64px; 
} 

我是flexbox的新手。 我該如何製作元素?

我試圖找到一個解決方案,但它在我的flexbox(現在)嚴重扭曲。有任何想法嗎?

編輯:

沒有flex-direction:column;

enter image description here

隨着撓曲方向:柱;

enter image description here

+0

由於絕對定位工作不一致跨瀏覽器的,哪裏是'icon'的標記,它的'align- items:center;'是假設在容器上,而不是flex項目,所以它容納了一些你需要居中的東西? – LGSon

回答

2

你需要有一個flex-direction屬性設置爲column爲您flex容器(.root)。

Here你可以找到一個jsfiddle的例子。

編輯: 更改align-items: center是爲了具備的要素align-items: flex-start靠左對齊,

+1

非常感謝! –