Here is the JSFiddle I'm trying to do: JSFiddle Example
It is responsive, and in a large width, it is exactly what I want, like this:
But in small sizes, It overlaps the another text and/or breaks the lines, like this:
and this:
And this is my css to the texts:
.giro-nome {
position: absolute;
top: 25%;
}
.giro-percentual {
position: absolute;
right: 0;
top: 25%;
font-weight: 700;
}
I wanted just to stop the text in a single line, something like this(expected, not real):
Is it possible? Probably not with absolute, like I'm doing, but I have no idea another way to do it.
Thank you advanced.
text-overflow: ellipsis; is what you're looking for.
8.2. Overflow Ellipsis: the ‘text-overflow’ property
This property specifies rendering when inline content overflows its
block container element ("the block") in its inline progression
direction that has ‘overflow’ other than ‘visible’. Text can overflow
for example when it is prevented from wrapping (e.g. due to
‘white-space:nowrap’ or a single word is too long to fit). Values have
the following meanings:
ellipsis Render an ellipsis character (U+2026) to represent clipped inline content. Implementations may substitute a more
language/script-appropriate ellipsis character, or three dots "..." if
the ellipsis character is unavailable.
However you should specify the width of the absolutely positioned element at first. Either by left/right properties, or by other approaches such as width: 90% or width: calc(100% - 80px):
EXAMPLE HERE
.giro-nome {
position: absolute;
top: 25%;
left: 0; right: 80px; /* Equal to > width: calc(100% - 80px) */
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
Apply the below css properties this will truncate your overflow text and append the three dots.
.giro-nome {
position: absolute;
top: 25%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Related
I use white-space: nowrap so my string will stay in one line but I also set max-width: 100px because I want the string to break only when over the max-width, makes sense only the two parameters conflicts each other. The white-space property "overpower" the max-width property and the string stay in one line.
<div class="mydiv">this is my text</div>
.mydiv {
position: absolute;
white-space: nowrap;
max-width: 100px;
left: 50%;
transform: translateX(-50%);
}
I tried "playing" with overflow-wrap property but that didn't work either.
If I remove the white-space property, the string break word by word, each word in a new line. That's happening because the element is position: absolute, I think..
So how do I solve this?
If I remove the white-space property, the string break word by word, each word in a new line. That's happening because the element is position: absolute, I think
It happens because of the left:50% that will restrict the width of your element to a maximum width equal to 50% of the containing block width.
Add a negative margin-right to avoid this issue
.mydiv {
position: absolute;
max-width: 400px;
left: 50%;
transform: translateX(-50%);
margin-right:-50%;
border:1px solid;
}
<div class="mydiv">this is my text this is my text this is my text this is my text this is my text</div>
Without the margin trick the item will wrap sooner:
.mydiv {
position: absolute;
max-width: 400px;
left: 50%;
transform: translateX(-50%);
border:1px solid;
}
<div class="mydiv">this is my text this is my text this is my text this is my text this is my text</div>
I have an example like this jsfiddle where I have a list of <a> element. Inside each <a> element I have a <span> and a <button>. What I would like to do is I want to align the button on the right, I do this by adding the class pull-right and it worked fine
<button class=" btt pull-right glyphicon glyphicon-chevron-right"></button>
, and I want to align the span and the button on the same line, but if I have a very long Name inside the span then the button is no longer on the same line with the span. How can I fix this problem?
You can set width and display property to the span elements like this:
.surveySummaryList a span {
width: calc(100% - 40px);
display: inline-block;
word-break: break-all;
}
and add rule for your buttons width like this:
.btt{
width: 30px;
}
I updated the FIDDLE
Use position: absolute; in your styling and set the buttons right styling to 0. This will place your button at an absolute position, according to your parental div.
.btt {
position: absolute;
right: 0;
}
Live example
This is an issue I have faced a few times and usually what I do is decide the maximum length I will allow this value to be and then truncate after that with ellipsis.
It is up to you but I think this is a good choice to make as it is defensive coding to keep your display neat no matter what the value.
Here is an example CSS class you can add to your span:
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
i wanted to make a menu using only html and css (no javascript). It should have several links next to each other and a scroll bar - a HORIZONTAL scrollbar - so one can access all links.
I can't figure out how to force these links to display next to each other, instead of making a break and displaying in another line. What I have untiol now looks like this: jsfiddle
html:
<nav>
<a>Site1</a>
<a>Site2</a>
<a>Site3</a>
...
<a>Site17</a>
<a>Site18</a>
<a>Site19</a>
</nav
css:
nav {
position: fixed;
top: 0;
left: 0;
height: 100;
background: #c00;
overflow-x: scroll;
overflow-y: hidden;
}
Edit:
The solution was to add white-space: nowrap to the css. jsfiddle
Check this out: http://jsfiddle.net/dmc56jkd/3/
white-space: nowrap;
This property prevents unwanted text wrap.
The key is to add white-space: nowrap
Here's a fork of your fiddle, using the following CSS
nav {
position: fixed;
top: 0;
left: 0;
height: 100;
background: #c00;
overflow-x: scroll;
width: 300px;
white-space: nowrap;
}
For demo purposes, I've limited the nav's width. If you wanted it to be as wide as the containing element, use width: 100% (if you don't define the width at all, the scrollbar slider may not show up)
http://jsfiddle.net/7tzo3vrh/
We are using the twitter bootstrap thumbnails.
We are adding a description underneath the same as in the bootstrap documentation.
The difference is that we don't have a size specified (the documentation uses .span4) on our thumbnails, instead the content sizes them.
This works great, except we want one difference, we don't want a long caption to extend the thumbnail, instead we want the extra caption length to be be hidden.
This would be easy if we were using fixed width's but since we are not I have no idea how to do this;
Here is a jsfiddle playground: http://jsfiddle.net/BbCQK/
I thought maybe I could just do:
.caption {
max-width: 100%;
text-overflow: ellipses;
}
But that doesn't work, it just stretches the container anyway, so how can I do this?
Got it :)
Absolute positioning to the rescue: http://jsfiddle.net/BbCQK/4/
a.thumbnail {
padding - bottom: 30px;
position: relative;
}.thumbnail.caption {
overflow: hidden;
white - space: nowrap;
position: absolute;
padding: 0;
bottom: 4px;
left: 4px;
right: 4px;
text - overflow: ellipsis;
}
I'm absolutely positioning text on top of images and would like to truncate the text if it expands over the image. This wouldn't be a problem if the width of the text was defined. However, the text block over the image is set to 100% and is positioned to the bottom of the image.
How do I hide the text if it expands pass the image?
Check out my example:
http://jsfiddle.net/qhFUL/
Set overflow to hidden:
.box {
overflow: hidden;
}
Demo: http://jsfiddle.net/qhFUL/1/
If you want to prevent the text from wrapping as well (so it doesn't hide the image) you can do this:
.box {
position: relative;
margin-bottom: 20px;
overflow: hidden;
}
.text {
position: absolute;
bottom: 0;
left: 0;
padding: 20px;
white-space: nowrap;
}
Which will truncate long text instead of wrapping.
You could also specify a height on the .text div so it will truncate and not wrap.
You could then add a little jQuery ellipsis script to pretty it up a bit...
http://yue.st/notes/code/js/ellipsis.en.html
or
https://github.com/rmorse/AutoEllipsis
nice... :)