CSS How to force DIVs side by side with text overflow? - html

I need force 2 divs side by side as it below in example :
#colwrap{
overflow:hidden;
background-color: orange;
width:300px;
}
#colLeft {
height: 48px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#colRight {
background-color: #c3d0ff;
height: 48px;
float: right;
}
//This is cool
<div id="colwrap">
<div id="colRight">icon1, icon2</div>
<div id="colLeft">Really long long long name of file.txt</div>
</div>
<br>
//But this is wrong :
<div id="colwrap">
<div id="colRight">icon1, icon2</div>
<div id="colLeft">Short name of file.txt</div>
</div>
//It should look like this, when text is shorter :
<div id="colwrap">
<div id="colLeft" style="float:left;">Short name of file.txt</div>
<div id="colRight" style="float:left">icon1, icon2</div>
</div>
fiddle : https://jsfiddle.net/2jno80ba/
!There is div contains name of file, on every end of file must be container for multiple icons, when text is larger, then container is fixed on end.1

you can use flex-box to achieve this.
check this pen out:
http://codepen.io/anon/pen/aOExbb
I just modified your css a bit:
#colwrap{
overflow:hidden;
background-color: orange;
width:300px;
display:flex;
flex-flow:row;
justify-content:flex-start;
}
#colLeft {
height: 48px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#colRight {
order:2;
background-color: #c3d0ff;
height: 48px;
float: right;
}
and here is a guide to flex-box

set the width of your divs as auto like #colleft{width:auto;}
https://jsfiddle.net/3v5jtcck/3/

Related

whitespace:nowrap - how can I truncate the overflowed text - rather than have it expand the element?

This plunker demonstrates what I'm trying and failing to do.
I have some simple HTML:
<div class = "fixed-width-div">
<label> hello world </label>
</div>
<div class ="fixed-width-div">
<label> adfkldjs sdklfjsdlkfjsdklfkj sdkfjsdlfjlsdkfj lsjdfklsdfjlsdjf lsdjfksdlfjskdf </label>
</div>
I don't want the long labels wrapping, nor do I want them overflowing or expanding the parent element.
label {
background-color: #ddd;
white-space: nowrap;
text-overflow: ellipsis;
}
.fixed-width-div {
width: 100px;
background-color: cyan;
padding: 5px;
margin-top: 15px;
}
How can I acheive this?
I suspect it's actually a difficult problem - as that text is in the DOM and has to go somewhere right?
Is this what you are after?
label {
background-color: #ddd;
}
.fixed-width-div {
width: 100px;
background-color: cyan;
padding: 5px;
margin-top: 15px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<div class="fixed-width-div">
<label>hello world</label>
</div>
<div class="fixed-width-div">
<label>adfkldjs sdklfjsdlkfjsdklfkj sdkfjsdlfjlsdkfj lsjdfklsdfjlsdjf lsdjfksdlfjskdf</label>
</div>
I'm not sure what exactly you are after here, but if you add:
overflow: hidden;
to your container div then it won't spill over or expand.
Now, I suspect you already know this and want to save your cyan padding-right of 5px. To do this, you need to add your labels to its own separate div with restricted width and then center that in your original container.
Hope this steers you down the right path.
Update with actual code:
.inner-container {
width: 95px;
overflow: hidden;
}
<div class ="fixed-width-div">
<div class="inner-container">
<label> adfkldjs sdklfjsdlkfjsdklfkj sdkfjsdlfjlsdkfj lsjdfklsdfjlsdjf lsdjfksdlfjskdf </label>
</div>
</div>

How to align two divs (one fixed and the other with break word attribute)?

I'm having problems with the attibute "word-wrap:break-word;" when trying to align horizontally with another DIV and its inside a DIV. Easy to understand my problem seeing this two examples:
#container {
height: auto;
overflow: hidden;
}
#left {
background-color: green;
width: 120px;
height: 20px;
overflow: hidden;
}
#right {
width: calc(100% - 120px);
float: right;
height: auto;
display: inline-block;
word-wrap: break-word;
background-color: red;
}
<div id="container">
<div id="right">AAAAAAAAAAAAAAAAAAAAA</div>
<div id="left"></div>
</div>
http://jsfiddle.net/galacticpower/a3nyxhtj/4/
Here, if the navigator is resized, the right div text is broken as needed! Yeah!
Adding a div inside the right div and its style comes the problems...
#inside_right{
width: auto;
display: inline-block;
word-wrap:break-word;
background-color: yellow;
}
<div id="container">
<div id="right">
<div id="inside_right">AAAAAAAAAAAAAAAAAAAAA</div>
</div>
<div id="left"></div>
</div>
http://jsfiddle.net/galacticpower/a3nyxhtj/3/
Here if the navigator is resized the "word-wrap:break-word" attribute is lost. The text is not broken! I need to apply some style in a div inside the right div without losing this behaviour.
To summ up, I want that the words were broken in the second example...
Any ideas?
Thank you so much!
Simply apply max-width: 100% to force the letters to actually break inside the inline-block #inside_right
#container {
height: auto;
overflow: hidden;
}
#left{
background-color: green;
width: 120px;
height: 20px;
overflow: hidden;
}
#right{
width: calc(100% - 120px);
float: right;
height: auto;
display: inline-block;
word-wrap:break-word;
background-color: red;
}
#inside_right{
width: auto;
display: inline-block;
word-wrap:break-word;
background-color: yellow;
max-width: 100%;
}
<div id="container">
<div id="right">
<div id="inside_right">
AAAAAAAAAAAAAAAAAAAAA
</div>
</div>
<div id="left"></div>
</div>
The problem is in "display". You use:
#inside_right{display: inline-block;}
And browser thinks that all the text inside this div is only one symbol.
you may use display: block and work with width of inside div.
This should help!
Lose the 'display: inline-block' from '#inside_right'. I don't see why you need it on '#right' either, but the property on '#inside_right' is tripping you up.

