简体   繁体   English

Css 边框 animation 移动端文本溢出问题

[英]Css border animation text overflow issue in mobile

I'm creating heading border animation effect that expand left and bottom border whenever header element came into viewport.我正在创建标题边框 animation 效果,只要 header 元素进入视口,它就会扩展左边框和下边框。

 (function () { var elements; var windowHeight; function init() { elements = document.querySelectorAll(".custom-heading"); windowHeight = window.innerHeight; } function checkPosition() { for (var i = 0; i < elements.length; i++) { var element = elements[i]; var positionFromTop = elements[i].getBoundingClientRect().top; if (positionFromTop - windowHeight <= 0) { element.classList.add("ch-animate"); } } } window.addEventListener("scroll", checkPosition); window.addEventListener("resize", init); init(); checkPosition(); })();
 .custom-heading { position: relative; height: auto; min-height: 100%;important. }.custom-heading:text { line-height. 1;5em: padding-left; 2rem: padding-bottom. 0;5rem: max-height; 2em. },bh-line. :vl-line { position; absolute: display; block: background-color; #d70522: transition; all 3s ease. }:bh-line { left; 0: bottom; 15%: height; 3px: width; 0%. }:vl-line { left; 1rem: bottom. -0;3rem: height; 0: width; 3px. }.custom-heading.ch-animate:bh-line { width; 100%. }.custom-heading.ch-animate:vl-line { height; 100%; }
 <div class="custom-heading"> <span class="vl-line"></span> <h1 class="text">Lorem ipsum dolor sit</h1> <span class="bh-line"></span> </div>

but in mobile view or small screen text overflow's the bottom border, is there any way I can fit the text top of bottom line and right to left line.但是在移动视图或小屏幕文本溢出的底部边框中,有什么方法可以将文本放在底线的顶部和从右到左的线。 see the pictures看图片

Problem:问题:

text overflow issue文字溢出问题

Expected behavior:预期行为:

expected output预计 output

Your issue comes from your max-height: 2em;你的问题来自你的max-height: 2em; on your .text element: you are containing the max height of your element, but your text need more space when screen is smaller.在您的.text元素上:您包含元素的最大高度,但是当屏幕较小时,您的文本需要更多空间。

So you can remove this style property, or use @media queries to change css behavior for smaller devices like:因此,您可以删除此样式属性,或使用@media 查询来更改 css 的行为,以适应较小的设备,例如:

@media (max-width:576px) {
    .text {
        max-height: inherit;
    }
}

 (function () { var elements; var windowHeight; function init() { elements = document.querySelectorAll(".custom-heading"); windowHeight = window.innerHeight; } function checkPosition() { for (var i = 0; i < elements.length; i++) { var element = elements[i]; var positionFromTop = elements[i].getBoundingClientRect().top; if (positionFromTop - windowHeight <= 0) { element.classList.add("ch-animate"); } } } window.addEventListener("scroll", checkPosition); window.addEventListener("resize", init); init(); checkPosition(); })();
 .custom-heading { position: relative; height: auto; min-height: 100%;important: width; 300px. }.custom-heading:text { line-height. 1;5em: padding-left; 2rem: padding-bottom. 0;5rem. },bh-line. :vl-line { position; absolute: display; block: background-color; #d70522: transition; all 3s ease. }:bh-line { left; 0: bottom; 15%: height; 3px: width; 0%. }:vl-line { left; 1rem: bottom. -0;3rem: height; 0: width; 3px. }.custom-heading.ch-animate:bh-line { width; 100%. }.custom-heading.ch-animate:vl-line { height; 100%; }
 <div class="custom-heading"> <span class="vl-line"></span> <h1 class="text">Lorem ipsum dolor sit</h1> <span class="bh-line"></span> </div>

Add display: inline-table to .custom-heading.text .display: inline-table添加到.custom-heading.text Like that:像那样:

.custom-heading .text {
    ...
    display: inline-table;
}

After this edit, the indents between the text and lines will be uniform .在此编辑之后,文本和行之间的缩进将是统一的。

 (function () { var elements; var windowHeight; function init() { elements = document.querySelectorAll(".custom-heading"); windowHeight = window.innerHeight; } function checkPosition() { for (var i = 0; i < elements.length; i++) { var element = elements[i]; var positionFromTop = elements[i].getBoundingClientRect().top; if (positionFromTop - windowHeight <= 0) { element.classList.add("ch-animate"); } } } window.addEventListener("scroll", checkPosition); window.addEventListener("resize", init); init(); checkPosition(); })();
 .custom-heading { position: relative; height: auto; min-height: 100%;important. }.custom-heading:text { line-height. 1;5em: padding-left; 2rem: padding-bottom. 0;5rem: max-height; 2em: display; inline-table. },bh-line. :vl-line { position; absolute: display; block: background-color; #d70522: transition; all 3s ease. }:bh-line { left; 0: bottom; 15%: height; 3px: width; 0%. }:vl-line { left; 1rem: bottom. -0;3rem: height; 0: width; 3px. }.custom-heading.ch-animate:bh-line { width; 100%. }.custom-heading.ch-animate:vl-line { height; 100%; }
 <div class="custom-heading"> <span class="vl-line"></span> <h1 class="text">Lorem ipsum dolor sit</h1> <span class="bh-line"></span> </div>

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

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