Flexbox布局和图像高度调整大小

时间:2018-07-14 17:23:23

标签: css responsive-design flexbox

嗨,我有一个flexbox布局,其中有一个页眉,内容和页脚。除了图像的缩放比例之外,其他所有功能都可以正常工作。 我希望图像在内容的高度上也能缩放,但是出于任何原因页脚都将其重叠。

它是这样的:

body {
  margin: 0;
}

.modal {
  display: flex;
  height: 100vh;
  width: 100vw;
  flex-direction: column;
  background: green;
}

.projectHeadline,
.projectFooter {
  background: yellow;
  height: 100px;
}

.swiper-container {
  display: flex;
  flex: auto;
  margin: auto;
  background: red;
  height: 100%;
}

.swiper-wrapper {
  margin: auto;
  height
  background: black;
}

.swiper-wrapper img {
  display: block;
  width: 100%;
  height: auto;
}
<div class="modal">
  <div class="projectHeadline">Headline</div>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <img src="http://via.placeholder.com/350x450">
    </div>
  </div>
  <div class="projectFooter">Footer</div>
</div>

1 个答案:

答案 0 :(得分:1)

您溢出了。您可以像这样纠正它:

    Alert alert = new Alert(AlertType.ERROR);
    alert.setTitle("Error Dialog");
    alert.setHeaderText("Look, an Error Dialog");
    alert.setContentText("Ooops, there was an error!");
    alert.showAndWait();
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main2Activity"
android:background="@drawable/ic_launcher_background"
android:padding="5dp"
android:weightSum="10"
android:orientation="vertical">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="vertical">

    <TextView
        android:id="@+id/amHeading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="0dp"
        android:fontFamily="casual"
        android:text="Your Record"
        android:layout_gravity="center"
        android:textStyle="bold"
        android:textColor="@android:color/white"
        android:textSize="28sp"
        />


    <TextView
        android:id="@+id/totalLectures"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="0dp"
        android:text="Total Lectures Delivered : 10"
        android:textColor="@android:color/white"
        android:textSize="15sp"
        />
  </LinearLayout>

  <ListView
    android:id="@+id/attendancRrecordList"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="7"
    android:background="@color/colorPrimary"
   />
<Button
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:text="asdasd"
    android:layout_weight="1"
    android:textColor="@color/colorPrimary"/>
</LinearLayout>