In order to display a list of news headers, I need a div of a fixed max-height.
That div should cut-off the text if the text overflows the div, and finish with an ellipsis in case of the cutt-off...
#lipsum {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-height: 75px;
height: 75px;
width: 100%;
}
<div id="lipsum">
<p>
Duis eget sapien leo. Vivamus dignissim elit eget enim varius, vel condimentum tellus sodales. Vestibulum scelerisque lectus at mauris elementum finibus. Ut enim risus, venenatis sagittis mi ac, facilisis lacinia nunc. Nam ornare urna tortor, a vehicula nisl facilisis quis. Etiam enim sem, ornare a hendrerit et, convallis id quam. Ut tincidunt facilisis tincidunt. Mauris sodales euismod orci, a tincidunt massa fermentum sed. Mauris odio quam, auctor ac viverra vitae, condimentum feugiat mauris. Phasellus fermentum velit sit amet orci interdum dignissim. Praesent venenatis aliquet magna, at hendrerit felis condimentum maximus. Fusce cursus, nulla at suscipit iaculis, magna odio bibendum arcu, a tincidunt diam sapien sit amet nisl. Nullam non risus et metus tempus finibus tempus in libero. Maecenas auctor eget mauris non malesuada. Quisque erat tellus, facilisis quis mauris quis, lacinia tristique orci. Suspendisse dignissim nibh et mi consequat venenatis.
</p>
</div>
my problem is that the existing behavior is OK if there is only one line, but I don't need one signle line, but several lines of text until the max max-height...
You may want to refer to the following post:
With CSS, use "..." for overflowed block of multi-lines
It looks like someone also posted an article on the topic. Though, the solutions seem a bit tangential to the problem:
https://css-tricks.com/line-clampin/
Finally, here is a .js solution:
Insert ellipsis (...) into HTML tag if content too wide
EDIT: To add to this list of resources, here is a pure css solution.
http://codepen.io/martinwolf/pen/qlFdp
*Be advised that the text-overflow:ellipsis; isn't supported in every browser, yet.
Finally, here is a .js solution to the issue:
Unfortunately, I think that you cannot achieve your objective with this approach. According to this source, "This property only affects content that is overflowing a block container element in its inline progression direction (not text overflowing at the bottom of a box, for example).".
So, as also stated in other answers, this cannot be done using CSS only, unless taking into account that not every browser may support such CSS3 directives. If you are planning a more general (traditional?) solution to overcome the compatibility issue, given that you already have headers, supposed short in length, you may pre-process and present them in a Wordpress-like fashion, for example. You can check out the official documentation.
Related
I am printing an HTML div with repeatable headers and footers. The repeatable headers and footers have been generated using an HTML table's thead and tfoot elements. Now, there is a requirement to generate page nos. after the footer on each page. I have done some searching on the net and found a few suggestions. But none of the suggestions gives the correct solution.
I have tried using the following CSS code to generate the nos.:
tfoot:after {
counter-increment: page;
content: counter(page);
}
But this code generates 1 as the page number for all pages on chrome. Also, only on the first page, is the page number gets printed after the footer. On other pages on chrome, page numbers are printed before the footer.
On firefox, the first page gets 2 as the page number, while other pages don't get any page nos.
Does anyone know of any way to generate the page nos. using CSS?
Bro it doesn't need CSS , please tell that the solution is working or not
<h1> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed erat diam, feugiat non quam quis, lobortis tincidunt sapien. Praesent neque tortor, sagittis nec tristique at, elementum non arcu. Phasellus tempor ac dui at egestas. Nam tellus eros, malesuada nec lectus non, condimentum ullamcorper sapien. Vestibulum vel fermentum nulla, at sollicitudin orci. Etiam rhoncus, sem pharetra auctor ultrices, turpis odio suscipit risus, at blandit metus turpis in eros. Vestibulum molestie, magna at porttitor dapibus, mi sapien maximus mi, non elementum risus purus eu velit. Aenean luctus metus porttitor consequat mattis. Ut vel nibh eget nisi sagittis porttitor. </h1>
<center>
<footer>
<h2> 1 </h2>
</footer>
</center>
By doing this the page no will automatically go into the footer just replace 1 to your page numbers. Thanks!
How to align a text box, left or right of the HTML page?
We all know how to align a picture to the right. But how do I create a textbox (with a border and a different background color) and how do I integrate this textbox into a paragraph so that the body text skirts the textbox with a specific padding?
We all know how to align a picture to the right.
The above is a little presumptuous.
I'd agree that your question needs examples of what you've tried. It also needs clarity around what you are asking for. I'm assuming that the code below is what you are after.
This example uses floats which will cause the wrapping effect that you mention, however for layout similar to this, I would take a good look at CSS Grid.
section {
width: 600px;
height: auto;
}
p {
display: block;
}
#funky {
background: pink;
padding: 1rem;
margin-left: 1rem;
border: 3px dashed;
width: 200px;
height: 150px;
overflow-y: scroll;
float: right;
display: inline;
}
<section>
<p id="main">
<div id="funky">
Aliquam erat volutpat. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Suspendisse non nisl sit amet velit hendrerit rutrum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer
</div>
Pellentesque egestas, neque sit amet convallis pulvinar, justo nulla eleifend augue, ac auctor orci leo non est. Nam at tortor in tellus interdum sagittis. Morbi vestibulum volutpat enim. Pellentesque egestas, neque sit amet convallis pulvinar, justo nulla eleifend augue, ac auctor orci leo non est. Sed in libero ut nibh placerat accumsan. jfdkjfd fdsjlfdsj Aliquam lobortis. Vivamus consectetuer hendrerit lacus. Vivamus euismod mauris. Vivamus euismod mauris. Fusce vulputate eleifend sapien. Vivamus euismod mauris. Vivamus euismod mauris. Fusce vulputate eleifend sapien. Vivamus euismod mauris. Vivamus euismod mauris. Fusce vulputate eleifend sapien. Proin pretium, leo ac pellentesque mollis, felis nunc ultrices eros, sed gravida augue augue mollis justo. Donec mi odio, faucibus at, scelerisque quis, convallis in, nisi.
</p>
</section>
Use a div and assign float: left or right to it (same as with floated images), plus a width setting to not have it span the whole page (percentage or px)
I have a link which I want to show to visitors with vision, but hide from visitors using screen-reader ATs. (This is not ideal of course).
This is the reverse of the usual problem (with known solution) of hiding content from vision visitors (e.g. a "skip to content" link)
An example:
Clicking the "read more" link expands the text inline.
and conversely, clicking the "read less" link collapses it again.
This collapsed/expanding text functionality is only of benefit to visitors with vision, whose field of view would take in the extra text before they get to it (and in this example displaces the next FAQ, pushing it off screen).
A visitor with a screen-reader should instead be presented with the full text as they can choose to skip ahead to the next block, and they shouldn't encounter a spurious "read more" link which (a) doesn't link to a page, and (b) simply gives them what they were about to hear from their screen reader anyway.
How would this be done in HTML5?
Use aria-hidden this way for the content:
<p aria-hidden="true">Screen readers will not read this!</p>
You can try to put the link in a pseudo element. That's brings another issue: you can't click on a pseudo element because is not part of the DOM, but can fake it with pointer-events.
$("p").click(function () {
$("span").toggleClass('on');
});
span {display:none; color:red}
p {pointer-events:none}
p:after {content:"Read more"; color:blue; text-decoration:underline; display: block;pointer-events:all}
span.on {display:block}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque at erat orci. Praesent non pulvinar nisl, at ultrices lorem. Sed semper ultricies eros, eu aliquet ipsum vehicula nec. Nullam orci justo, dapibus eget elit ac, tincidunt mollis urna. Ut sed felis lobortis, blandit urna non, fermentum arcu. Suspendisse fermentum elit ante. Nulla tincidunt elit vel elementum eleifend. Fusce sed nisi vulputate, aliquam urna congue, egestas arcu.<span> Praesent dignissim, risus in elementum eleifend, velit elit accumsan diam, sit amet vestibulum purus urna quis dui. Proin ut venenatis orci, sit amet ullamcorper tellus. Morbi lorem purus, ornare non convallis nec, venenatis cursus urna. Maecenas cursus, leo vel tincidunt viverra, leo nibh placerat sem, ut molestie tellus ex et nulla. Vivamus eget magna libero.</span></p>
I use display:noneas an example, of course I assume you have your own method to hide the text but no for JAWS or other screen readers.
I am currently working on designing my website, and I would like to be able to resize/zoom the webpage without messing up the flow of the elements of the website. I am aware that the correct use of % signs solves most of the flow problem, and it seems like it does with everything except text. If I have a simple menu like in the jsfiddle below. The width of the menu div lets say is %30. I would like the text in the menu container to scale to size without wrapping around or entering a new line, which I cant seem to avoid. The same problem remains in the paragraph below. Is there a way to achieve this?
<html>
<head>
<title>Scalable</title>
</head>
<body>
<div style="height:800px; border:1px solid green; width:900px; margin-left:auto; margin-right:auto; " >
<img src="http://files.prof-web-diego.webnode.pt/200000028-04da905d3d/Oxford_Silhouette_Web_Banner.jpg" style="width:50%; height:auto;"/>
<div style="float:right; width:30%; border:2px solid blue; font-size:11px;">
<a href="#">Home<a> |
<a href="#">Store<a> |
<a href="#">Contact<a> |
<a href="#">About<a> |
<a href="#">Pictures<a> |
<a href="#">Entertainment<a> |
</div>
<div style="border:1px solid #ddd; width:65%;">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vehicula velit in lectus dapibus porta. Sed pulvinar ultrices ipsum vitae gravida. Vestibulum at metus dolor. Nunc pulvinar nisl nec libero sodales faucibus. Quisque tincidunt risus vitae risus tempor viverra. Vestibulum interdum eros in tellus blandit vulputate. Suspendisse eget ante purus, sit amet semper purus. Nam lacinia magna a mi euismod sit amet rhoncus dolor congue. Mauris pharetra laoreet accumsan. Ut quis velit ac nisl rutrum varius nec nec orci.
Vestibulum quis tellus neque, a scelerisque est. In varius ante eget purus fringilla in aliquet massa convallis. Vestibulum in scelerisque ligula. Nulla a neque nibh. Maecenas tristique, odio nec scelerisque tincidunt, sem orci tempus nulla, eu tincidunt dolor sapien ut lorem. Donec aliquet, eros nec blandit adipiscing, leo est malesuada nulla, vel adipiscing sem risus quis ante. Proin rutrum ultrices dolor, quis auctor sem feugiat sit amet. Morbi in tellus nisl, et iaculis turpis. Cras ligula velit, pharetra vitae imperdiet nec, commodo quis erat. Aenean iaculis nunc nec nunc dignissim aliquam. In venenatis, orci vitae pretium elementum, lorem lorem sagittis est, a consectetur est lacus accumsan elit. Vestibulum iaculis hendrerit elit, nec vulputate nunc ornare sit amet. Fusce nisi risus, auctor vitae pellentesque ut, pulvinar nec nisi. Aenean nec nunc augue, non imperdiet arcu. Integer interdum orci non diam tristique ut tristique risus adipiscing. Vestibulum tellus orci, lobortis vel sollicitudin vel, gravida sed dui.
Vestibulum eu dui ni
</p>
</div>
</div>
</body>
</html>
jsFiddle
http://jsfiddle.net/6UyYa/
Two approaches you can take:
Use the viewport meta tag to scale the page to the width of the
device (to the extent that browsers support that)
Responsive Design: Use a series of CSS media queries to adapt the content based on the size of the device.
Two versions of Responsive Design:
Change the layout of the page (number of columns and how the content flows on the page) based on the size of the device, and optionally scale some of the content. A good example of this is The Boston Globe.
Leave the layout unchanged and uniformly scale all of the content. #rlemon mentioned a good link for this. I learned it by reading Ethan Marcotte's ebook Responsive Web Design (unfortunately the ebook isn't free). This approach is relatively difficult and it limits your options.
In both versions of Responsive Design, changes to the content are triggered entirely by CSS media queries (rather than by JavaScript). And the HTML doesn't change. Only the styling of the HTML changes.
The first type of Responsive Design appears to be used much more widely than the second type.
For the second type of Responsive Design listed above, a series of media queries for different device sizes sets the base font-size for the body tag in %, and all size units for the content are specified in em or % instead of px (with absolutely no use of px for the content itself). All content is scaled based on whichever media query is used.
Additionally, in the second type of Responsive Design, there's little or no use of background images (at least, in my experience). img tags are used for almost all images, with a special trick for proportionally scaling the img tags via CSS. The following code proportionally scales an image to the full width of its parent container:
<img class="my-image" src="image.png"/> <!-- No width or height attribute -->
.my-image {max-width:100%; width:100%;}
If i do:
<img src="" style="float:left"> SOME TEXT BLA BLA BLA BLA
It doesn't work because text goes down to the image when the image height stops. I mean:
it would do this:
http://img8.imageshack.us/img8/9379/senzatitolo1yt.jpg
While what i want to get is:
http://img28.imageshack.us/img28/606/senzatitolo2rd.jpg
I could use old good table (<td>img</td><td>text</td>) but in 2011 that doesnt' seem the way to go :)
Any easy cross-browser trick to do that?
Edit: I can't know the image-width
Thanks!
Use two div tags, float them both to left. Give a width of 30% to one of them and 70% to the other. Put the image in the first one, text in the second one.
Given the simplistic html:
<img src="path/to/img.png" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dui odio, luctus ut viverra vitae, dignissim a mauris. Vestibulum vel massa at sapien tincidunt venenatis id sed purus. Ut quam libero, mollis a ullamcorper sed, gravida id ligula. Sed nec augue enim. Phasellus accumsan aliquet erat interdum ullamcorper. Cras tellus libero, tincidunt non placerat interdum, venenatis id arcu. Nulla facilisi. Maecenas malesuada vestibulum venenatis. Nam vel tellus arcu. Sed non dui urna. Proin fermentum aliquet lectus non fermentum. Donec aliquet purus et tortor lobortis gravida. Duis vehicula ligula nec enim consequat ut tempor diam molestie. Aenean egestas eros sem. Phasellus ullamcorper pretium nunc molestie luctus. Mauris semper ultricies nulla, at tempus purus eleifend vel. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas ac est nunc.</p>
The following CSS works:
p {
margin-left: 100px; /* width of image plus some padding for white-space */
}
img {
float: left;
width: 90px;
height: 90px;
}
JS Fiddle demo.
Surprisingly enough the following works, albeit only tested on Chromium 8/Ubuntu 10.10:
img {
width: 100px;
height: 100px;
background-color: #f90;
float: left;
margin: 0 10px 100% 0;
}
JS Fiddle demo (ignore the colours, they were just so's I could see where things were sitting).
Second (post-edit) JS Fiddle demo, featuring an img with non-specified dimensions.
There are multiple ways to realize that.
1) two divs. assign to both a width. float the image-div to the left, the text-div to the right.
2) use margins!
give it a shot and give me feedback.