Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply "text-overflow: ellipsis;" to inner div

Tags:

html

css

I have a div structure similar to following image. image 1

I need to apply "text-overflow: ellipsis;" to text in this div structure in smaller windows.(image 2)

image 2

But it didn't apply as I expect. this is my HTML code

    .header {
		height: 60px;
		width: 100%;
	}
	.header > .header_middle {
		margin: 0 auto;
		width: 100%;
	}
	.header > .header_middle.share-file-header > .caption {
		float: left !important;
		line-height: 60px;
		overflow: hidden;
		padding-right: 0 !important;
		text-overflow: ellipsis;
		white-space: nowrap;
		padding: 0 30px;
	}
	.header > .header_middle.share-file-header .settings {
		line-height: inherit;
		padding: 0 15px 0 0;
		float: right;
		height: 60px;
		position: relative;
	}
	.shared-person-detail-wrapper {
		display: inline-block;
		overflow: hidden;
		text-overflow: ellipsis;
		line-height: inherit;
	}
	.settings .share-files-msg, .settings .shared-person {
		display: block;
		font-size: 14px;
		text-overflow: ellipsis;
	}
	.settings .more-persons-wraper {
		display: inline-block;
		position: relative;
	}
    <div class="header">
    <div class="header_middle share-file-header">
        <div class="caption">
            <p>
                <a href="/">
                    <img src="/resources/Image1.png" alt="Image 1" title="Image 1">
                </a>
            </p>
        </div>
        <div class="settings">
            <div class="shared-person-detail-wrapper">
                <div class="shared-person">
                    User Name <a href="mailto:[email protected]">([email protected])</a>
                </div>
                <div class="share-files-msg">
                    has shared file(s) with you
                    <div class="more-persons-wraper">and some <a href="#" data-toggle="dropdown" id="more">more</a> people.
                        <ul class="dropdown-menu pull-right" id="more-persons">
                            <li>[email protected]</li>
						</ul>
                    </div>
                </div>
            </div>
            <div class="share-icon"><img src="/resources/Image2.png" alt="Image 2" title="Image 2"></div>
        </div>
    </div>
</div>

What is the wrong with this code, can any one give me a guide ?? thank you

like image 239
indrarajw Avatar asked Dec 14 '16 10:12

indrarajw


People also ask

How do I force text-overflow ellipsis?

Inline overflow occurs when the text in a line overflows the available width without a breaking opportunity. To force overflow to occur and ellipses to be applied, the author must apply the nowrap value to the white-space property on the element, or wrap the content in a <NOBR> tag.

Why does text-overflow ellipsis doesn't work?

text-overflow: ellipsis only works when the following is true: Parent element is not set to display: inline (span's default,) You must use display: block or display: inline-block. The element's width must be constrained in px (pixels) – it doesn't work with values specified using % (percent.)

How do you text-overflow ellipsis in a table?

To make an ellipsis work on a table cell, you can use the CSS display property set to its "block" or "inline-block" value. In our example below, besides the display property, we set the text-overflow to "ellipsis", use the "nowrap" value of the white-space property, set the overflow to "hidden".


1 Answers

In order for an element to have overflow as elipsis you need to set these CSS rules on it:

white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 60px; #(any width would do)

Here is a jsfiddle where I have added these on the .shared-person class. https://jsfiddle.net/3dukmv5q/

like image 95
knaos Avatar answered Oct 25 '22 11:10

knaos