Creating Horizontal Scroll and Wrapping Elements

I have a horizontal scroll that I'm building but the divs end up wrapping to the next line instead of going off screen. In essence I'm trying to create this.
http://codepen.io/calendee/pen/HIuft?editors=100
My CSS looks like
.wide-as-needed {
white-space: nowrap;
overflow: scroll;
}
.scroll {
min-width: 100%;
}
parts * {
width: 100px;
}
parts {
display: inline;
float: left;
margin-right: 20px;
}
My HTML looks like
<ion-scroll class="wide-as-needed" direction="x">
<parts ng-repeat="part in popularParts" part="part"</parts>
</ion-scroll>
The parts element sample here
<parts ng-repeat="part in popularParts" part="part" class="">
<div class="text-center">
<img src="image.png">
<div class="bold assertive ng-binding">Product 1</div>
<div class="assertive ng-binding">John Deere</div>
<div class="bold balanced ng-binding">$88.0</div>
</div>
</parts>
What's wrong and how do I fix this?
Does it have to use Ionic? Here is an example with CSS and HTML, not using Ionic.
http://codepen.io/tylerism/pen/zGPQaj
.item{
display: inline-block;
vertical-align: middle;
background:#333388;
color:white;
padding:10px 50px;
margin-right:10px;
}
.scroll_outer{
width: auto;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
Does that work?

How to place 2 spans beside each other with full width with CSS

in my custom file manager I want to show truncated filenames. It's important to see the beginning and the ending, so just overflow:ellipsisdoesn't do the work.
The tiles where the filename is shown can change their width (inside bootstrap columns). They are rendered with handlebars, so I can manipulate the String before it's rendered (witch a helper). After that, I don't want to use javascript anymore (e.g. eventlisteners which listen to resize)
My Idea: Splitting the string of the filename (regex) while the tile is rendered. So "long_filename_with_number_at_the_end_001.jpg" becomes ["long_filename_with_number_at_the_end_","001.jpg"].
Now I want to include these strings in two spans inside a parent div, while the right span is as large as needed. and the left span fills the rest. The left span shall get the text-overflow:ellipsis property.
I found this answer, which is quite near to mine. I changed a little bit, but I did't get what I expected.
* {
position: relaitve;
}
.outer {
width: 110px;
height: 22px;
border: 1px solid #ccc;
}
#colA {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
background:yellow;
}
#colB {
float:right;
background: pink;
}
<div class="outer">
<div id="colA">long_filename_foo_bar</div>
<div id="colB">001.jpg</div>
</div>
Just switch #colA and #colB in your html document.
<div class="outer">
<div id="colB">001.jpg</div>
<div id="colA">long_filename_foo_bar</div>
</div>
JSFiddle:
http://jsfiddle.net/skeurentjes/0nam7L2q/
Flex based solution:
.filename {
display: flex;
}
.filename .start {
flex-shrink: 1;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.filename .finish {
flex-shrink: 0;
}
/* decorations */
.column {
width: 150px;
border: 1px solid #666;
overflow: hidden;
}
.filename:hover {
display: flex;
background: #ddd;
}
<div class="column">
<div class="filename">
<div class="start">long_filename_foo_bar_</div>
<div class="finish">001.jpg</div>
</div>
<div class="filename">
<div class="start">long_filename_foo_bar_</div>
<div class="finish">123001.jpg</div>
</div>
<div class="filename">
<div class="start">short_</div>
<div class="finish">001.jpg</div>
</div>
</div>

Limit width of div to parent width, otherwise use ellipse

I want to build a container that contains an image on the left side and to its right there is supposed to some information about it, like a headline and some description.
I want the container to be able to expand between some minimum and maximum width dynamically. The images can also have different widths between two boundaries and if the container already has a maximum width, but the headline is longer, the headline should be shortened and there should appear some dots.
I found a way to shorten the headline, like here: http://jsfiddle.net/h0452569/
, but therefore I need to limit the width of the container next to the image. I tried this with the code below, but I can't find a way with CSS to dynamically limit the div width to not extend the container's div!
I would be very happy if anyone had an idea out there!
jsfiddle
HTML:
<div class="container">
<div class="image"><img src="https://farm6.staticflickr.com/5238/14184095861_d3787020c7_t.jpg" width="100" height="71" alt="alt_flickr-7"></div>
<div class="meta-container">
<div class="headline">Some very very very long headline</div>
<div class="description">Some description</div>
<div class="description">Other stuff</div>
</div>
<div style="clear:both"></div>
CSS:
.container {
min-width: 200px;
max-width: 250px;
max-height: 100px;
position: absolute;
border: 1px solid #666666;
white-space:nowrap;
}
.image {
float: left;
display: inline-block;
vertical-align: top;
}
.image img {
max-width: 100px;
max-height: 80px;
vertical-align: top;
}
.meta-container {
overflow: hidden;
text-overflow:ellipsis;
display: inline-block;
}
.headline {
width: 100%;
white-space:nowrap;
}
.description {
font-size:.8em;
}
In the example you refer to, those styles are added to the text element itself. In your design, the styles are given to the parent element.
Solution: add the styles to .headline instead of .meta-container.
.container {
min-width: 200px;
max-width: 250px;
max-height: 100px;
border: 1px solid #666666;
overflow: hidden;
}
.image {
float: left;
}
.image img {
max-width: 100px;
max-height: 80px;
vertical-align: top;
}
.headline {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.description {
font-size: .8em;
}
<div class="container">
<div class="image"><img src="https://farm6.staticflickr.com/5238/14184095861_d3787020c7_t.jpg" width="100" height="71" alt="alt_flickr-7"></div>
<div class="meta-container">
<div class="headline">Some very very very long headline</div>
<div class="description">Some description</div>
<div class="description">Other stuff</div>
</div>
</div>
<p>Next element</p>
In order to break the word use "word-wrap: break-word" in your .headline class, you also need to set a width (in px). For example:
.headline{
width:100px;
word-wrap: break-word;
}