Context: (simplified)
<div style="width:300px;" >
<img src="blabla..." />
<div style="oveflow:hidden; etc..." >
description
</div>
</div>
Problem:
Sometimes the description can be very long and gets cut (intended, see "overflow:hidden;"). So I made it so that when the user hover the description a css animation pushes the description to the left side a bit, let's say "margin-left:-200px;". This way the user can continue reading the description while it reveals itself (css animate).
Now comes the issue: the description can vary from long to very long to very very long. And obviously pushing it to the left for -200px is sometimes not enough, sometimes too much.
Solutions I know:
1)
Javascript/jQuery
My website is full non-js and very lightweight, I do not want to use js. I found many solutions on the web using js, I already know them. Please respect this. I would love to solve it via pure css.
2)
<marquee>description</marquee>
Depreciated.
Ideas:
I was thinking about "tricking" it using PHP code. For example I would calculate the description's length so that I could set a "margin-left:-???px;" accordingly. Now that sounds even uglier than js to me, forcing me to "hardcode" it in the php file bypassing the conveniant css stylesheet and resulting in a heavy php file. Irrelevant.
I didn't find anything in the CSS3 about it eventhough many other designers came accross this issue from what I could find searching on GG. Is it beyond css language's scope?
Thank you.
PS: my description MUST fit in 1 line. No line break, no scrollbar, no "show more" button, etc.
you could use echo <br/> with php when a certain length is reached
each time.
you could use css max-width property to restrict the width to a
certain amount
http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_word-wrap
p.test {
word-wrap: break-word;
}
Is this what you're looking for?
Closest I could come.
I am slightly concerned that the slide eventually end with the description hidden but I think that's a small price to pay...otherwise I think it meets most of the criteria
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrap {
width: 300px;
margin: 1em auto;
border:1px solid green;
display: flex;
flex-direction: column;
}
.wrap img {
max-height:100%;
width: auto;
}
.desc {
width: 300px;
height: 15px;
white-space:nowrap;
overflow: hidden;
font-size:13px;
line-height: 15px;
position: relative;
}
.wrap .desc p{
position: absolute;
transform: translateX(0);
transition: transform 5s ease;
}
.wrap:hover .desc p{
transform: translateX(-100%);
}
<div class="wrap" >
<div class="image">
<img src="http://lorempixel.com/output/abstract-q-c-300-300-10.jpg" alt="" />
</div>
<div class="desc" >
<p>Tri-tip shank turkey chuck, porchetta drumstick andouille beef ribs prosciutto salami beef. Ham hock pork belly pig pastrami. </p>
</div>
</div>
Codepen Demo
What i would suggest you is fix the width and height of the description div and use the css property overflow-y:auto.
The default scrollbar is ugly and different for all the browsers so you may try a js plugin but as you said you don't want to add a library just to achieve a small task.:)
Try this-
div.test {
white-space: nowrap;
width: 12em;
overflow: hidden;
height:30px;
}
div.test:hover {
text-overflow: inherit;
overflow: visible;
}
<p>Hover over the two divs below, to see the entire text.</p>
<div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box. This is some long text that will not fit in the boxThis is some long text that will not fit in the boxThis is some long text that will not fit in the boxThis is some long text that will not fit in the box</div>
<br>
<div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div>
Related
{ PS : i referred to Unable to get ellipsis for Multiline Paragraph }
Expected Output:
Focus with soft study music in
the background and make sure...
[after two lines, ellipsis is showing and text stops]
(https://i.stack.imgur.com/BeBdt.png)
..................................................................................................................................................................................
Obtained Output:
But after researching and checking many answers and tutorials I obtain the below result
I get this output with text flowing after the ellipsis
Focus with soft study music
in the background and make sure ...
it caters to all your needs.
....................................................................................................................................................................................
Main picture:
This is the css code
.text-tocut{
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
width:170px;
height: 60px;
font-size: 13px;
margin-bottom: 10px;
}
This is html code
<div class="sub-box">
<img class ="sub-image" src="thumbnails\c.jpg">
<img class="playsong-button" src="buttons\playsong-button.jpg">
<p class="sub-desc">
Instrumental Study
</p>
<p class="text-tocut">
Focus with soft study music in the background and make sure it caters to all your needs.
</p>
</div>
How do I get the output that I need?
which is
enter image description here
I thought we had to put the "para" into a div with a fixed width and height
or make the para the child class and apply
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
also tried using text overflow,
But, unfortunately, this didn't work either
I found similar question but none of them matched mine and I haven't found an answer so far
not clear exactly what you are asking but it looks like you just need to make sure your text actually overflows
.text-tocut {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
width: 173px;
height: 30px;
font-size: 13px;
margin-bottom: 10px;
border:solid 1px red;
}
<div class="sub-box">
<img class="sub-image" src="thumbnails\c.jpg">
<img class="playsong-button" src="buttons\playsong-button.jpg">
<p class="sub-desc">
Instrumental Study
</p>
<p class="text-tocut">
Focus with soft study music in the background and make sure it caters to all your needs.
</p>
</div>
I found an intriguing SCSS example of dynamic moving background colors, Floating Stained Glass Effect. Think multi-colored lava lamp. Here's the original codepen.
What I'm trying to achieve is a simple "clip" of that background content and display a div with the dynamic color content... My current codepen and the display.
What I'm looking for is the dynamic content only in the inscribed "box" with everything else on the screen pure white.
<div class="splash box">
<div class="splash_head" />
<div class="splash_body" />
</div>
All my attempts at overflow: hidden; have failed miserably. Not sure how to beat the position: fixed; code within
.splash_head::before,
.splash_head::after,
.splash_body::before,
.splash_body::after {
position: fixed;
top: 50%;
left: 50%;
width: 3em;
height: 3em;
content: "V";
mix-blend-mode: screen;
animation: 44s -27s move infinite ease-in-out alternate;
}
Turns out if I wrap the content with an additional surround container, I'm able to get what I asked for.
<div class="surround">
<div class="splash box">
<div class="splash_head" />
<div class="splash_body" />
</div>
</div>
SCSS:
.surround {
background-color: white;
padding: 10%;
height: 100vh;
}
And it looks pretty.
Unfortunately, this example as written was a minimum problem statement. And in a static HTML web page, these div containers would work great. Unfortunately my actual use case is a complex SvelteKit application, with nested slots where the color bleed thru is terrible. It's not clear if this is a z-index issue or something else. But yeah, it's ugly, sigh.
The other issue here is with the pretty lava lamp stuff is a significant Lighthouse website ranking performance degradation. (71 goes down to 63) At this point, not sure it's worth spending time on. I may just create a static site, grab some screen shots of the pretty pictures and use them static. I'm really just looking for a subtle but interesting splash of color.
I have a html code where I want to store long paragrapsh of information. The only issue is that in my code I don't want hundreds of sentences on just one line. Id rather see it formatted like:
<div id ="sidebar">
<div><b> Things to take into account: </b></div>
<div>
<p>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
</p>
</div>
</div>
However, when I do it this way and run my website the words run outside the container they are in
Can you help give me a way to display it this way in the code while keeping the words inside it's container?
my css:
#sidebar {
"background-color: #eee;
height: 200px;
width:350px;
float:left;
margin-top: 30px;
margin-left: 30px;
border: 1px solid black;
border-radius: 5px;
display: block;
}
UPDATE: changed X to words and fixed it. Weird but ok lol
Your issue is that xxxxxxxxxxxxxx is considered one word and by default the browser won't break this word.
adding
word-wrap:break-word;
Will fix this, but I would guess once you use actual text in there it will break more naturally since it won't be a single word of so many characters.
fiddle: http://jsfiddle.net/ktbypbtt/
Here is another fiddle without the word-wrap, but with actual text.
http://jsfiddle.net/ktbypbtt/1/
Notice how it breaks itself since the browser will naturally wrap the word after each word if it hits the end of the div, but needs to be specifically told to break words.
Just add a <br> tag where ever you want the text to go to the next line
<div id ="sidebar">
<div><b> Things to take into ACCOUNT: </b></div>
<div>
<p>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
</p>
</div>
</div>
Helpful? Let me know :)
add some css.
#sidebar{
display: block;
}
or add a class to your wrapping div and do the same thing with setting display as block
edited
You could cut off the overflow:
#sidebar{
overflow: hidden;
}
http://jsfiddle.net/5deyo1tb/
I have this div:
<div class="text">
Thisismytextwontgoinanewparagraph
</div>
with this CSS:
.text
{
background-color:red;
width:100px;
}
As you can see in this JSFiddle, the text goes outside of the div.
Is there a way in CSS to force wrapping for a text without spaces (such as a hyperlink)?
you could try this, but it's not very pretty:
.text
{
background-color:red;
width:100px;
word-wrap: break-word;
}
http://jsfiddle.net/esGEn/1/
Why not just use ellipsis with overflow hidden? That will also look pretty.
.text {
background-color: red;
width: 100px;
overflow: hidden;
text-overflow: ellipsis;
}
Here is how I did it. I added the <br> tag to the text I wanted to push to the next line.
<p> Sleek custom designs and durable functionality. <br>Let your headwear work for you. </p>
text multiple lines example
I have a header which I constructed like this:
<header class="top">
<a href="">
<span class="right">Stichting Delftsche Opera Compagnie presenteert</span>
<h1 class="right">Carmen</h1>
<h2 class="right">Een opera door Krashna Musika en de TU Delft</h2>
</a>
</header>
This should look like this, as someone made this in Adobe Illustrator
Then I applied some css and got to this (in the original there is a Dutch spelling mistake, this one is corrected, the scale is not completely equal either):
The rules:
.top {
display: block;
width: 800px;
float: right;
}
.top a {
background-image: url('../img/logo.jpg');
background-size: 150px 150px;
background-repeat: no-repeat;
padding-left: 150px;
height: 175px;
display: block;
overflow: hidden;
}
.top .right {
text-align: justify;
width: 650px;
}
.top span, .top h2 {
color: #E02C33;
font-size: 1.8em;
}
.top h1 {
color: #B02025;
font-size: 4.7em;
text-transform: uppercase;
}
I have two issues here:
How can I justify both the <span> and <h2> to their equal lengths (my justify is not working as expected)
How can I constraint "CARMEN" such the width and height are pre defined, the spacing between characters is rendered by the browser
The problem with justify is that the last line is usually no justified, because the letter spacing would be too long.
If you can use CSS3, there are new attributes, which make this possible:
http://www.css3.com/css-text-justify/
If the header always stays the same, you can also adjust the font-size and letter-spacing attributes, until it fits.
One important thing is that while creating graphics initially in adobe photo shop or illustrator etc. is different and when we implement in actual webpage the output may vary little bit in some cases. So we have to write css like that so we can accomplish the desired design. Thanks.
see fiddle for code and demo
Fiddle: http://jsfiddle.net/ybf25/3/
Demo: http://jsfiddle.net/ybf25/3/embedded/result/
Note: As i don't have the Rose image so i was not able to create Demo as your given image in question.
See screen shot for output: Please open the screen shot in new window to see clear image.