숨겨진 오버플로가있는 범위에서 점 (“…”)을 표시하려면 어떻게해야합니까?
내 CSS :
#content_right_head span
{
display:inline-block;
width:180px;
overflow:hidden !important;
}
이제 컨텐츠 컨텐츠를 보여주고 있습니다
하지만 콘텐츠 콘텐츠 처럼 보여주고 싶습니다 ...
내용 뒤에 점을 표시해야합니다. 데이터베이스에서 컨텐츠가 동적으로 제공됩니다.
이를 위해 text-overflow: ellipsis;
속성 을 사용할 수 있습니다 . 이렇게 쓰세요
span {
display: inline-block;
width: 180px;
white-space: nowrap;
overflow: hidden !important;
text-overflow: ellipsis;
}
<span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book</span>
text-overflow : ellipsis를 사용하는 경우 브라우저는 해당 컨테이너 내에서 가능한 모든 내용을 표시합니다. 그러나 점 앞에 문자 수를 지정하거나 일부 내용을 제거하고 점을 추가하려면 아래 기능을 사용할 수 있습니다.
function add3Dots(string, limit)
{
var dots = "...";
if(string.length > limit)
{
// you can also use substr instead of substring
string = string.substring(0,limit) + dots;
}
return string;
}
처럼 전화
add3Dots("Hello World",9);
출력
Hello Wor...
여기에서 실제로 확인하십시오
function add3Dots(string, limit)
{
var dots = "...";
if(string.length > limit)
{
// you can also use substr instead of substring
string = string.substring(0,limit) + dots;
}
return string;
}
console.log(add3Dots("Hello, how are you doing today?", 10));
나는 당신이 찾고있는 생각 text-overflow: ellipsis
과 함께white-space: nowrap
이 시도,
.truncate {
display:inline-block;
width:180px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.truncate
요소 에 클래스를 추가 하십시오.
편집 ,
Above solution is not working in all the browsers. you can try following jQuery plugin with cross browser support.
(function ($) {
$.fn.ellipsis = function () {
return this.eachAsync({
delay: 100,
bulk: 0,
loop: function (index) {
var el = $(this);
if (el.data("fullText") !== undefined) {
el.html(el.data("fullText"));
} else {
el.data("fullText", el.html());
}
if (el.css("overflow") == "hidden") {
var text = el.html();
var t = $(this.cloneNode(true))
.hide()
.css('position', 'absolute')
.css('overflow', 'visible')
.width('auto')
.height(el.height())
;
el.after(t);
function width() { return t.width() > el.width(); };
var func = width;
while (text.length > 0 && width()) {
text = text.substr(0, text.length - text.length * 25 / 100);
t.html(text + "...");
}
el.html(t.html());
t.remove();
}
}
});
};
})(jQuery);
how to call,
$("#content_right_head span").ellipsis();
Well, the "text-overflow: ellipsis" worked for me, but just if my limit was based on 'width', I has needed a solution that can be applied on lines ( on the'height' instead the 'width' ) so I did this script:
function listLimit (elm, line){
var maxHeight = parseInt(elm.css('line-Height'))*line;
while(elm.height() > maxHeight){
var text = elm.text();
elm.text(text.substring(0,text.length-10)).text(elm.text()+'...');
}
}
And when I must, for example, that my h3 has only 2 lines I do :
$('h3').each(function(){
listLimit ($(this), 2)
})
I dunno if that was the best practice for performance needs, but worked for me.
You can try this:
.classname{
width:250px;
overflow:hidden;
text-overflow:ellipsis;
}
var tooLong = document.getElementById("longText").value;
if (tooLong.length() > 18){
$('#longText').css('text-overflow', 'ellipsis');
}
Thanks a lot @sandeep for his answer.
My problem was that I want to show / hide text on span with mouse click. So by default short text with dots is shown and by clicking long text appears. Clicking again hides that long text and shows short one again.
Quite easy thing to do: just add / remove class with text-overflow:ellipsis.
HTML:
<span class="spanShortText cursorPointer" onclick="fInventoryShippingReceiving.ShowHideTextOnSpan(this);">Some really long description here</span>
CSS (same as @sandeep with .cursorPointer added)
.spanShortText {
display: inline-block;
width: 100px;
white-space: nowrap;
overflow: hidden !important;
text-overflow: ellipsis;
}
.cursorPointer {
cursor: pointer;
}
JQuery part - basically just removes / adds class cSpanShortText.
function ShowHideTextOnSpan(element) {
var cSpanShortText = 'spanShortText';
var $el = $(element);
if ($el.hasClass(cSpanShortText)) {
$el.removeClass(cSpanShortText)
} else {
$el.addClass(cSpanShortText);
}
}
참고URL : https://stackoverflow.com/questions/11426275/how-can-i-show-dots-in-a-span-with-hidden-overflow
'development' 카테고리의 다른 글
날짜 객체에 대한 prop 소품 유효성 검사 (0) | 2020.06.13 |
---|---|
하스켈에서 줄을 나누는 방법? (0) | 2020.06.12 |
Git 브랜치의 커밋 수 계산 (0) | 2020.06.12 |
값이 null이 아닌 DataTrigger? (0) | 2020.06.12 |
Perl의 배열에서 중복 항목을 어떻게 제거합니까? (0) | 2020.06.12 |