HTML-当div(工具提示)到达视口末端时,自动将其位置更改为左侧



我已经使用css在右侧位置为两个div提供了工具提示。当到达视口的末端时,当工具提示显示时,我得到水平滚动。如何更改自动将工具提示向左放置的行为?我有角码app.component.css如下

p {
font-family: Lato;
}

.swidth {
position: relative;
cursor: pointer;
}

.swidth:hover .type-text {
display: block;
}
.type-text {
display: none;
position: absolute;
background: #939393;
border: 4px solid #939393;
left: 125%;
top: -12px;
padding: 4px;
border-radius: 5px;
width: 152px;
font-size: 12px;
color: #cccccc;
z-index: 1;
}
.pb-mb-3 {
padding-bottom: 3px;
margin-bottom: 3px;
}
.type-text:after,
.type-text:before {
right: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.border-bottom-grey {
border-bottom: 1px solid #cccccc;
}
/* .type-text:after {
border-color: rgba(116, 129, 149, 0);
border-right-color: #748195;
border-width: 30px;
margin-top: -30px;
} */
.type-text:before {
border-color: rgba(116, 129, 149, 0);
border-right-color: #939393;
border-width: 10px;
margin-top: -11px;
}
.card {
position: relative;
}

在app.component.html中,我有如下代码

<div class="viewContent" style="display:inline-block">
<div class="text-center swidth iconbdr view-type">
<div class="type-text ">
<div class="border-bottom-grey pb-mb-3">Technology
</div>
<div>Business </div>
</div>
<div class="view-count" style="margin-top:5px">view
</div>
<div class=" view-count">
<span class="secondaryInfo d-inline-block pb-0">123</span>
</div>
</div>
</div>
<div class="viewContent " style="display:inline-block;margin-left:270px">
<div class="text-center swidth iconbdr view-type">
<div class="type-text ">
<div class="border-bottom-grey pb-mb-3">Technology
</div>
<div>Business </div>
</div>
<div class="view-count" style="margin-top:5px">view
</div>
<div class=" view-count">
<span class="secondaryInfo d-inline-block pb-0">123</span>
</div>
</div>
</div>

Stacklitz链接在这里:https://stackblitz.com/edit/angular-cmopwb

提前感谢

不是最好的解决方案,但作为想法,我在css中创建了新的类,然后我在窗口宽度和元素宽度之间进行检测,然后我将其用作appcomponent 中的类

https://stackblitz.com/edit/angular-ihsaj1

在apcomponent 中

innerwidth=window.innerWidth;
@HostListener('window:resize', ['$event'])
onResize(event) {
console.log("girdi");
this.innerwidth = window.innerWidth;
}
constructor(private _el: ElementRef){}
getClass(ref){
if(ref._el.nativeElement.offsetWidth+186>=this.innerwidth){return "type-text-left";}
}

在html中,我用作类名

<div class="type-text {{getClass(this)}}  type">

在css中,我为type text left 编写

最新更新