Reputation: 874
I want to implement the android layout bellow via flexbox.
android layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400px"
android:layout_height="200px"
android:background="#0ee"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"/>
</LinearLayout>
<View
android:layout_width="100px"
android:layout_height="50px"
android:background="@color/red" />
</LinearLayout>
How to change the code below to achieve the effect above?
ps: If I specified the width of the vertical
class, it works, is there another way to achieve this?
<html>
<header>
<style>
.container {
width: 400px;
height: 200px;
display: flex;
flex-direction: row;
align-items: center;
background: teal;
}
.vertical {
display: flex;
/* width: 100px; I don't want to specify the width*/
flex: 1;
flex-direction: column;
}
p {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.button {
width: 100px;
height: 50px;
background: red;
}
</style>
</header>
<body>
<div class="container">
<div class="vertical">
<p>TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT</p>
<p>TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT</p>
</div>
<div class="button">
</div>
</div>
</body>
</html>
Upvotes: 0
Views: 1587
Reputation: 184
You need to add min-width: 0;
to the .vertical
element
<html>
<header>
<style>
.container {
width: 400px;
height: 200px;
display: flex;
flex-direction: row;
align-items: center;
background: teal;
}
.vertical {
display: flex;
min-width: 0;
flex: 1;
flex-direction: column;
}
p {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.button {
width: 100px;
height: 50px;
background: red;
}
</style>
</header>
<body>
<div class="container">
<div class="vertical">
<p>TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT</p>
<p>TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT</p>
</div>
<div class="button">
</div>
</div>
</body>
</html>
https://codepen.io/withn/pen/RwwOmKm
The issue has to do with the way text is wrapped in flexbox children.
More info here: https://css-tricks.com/flexbox-truncated-text/
Upvotes: 1