简体   繁体   English

如何从不同的组件在angular2中设置CSS样式,以便它们彼此完全匹配?

[英]How to style css in angular2 from different component so they can well suited each other?

i trying to create a sub component of angular2 css well suited each other? 我试图创建一个适合彼此的angular2 css的子组件? here is my problem, when i create a sub component and then i called my component with the selector, my css that bigger than the other component hidden in side my selector component, here is my project structur : 这是我的问题,当我创建一个子组件,然后用选择器调用我的组件时,我的css比隐藏在选择器组件旁边的其他组件大,这是我的项目结构: 在此处输入图片说明

then here is my home.html : 这是我的home.html:

<div class="row">
  <div class="homecarousel-recent-offer col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
    <carouselItemsme></carouselItemsme>
  </div>
</div>

that's how i call my sub component, then here is come my problem 这就是我所谓的子组件的方式,那么这就是我的问题 在此处输入图片说明

here is the look of my tooltip html get hidden in side the component, here is my carouselItems.scss : 这是隐藏在组件旁边的我的工具提示html的外观,这是我的carouselItems.scss:

.carousel-recent-offers {
position:relative;
}

.carousel-recent-offers .next-carousel, .carousel-recent-offers .previous-carousel {
    outline: 0;
    -webkit-transition: background 0.2s ease-in-out;
    transition: background 0.2s ease-in-out;
    background-color: rgba(234,235,236,0.7);
    height: 100%;
    color: #70747c;
    box-shadow: none;
    -webkit-transition: opacity 0.2s ease-in-out;
    -moz-transition: opacity 0.2s ease-in-out;
    -ms-transition: opacity 0.2s ease-in-out;
    transition: opacity 0.2s ease-in-out;
    position: absolute;
    top: 0px;
}

    .next-carousel, .previous-carousel{
        box-sizing: border-box;
        padding: 0;
        width: 36px;
        line-height: 38px;
        height: 38px;
        font-size: 14px;
        font-weight: bold;
        color: #70747c;
        text-align: center;
        text-shadow: none;

        z-index: 2;
        border: none;


    }

    .next-carousel {
        right: 0;
    }

    .previous-carousel:hover {
      opacity: 0.5;
    }
    .next-carousel:hover {
      opacity: 0.5;
    }

    .offer--carousel {
        display: inline-block;
        //height: 285px;
        background-color: #ffffff;
        border: 1px solid #d3d3d3;
        border-radius: 2px;
        position: relative;
    }

    /* Tooltip text */
    .offer--carousel .tooltiptext {
        visibility: hidden;
        width: auto;
        background-color: white;
        color: #000000;
        text-align: center;
        padding: 15px;
        border-radius: 6px;

        /* Position the tooltip text - see examples below! */
        position: absolute;
        top: 0px;
        left: 105%; 
        z-index: 9000;
    }

    .offer--carousel .tooltiptext::after {
        content: " ";
        position: absolute;
        top: 50%;
        right: 100%;
        margin-top: -5px;
        border-width: 5px;
        border-style: solid;
        border-color: transparent white transparent transparent;
    }

    .offer--carousel:hover .tooltiptext {
        visibility: visible;
    }

    a img {
        width: 100%;
        height: 140px;
    }

    .offer--carousel .offer__details {
        padding: 10px;
    }

    .offer--carousel .offer__title {
        max-height: 40px;
        color: #006cb7;
        font-size: 14px;
        font-weight: normal;
        line-height: 20px;
        text-overflow: inherit;
        white-space: normal;
    }

    .offer__title, .offer__subtitle {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .offer__subtitle {
        color: #212121;
    }

.rating--carousel
    .rating--carousel .rating__reviews {
        color: #b9bcc2 !important;
    }
    .rating__value, .rating__reviews {
        display: block;
    }
    .rating--carousel .rating__value, .rating--carousel .rating__reviews {
        color: #212121;
        font-size: 14px;
        font-weight: normal;
    }

    .price--mini-dark {
        top: 1px;
        right: 1px;
        padding: 5px;
        color: #ffffff;
        background-color: rgba(2,21,33,0.8);
        position: absolute;
        text-align: right;
    }
    .price--mini-dark .price__tag {
        font-size: 20px;
        color: #ffffff;
    }
    .price--mini-dark .price__info {
        font-size: 12px;
        line-height: 1.5;
    }

how can i make my tooltip get outside the selector area if the tooltip box is big and have many content in it? 如果工具提示框很大并且其中包含很多内容,我该如何使工具提示移出选择器区域?

UPDATE : you guys can just focus on this css code, here is how i use to create a tooltip 更新:你们可以只专注于此CSS代码,这是我用来创建工具提示的方式

.offer--carousel {
    display: inline-block;
    //height: 285px;
    background-color: #ffffff;
    border: 1px solid #d3d3d3;
    border-radius: 2px;
    position: relative;
}

.offer--carousel .tooltiptext {
    visibility: hidden;
    width: auto;
    background-color: white;
    color: #000000;
    text-align: center;
    padding: 15px;
    border-radius: 6px;

    position: absolute;
    top: 0px;
    left: 105%; 
    z-index: 9000;
}

.offer--carousel .tooltiptext::after {
    content: " ";
    position: absolute;
    top: 50%;
    right: 100%;
    margin-top: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: transparent white transparent transparent;
}

.offer--carousel:hover .tooltiptext {
    visibility: visible;
}

and here is my carouselItems.html 这是我的carouselItems.html

<ks-swiper-slide *ngFor="let s of data; let i = index" >
    <a class="offer--carousel" [routerLink]="['/course-detail', s._id]" routerLinkActive="active">
      <div class="offer-image__column">
        <img [src]="s.courseLandingPage.course_image">
      </div>
      <div class="offer-details__column">
        <div class="offer__details">
          <h3 class="offer__title">
            {{s.courseLandingPage.course_title}}
          </h3>
          <div class="offer__subtitle">
            {{s.courseLandingPage.course_subtitle}}
          </div>
          <div class="offer__rating">
            <div class="rating--carousel">
              <span class="rating__value">9.4 Excellent</span>
              <span class="rating__reviews">(44 reviews)</span>
            </div>
          </div>
        </div>
        <div class="price--mini-dark">
          <div class="price__tag">
            {{s.price_coupons.price}}
          </div>
        </div>
      </div>
      <div class="tooltiptext">
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
        <div>ksadjfkljsalfjdsakldfa</div>
      </div>
    </a>
</ks-swiper-slide>

Notes : i use ks-swiper-slide for the slider, can be the ks-swiper-slide is the problem? 注意:我将ks-swiper-slide用于滑块,请问ks-swiper-slide是问题吗?

The thing is your tooltip is inside .offer--carousel and it will not get outside its parent if you use absolute and the parent(s) has a style of overflow: hidden as the position you have to use fixed for that and it will harder to manage . 关键是您的工具提示位于.offer--carousel内部,如果您使用absolute ,并且父代具有overflow: hidden样式,它将不会超出其父代 overflow: hidden为您必须为此使用fixed的位置,它将难以管理 In this case, can I suggest a better jQuery plugin for this: 在这种情况下,我可以为此建议一个更好的jQuery插件

I will go with Tooltipster if I were you. 如果我是我,我将选择Tooltipster It has many customize option as well.Hope this helps you ty. 它还具有许多自定义选项。希望这可以帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM