Edit: This HTML is output from a Flash application & its badly formed because it contains li elements NOT inside a ul or ol element. Is there a way to get the desired indentation with this HTML(using CSS)? Hopefully I wont have to parse the HTML & insert my ol tags where I need to, hopefully :(
<textformat leading="2">
<li>
<font style=" font-family: 'arial'; font-size: 14px; color: #FFFFFF; letter-spacing: 0px; ">
Remaining optimistic and focused while paying attention to the doubts of others
</font>
</li>
</textformat>
Is there a way to make EVERY line of text inside a HTML li element be indented?
Example of what I am trying to achieve:
This is what currently happens which is what I am trying to avoid:
So I have this html:
<ol>
<li><font>text here <b>some bold</b></font></li>
</ol>
Add a padding and text-indent:
li {
text-indent: -1em;
padding-left: 1em;
}
Try it on JSFiddle.
It displays like that fine in all majors browsers by default. The only way you'll get the wrap around like the second example is if you actually wrote the numbers themselves instead of using:
<ol>
<li>List item 1</li>
<li>List item 2</li>
</ol>
There shouldn't be a problem as long as you use these tags. The only way you should be getting the second image is with the CSS style list-style-position: inside;. Should you have some strange stylesheet interfering with your example, you could add style="list-style-position: outside;" to the <ol> tag to ensure that the numbers are outside of the text.
Oh, gah... post edit:
<li> isn't really gonna work, then. Why not use a div for each one like this: http://jsfiddle.net/aMdm9/
Related
I have a page, reading a text file and showing it on the site on runtime. I use jQuery to parse the file and append to the page with the following code:
resultArray.forEach(function (val) {
$('#OutputArea').append(appendText(val.content));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<ol id="OutputArea">
<li class="someClass"> some content...</li>
<li class="someClass"> some content...</li>
<li class="someClass"> some content...</li>
<li class="someClass"> some content...</li>
<li class="someClass"> some content...</li>
<!-- New content will add below -->
</ol>
</div>
It was okay when there are only thousands of line, however as more content appended to the page, the site will become less responsive, i.e. Took long time to render and laggy when scroll.
I understand the browser will become slower as the page do take a lot of resources, however is there a way to optimize the performance of it? Thanks.
26/7/2018 Update
I've done a couple things to speed up the process:
1.Make use of DocumentFragment instead of appending html strings like <li class="someClass"> some content...</li>
2.Instead of jQuery forEach loop, the following loop did make things sightly faster
var fragment = document.createDocumentFragment();
for(var i =0 ;i<resultArray.length;i++)
{
var val = resultArray[i];
fragment.appendChild(appendText(val.content, val.id));
}
document.getElementById("LogArea").appendChild(fragment);
Adding will-change:transform; CSS property to the div, the scrolling is MUCH more faster than before.
I also found that removing the counter-increment will make the render a lot faster, almost 70%. I use the following CSS to create my own <li> number style.
My guessing is that the li:before content calculation did a lot of work load to the rendering? I had no idea on how to get over it.
ol {
counter-reset: item;
list-style-type: none;
padding-left: 10px
}
li {
display: -webkit-box;
}
li:before {
content: counter(item) " ";
counter-increment: item ;
color: gray;
display: block;
text-align: right;
font-size:14px;
}
li:last-child:before {
content: "";
}
A few thoughts
Only append once. So build a var of all your list items
var text = '';
resultArray.forEach(function (val) {
text += appendText(val.content);
});
$('#OutputArea').append(text);
Chunk your text file. So the most important file is loaded / parsed first.
Build an API with pagination
I've tried a few JQuery and CSS implementations of this, but can't seem to get it quite right. I'm utilizing FontAwesome icons in the navbar for Bootstrap, and I would like to have a single location where, when the icons are hovered, a text description of them is shown/hidden.
This implementation has gotten me the farthest, with the different captions showing up. However, I need them all to appear in one location (preferably to the front of the ul navbar-nav grouping, as they will be right aligned).
CSS:
div#navbar a span {display: none;}
div#navbar a:hover span {display: block; position: absolute; top: 40px; left:-50px; width: 125px; padding: 5px; margin: 10px; z-index: 100;color: #AAA; background: black;font: 10px Verdana, sans-serif; text-align: center;}
HTML:
<ul class="nav navbar-nav">
<li><div class="nav-button"><i class="fa fa-user"></i></div><span>Text Goes Here</span></li>
<li><div class="nav-button"><i class="fa fa-umbrella"></i></div><span>Text Goes Here 2</span></li>
<li><div class="nav-button"><i class="fa fa-star"></i></div><span>Text Goes Here 3</span></li>
</ul>
The implementation above is based off MeyerWeb's CSS Popup Demo
I have tried JQuery Fiddles that worked for simple classes/links such as this: http://jsfiddle.net/AstroCB/42gV5/ , but I'm uncertain if the depth of Bootstrap classes is causing some sort of override, as I cannot seem to get JQuery show/hide functions based on the examples I've seen to work.
I have also tried ~ relations such as: http://jsfiddle.net/YsHA4/ but am again hitting a wall.
It's highly likely I am just approaching this the wrong way, but I've been attempting to solve this problem for a few days now and just can't seem to find a solution. A fresh set of eyes and any and all help would be absolutely appreciated. If there's any way I can clarify, please let me know. Thank you!!
EDITED TO ADD: I do not need the final result to be spans inside the links in any regard, they can be hidden external divs, etc. The example I gave is the farthest I have managed to get the functionality to what I want (separate information showing up for each hover), but if a different approach using JS/etc removes the spans or hard codes the text into a JS string in some way, so be it. I am just looking to get this functionality to work as anticipated with Bootstrap, whatever implementation best gets it there!
Also, see my comment for an image representation of what I am trying to achieve.
I made a Fiddle based on your image.
It uses bootstraps right section for the menu.
I have applied a loop to each link:
$.each($('a'), function() {
$(this).hover(function() {
$('.placeholder').html($(this).html());
});
});
It simply takes the HTML inside a tag and places in the menu item with the class placeholder.
Update:
In your case your links are bit more complex so the selector for the loop would look like this:
$.each($('a > span'), function() {
// do stuff here
});
This fetches all links in your document and then the span element inside that.
Aaand finally a Fiddle for the HTML you have provided here.
Code below edited since loops are unecessary:
$('a').hover(function() {
$('.placeholder').html($(this).html());
});
$('a > span').hover(function() {
// do stuff here
});
HTML
<ul class="nav navbar-nav">
<li class="hover"><div class="nav-button"><i class="fa fa-user"></i><span class="text hidden"> Text Goes Here</span></div>
</li>
<li class="hover"><div class="nav-button"><i class="fa fa-umbrella"></i><span class="text hidden"> Text Goes Here 2</span></div>
</li>
<li class="hover"><i class="fa fa-star"></i> <span class="text hidden">Text Goes Here 2</span>
</li>
</ul>
JS
$(document).ready(function () {
$('.hover').each(function (index, el) {
var thiz = $(this);
var text = thiz.find('.text');
thiz.on('mouseover', function (e) {
text.removeClass('hidden');
});
thiz.on('mouseleave', function(e){
text.addClass('hidden')
});
});
});
jsFiddle
I'm doing a pretty typical JSON request and populating a JRendere template. It works great, but when I wrap the li in a href it loses all formatting.
HTML Code:
<script id="recipeTemplate" type="text/x-jquery-tmpl">
{{for Content}}
<a href='searchResults.html' data-transition='slide'>
<li class="ui-li ui-li-static ui-body-c" style='height: 150px; border: 0px; margin-left: 20px; margin-right: 20px;'>
<img src="{{:ImageURL}}" style='max-height: 125px; max-width: 125px; position: absolute;'/>
<div style='margin-left: 50px;'>
<h3 style="white-space : normal;">{{:Title}}</h3>
<h3 style="white-space : normal;">Ratings:</h3>
<p style="white-space : normal;">{{:Description}}</p>
</div>
</li>
</a>
{{/for}}
</script>
The JS is as follows:
$("#search").focusout(function()
{
var searchTerm = $("#search").val();
$.getJSON("http://website?searchterm=" + searchTerm + "&callback=?",
function (data)
{
var htmlString = $("#recipeTemplate").render( data );
$('#results').html(htmlString).listview('refresh');
});
});
It looks as above. Why does it lose the CSS?
Thanks, Graeme.
It works great, but when I wrap the li in a href it loses all
formatting.
First of all, having an <li> within an <a> tag is invalid HTML.
Your CSS is most likely relying on a specific order, targeting an element then maybe another element which has to have a specific class inside that element, and so on.
By adding the <a> around the <li> element you have now changed the expected order and you CSS is not able any more to match the selectors.
Placing your <a> tag inside the <li> instead could keep the CSS intact and at the same time be valid HTML, well, assuming you have ul or ol around the set of li's in the final HTML.
Check your CSS and make sure you are not messing with the expected order of nested elements or classes. Then either ass the <a> so it doesn't break the CSS or update the CSS to match your new hierarchy.
I've got an unordered list with a list style using indented dots. I'd like to maintain those dots but remove the text from view. I originally guessed that I could simply set text-indent:-999px; but that removes the dot as well.
Any recommendations?
I know that it will work if the text inside the li is set to  , but that feels like cheating.
HTML
<div id="page_nav">
<ul>
<li class="showlink" id="show_one">PAGE ONE</li>
<li class="showlink" id="show_two">PAGE TWO</li>
<li class="showlink" id="show_three">PAGE THREE</li>
</ul>
</div>
CSS
#page_nav ul{
margin:0;
display:block;
}
#page_nav li{
width:15px;
height:15px;
margin:0 0 0 5px;
float:left;
font-size:3.5em;
}
<li><span class="list_item">Item</span></li>
.list_item { display: none; }
some context as to why you are hiding the text would help answer the question
How about using a span inside the list item with display:block, and setting text-indent on the span?
$('li.your_style').each(function()
{
$(this).html($(this).html().toString().replace(/([^\.]+)/g,''));
});
this can help you
All you need to do is leave a blank <li></li> and that will display the dots without any text
We need to know why you want this... the context...
Wo you want something to happen later that makes the text visibile? If so, you should put all the text within the <li> in a <span> that is visibility:hidden then upon wanting it to be displayed/read you should make it visible..
If you want to maintain the dot but lose the text... what would you want the screen reader to say? "dot?"..
If you really don't want to set the text to a then you could use wrapInner as follows:
Try this:
$(function(){
$("li.showlink").wrapInner("<span style='display:none'></span>");
});
I have an unordered list containing links.
I styled the list so that there is a "Click Me" image to the left of the link.
ul
{
list-style-image:url(/images/ClickMe.png)
}
The problem is: when the user clicks on "Click Me", they are not redirected and nothing happens.
How do I make a click of the list image trigger a click of the link in that list element?
<ul>
<li>Some Url</li>
<li>Some Other Url</li>
</ul>
This is more of a CSS problem I think, because the list bullets are not actually part of the a tag. You can cheat by making the links "wide left" to include the bullets like this (see the jsfiddle snippet):
ul
{
list-style: disc;
list-style-position: inside;
padding: 0;
margin: 0;
}
a {
margin-left: -20px;
padding-left: 20px;
}
You can always make the item clickable through jQuery:
$("li").click( function (evt) {
location.href = $(this).find("a").attr("href");
});
I don't know if there's a better way to do it but this works by making the link size so that it includes the bullets to the left of the link.
a{
margin-left: -2em;
padding-left: 2em;
}
Incidentally, this also works, but does not pass validation, does anyone knows if there's a correct way of doing it?
<body>
<ul>
<li>Some Url</li>
<li>Some Other Url</li>
</ul>
</body>
If you only need the list to have those bullets, you can do it also without lists by making the links "list-item" displays:
<style>
a{
display:list-item;
list-style-image:url(/images/ClickMe.png);
list-style-position:inside;
}
</style>
<div style="padding:12px;">
Some Url
Some Other Url
</div>
http://jsfiddle.net/zp8QU/