【问题标题】:How do I remove this space in Ionic app如何在 Ionic 应用程序中删除此空间
【发布时间】:2017-07-18 18:11:04
【问题描述】:

我想用 .prof-cont 的类删除头像和我的 div 之间的空间,它们都在 divmaincontent 的类我尝试使用 no-padding 不工作我的课程仍然是同样的问题,我做错了什么我的视图和 sass 文件的代码。这是一个 Ionic 3 项目。

查看

<ion-content>
    <div class="profile">
    </div> 
    <div class="maincontent">
        <ion-avatar no-padding> 
            <img src="../assets/profile/profilesnap.png" class="dp"> 
        </ion-avatar> 
        <div class="prof-cont">
            <h2 text-center>John Doe</h2>
            <p text-center padding>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae ipsa fuga cupiditate quos doloremque nulla ex a, rerum, eos nesciunt dolorum excepturi unde dolores nam.</p> 
        </div> 
        <!--Segments  -->
        <div padding>
            <ion-segment [(ngModel)]="profile">
                <ion-segment-button value="service">
                    Service
                </ion-segment-button>
                <ion-segment-button value="review">
                    Review
                </ion-segment-button>
            </ion-segment>
        </div>
        ....
<ion-content> 

对于我的 SASS 文件

page-instraprofile {
    .scroll-content{
        // text-align: center;
        // display: flex;
        // flex-direction: column;
        // justify-content: center;
        // text-align: center;
    }

    .profile{
        // background-image: url('../assets/bg@3x.png');

        background-repeat: no-repeat;
        background-size: cover;
        height: 30%;
    }

    .maincontent{
        background-color: aqua;
    }

    .dp{
        position: relative;
        left: 50%;
        transform: translate(-50%,-50%);
        // z-index: 10;
    }

    ion-avatar{
        img{}
    }

    .prof-cont{
        height: 100%;
        color: red;
        padding-top: 0 !important;
        background-color: yellow;

        h2{
            color: green;
        }
    }
}

【问题讨论】:

  • 这主要是您的&lt;h2&gt; 默认边距。您可能需要重置这些。
  • 我不这么认为我的自定义类“prof-cont”的背景是黄色的,我必须将它拉到头像图像。如果我将 h2 更改为填充 0,它在“prof-cont”类中仍然是相同的,而不是在“maincontent”中,颜色为 aqua。

标签: javascript css angular ionic2 flexbox


【解决方案1】:

这里的主要问题是transform: translate()

它将图像一半的高度移向顶部(translate(-50%,-50%) 中的第二个参数沿其 y 轴重新定位元素),但这只会发生从视觉上看,这意味着它在技术上仍然处于文档流中的原始位置。 (见下图)

为了保持文档的动态流动,并且由于图像包装器&lt;ion-avatar no-padding&gt; 出现的目的是将图像固定到位,将其高度降低到图像高度的一半左右,它仍然会将图像定位在它所在的位置是现在,尽管以下元素会向上移动。

即:

ion-avatar{
  height: 60px;        /*  adjust this value to control the distance to the text  */
}

【讨论】:

  • 哇,这个LGSon就这么多,它解决了这个问题。我花了一天多的时间试图修复这个错误,但徒劳无功,再次感谢。
猜你喜欢
  • 1970-01-01
  • 2017-04-30
  • 2014-10-13
  • 2015-10-07
  • 1970-01-01
  • 1970-01-01
  • 2018-09-28
  • 2018-02-26
  • 1970-01-01
相关资源
最近更新 更多