I have been trying to figure out how to put space in between a numbered list and the text and still have the text wrap nicely under the line above it. I found some script on Stack Overflow that works but for some reason I can only get bullets, no numeric's.
Thanks.
ul {
margin: 0;
padding: 50;
}
/* The wider the #list_wrapper is, the more columns will fit in it */
#list_wrapper {
width: 1000px
}
/* The wider this li is, the fewer columns there will be */
ul.multiple_columns li {
text-align: right;
float: right;
list-style: decimal;
height: 30px;
width: 400px;
}
<form id="form1" runat="server">
<div>
<div id="list_wrapper">
<ul class="column-count: 2;">
<li>One: If I knew how to spell the ABC's I would write and write and write and write and write and write and write some more and write and write and write and write and write and write and write.</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
<li>Seven</li>
<li>Eight</li>
<li>Nine</li>
</ul>
</div>
</div>
</form>
Change anything ul (unordered list) to ol (ordered list).
CSS becomes:
ol{
margi... }
ol.multiple_columns li{
text-align: right;
float: ri... }
HTML becomes:
<ol class="column-count: 2;">
<li>One: If I knew ...</li>
<li>Two</li>
...
</ol>
In order to make the list numbers bold, but not the text, you would change the ol class in your CSS to include font-weight:900;:
ol {
margin: 0;
padding: 50;
font-weight: 900;
}
Then wrap the text of your <li> to include <span style="font-weight:normal;"></span>, like so:
<li><span style="font-weight:normal;">One: If I knew how to spell ... </span></li>
Without the span returning the text to a normal weight, the number and text will both be bold. BTW, font-weight ranges from 100-900. 900 is the heaviest weight available.
Related
Here's an example I've changed slightly from a previous SO question:
http://jsfiddle.net/tPjQR/72/
ol {
font-family: Georgia, serif;
}
ol span {
font-family: Arial, sans-serif;
font-size: 17px
}
<ol>
<li><span>Entry one</span></li>
<li><span>Entry two</span></li>
<li><span>Entrye three</span></li>
<li><span>Entry five</span></li>
<li><span>Entry six</span></li>
<li><span>Entry Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long Long</span></li>
</ol>
I would like to line up the columns so that, no matter how much text is in one column, the first characters of each column will be lined up.
E.g.
not
Entry one
Entry two
Entrye three
Entry five
Entry six
rather
Entry one
Entry two
Entrye three
Entry five
Entry six
Is there a way to do this with list items, or do I need to use a table?
Use the below code to get that design...
li span {
display:inline-block;
width: 25%;
}
<ol>
<li><span>Entry</span> one</li>
<li><span>Entry</span> two</li>
<li><span>Entrye</span> three</li>
<li><span>Entry</span> five</li>
<li><span>Entry</span> six</li>
</ol>
An alternative method...
ol {
list-style-type: none;
padding: 0;
}
ol li:before {
content: "Entry";
display: inline-block;
margin-right: 10px;
}
<ol>
<li>one</li>
<li>two</li>
<li>three</li>
<li>five</li>
<li>six</li>
</ol>
You can change your css
li span {
display:inline-block;
width:15%;
}
li p {text-align: left; display:inline-block; margin : 0px 45px;}
inline-block value of the display property makes this even easier
CSS margin properties are used to generate space around elements.
learn more about that CSS Margins
li span {
display:inline-block; width:15%;
}
li p {text-align: left; display:inline-block; margin : 0px 75px;}
<ol>
<li><span>Entry </span> <p>
one</p></li>
<li><span>Entry</span> <p>
two</p></li>
<li><span>Entryre</span> <p>
three</p></li>
<li><span>Entry</span> <p>
fiv</p></li>
<li><span>Entry</span> <p>
six</p></li>
</ol>
I usually code as the following:
.list01 {
width: 200px;
}
.list01 li {
overflow: hidden;
}
.col01 {
float: left;
width: 5em;
}
.col02 {
display: block;
overflow: hidden;
}
<ol class="list01">
<li><span class="col01">Entry</span><span class="col02">long long long one</span></li>
<li><span class="col01">Entry</span><span class="col02">two</span></li>
<li><span class="col01">Entrye</span><span class="col02">three</span></li>
<li><span class="col01">Entry</span><span class="col02">five</span></li>
<li><span class="col01">Entry</span><span class="col02">six</span></li>
</ol>
What you are trying to do is not possible beacuse the DOM object rendering is based on its architructure and what you want to do is possible through the tables.
* {
font-family: Georgia, serif;
}
<table>
<tr><td>Entry</td><td>One</td></tr>
<tr><td>Entry</td><td>Two</td></tr>
<tr><td>Entry Xyz</td><td>Three</td></tr>
<tr><td>Entry</td><td>Four</td></tr>
<tr><td>Entry</td><td>Five</td></tr>
<tr><td>Entry</td><td>Six</td></tr>
</table>
good evening. The below code is for my navigation bar on my website.The two unordered lists are currently sat side by side (inline) which is what I wanted. However, I would like the second sat over on the right had side. I know there are several ways to achieve this. My question is specific to this method, as I do not understand why it is happening. Why is it, if I add the following code to my style sheet (.float { float: right }), the second moves to the right, but does not stay 'inline' with the first ; it shows on a slightly different level? I do not understand why this is the case. Would someone be kind enough to explain?
Secondly, if I add a different class to each of the unordered lists and float one to the right and one to left, simaultaneously removing the CSS ( .nav ul {display: inline; ), I do not understand why it is that they sit 'inline' with each other? What is instructing them to do so? How does a float: right instruction, also instruct the element to move up besides the one on the left? Many Thanks
display: inline;
}
http://jsfiddle.net/mugman/rnmht1y2/
<body>
<div class="nav">
<div class="container">
<ul>
<li>Name</li>
<li>Browse</li>
</ul>
<ul class="float">
<li>Sign Up</li>
<li>Log In</li>
<li>Help</li>
</ul>
<style>
.nav a {
color: #5a5a5a;
font-size: 11px;
font-weight: bold;
padding: 14px 10px;
text-transform: uppercase;
}
.nav li {
display: inline;
}
.nav ul {
display: inline;
}
An element is said to be inline-level when the calculated value of its display CSS property is: inline, inline-block or inline-table. Visually, it doesn't constitute blocks of contents but is distributed in lines with other inline-level content. Typically content of a paragraph, being text, with different formatting like emphasis, or images, is made from inline-level elements.
(from: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Visual_formatting_model)
If you apply inline-block to your "nav ul" your elements will display inline.
.nav a {
color: #5a5a5a;
font-size: 11px;
font-weight: bold;
padding: 14px 10px;
text-transform: uppercase;
}
.nav li {
display: inline;
}
.nav ul {
display: inline-block;
}
.float {
float: right;
}
<!DOCTYPE html>
<body>
<div class="nav">
<div class="container">
<ul>
<li>Name</li>
<li>Browse</li>
</ul>
<ul class="float">
<li>Sign Up</li>
<li>Log In</li>
<li>Help</li>
</ul>
</div>
</div>
What I am looking to achieve is this:
<p class="parent">Paragraph text
<ul>
<li>One</li>
<li>Two</li>
</ul>
</p>
When I try
p.parent
| Paragraph text
ul
li One
li Two
It produces
<p class="parent">Paragraph text</p>
<ul>
<li>One</li>
<li>Two</li>
</ul>
Is there a way to achieve the desired nesting?
While nesting a <ul> within a <p> element is invalid HTML (so no, you can't do that), you can emulate it using, for example, <span> elements:
<p>Paragraph text <span>First span</span><span>Second span</span></p>
With the CSS:
p span {
display: block;
counter-increment: spanCount;
position: relative;
}
p span::before {
content: counter(spanCount);
margin-right: 0.4em;
width: 2em;
text-align: right;
}
JS Fiddle demo.
References:
'Generated content, automatic numbering and lists.'
I'm not sure how to build a horizontal list that looks like this:
Here are the rules:
There is an unlimited number of items in the list.
Each item should be on a single line and not wrap to a 2nd line.
Multiple items can be on a single line if there is space for them to fit
If multiple items are on a single line, they should be separated by a divider
The divider looks like a bullet, but it could be an image
Need it to work in modern browsers as well as IE8+
The thing I'm not sure how to do is to make the bullets appear only between items, and not also before or after each row of items.
For those of you who don't have to worry about IE8, this is as simple as:
ul li { list-style: none; display: inline; }
ul li:after { content: " \00b7"; }
ul li:last-child:after { content: none; }
This solution matches all of OP's requirements, except IE8 compatibility (that was 2013).
Simple markup. No JavaScript. No :last-child
Link to CodePen
ul {
display: inline-block;
padding: 0;
margin: .5rem;
text-align: center;
background-color: #fff;
}
li { display: inline; }
li a { white-space: nowrap; }
li:after {
content: " ";
letter-spacing: 1em;
background: center center no-repeat url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwAAADsABataJCQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAAAnSURBVBhXY/Dz89MA4sNA/B9Ka4AEYQIwfBgkiCwAxjhVopnppwEApxQqhnyQ+VkAAAAASUVORK5CYII=);
}
body { background-color: #D3D3D3; }
<div id="d">
<ul>
<li><a>Profile Image</a></li>
<li><a>Name</a></li>
<li><a>Activity Information</a></li>
<li><a>Distance</a></li>
<li><a>Pace</a></li>
<li><a>Points Earned</a></li>
</ul>
</div>
<div style="width: 20rem"><script>document.write(d.innerHTML)</script></div>
<div style="width: 10rem"><script>document.write(d.innerHTML)</script></div>
For almost all browsers, you can use the CSS3 selector last-child instead of JavaScript:
ul li { display: inline; white-space: pre; }
ul li:after { content: " \00b7 "; }
ul li:last-child:after { content: ""; }
The white-space: pre stops wrapping within list items (because usually you want it to wrap between list items), and is a hack that allows you to increase the space between list items by adding spaces on the second line.
u00b7 ⋅ (MIDDLE DOT) is the standard unicode character for interpuncts, but you could also use u2022 • (BULLET), u2b24 ⬤ (BLACK LARGE CIRCLE), U+2043 ⁃ (HYPHEN BULLET), or any other unicode character you choose.
Note that some characters may not be supported on all systems.
Here is a further improved version. I kept getting an inconsistency at certain page widths where two bullets would be missing rather than just the last one. i.e.
link1 · link2 · link3 link4
link5 · link6
I think the issue was that removing the last bullet separator could itself affect the text flow if the page width was just right. The new script locks the original text flow by adding and removing literal line breaks.
I have the same script to run every time the screen is resized so you don't get stuck with awkward line breaks.
<style>
ul { width: 700px; text-align : center }
ul li { display: inline; white-space: nowrap; }
ul li:after { content: " \00b7"; }
ul li.nobullet:after { content: none; }
</style>
<body onresize="processBullets()" onload="processBullets()">
<ul>
<li>Harvard Medical School</li>
<li>Harvard College</li>
<li>Harvard Medical School</li>
<li>Harvard College</li>
<li>Harvard Medical School</li>
<li>Harvard College</li>
<li>Harvard Medical School</li>
<li>Harvard College</li>
</ul>
<body>
<script>
function processBullets() {
var lastElement = false;
$("br").remove(".tempbreak");
$("ul li").each(function() {
$(this).removeClass("nobullet");
if (lastElement && lastElement.offset().top != $(this).offset().top) {
$(lastElement).addClass("nobullet");
$(lastElement).append('<br class="tempbreak" />');
}
lastElement = $(this);
}).last().addClass("nobullet");
}
</script>
If you don't mind creating a PNG image (with transparent background) of the bullet (or other separator), then you can use a natural space between the list items painted with this as the background.
Where the list items wrap onto the next line, the space---and thus its background---won't be rendered.
This avoids layout issues relating to the space taken up by the separator, as well as avoiding any Javascript/jQuery, taking advantage of the browser's own layout engine to do the work. You can adjust the space for the separator with the word-spacing attribute.
You'll need to ensure there is no other whitespace within the markup that might otherwise be used as the natural space. You could use a higher-res image than the 5x5 here, in conjunction with background-size, so that it still looks ok when zooomed, but note IE8 doesn't support scaling of background images. The other drawback is that if you want to change the colour you'll have to edit the PNG.
FIDDLE
Code based on modifying #bleuscyther's answer:
CSS :
ul { max-width: 700px; padding: 0; text-align: center; }
ul li { display: inline; white-space: nowrap; }
ul .separator {
word-spacing: 1.1em;
background-repeat: no-repeat;
background-position: 50% 60%;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAOElEQVQI113M0Q3AIBRC0aM76P7jmHSmSj/6mibyc4EQkEEWuYtDmU1SXO1d6H7tjgupIl8+P+cD22cff9U1wbsAAAAASUVORK5CYII=);
}
HTML :
<ul>
<li>Harvard Medical School</li><span class='separator'>
</span><li>Harvard College</li><span class='separator'>
</span><li>Harvard Medical School</li><span class='separator'>
</span><li>Harvard College</li><span class='separator'>
</span><li>Harvard Medical School</li><span class='separator'>
</span><li>Harvard College</li><span class='separator'>
</span><li>Harvard Medical School</li><span class='separator'>
</span><li>Harvard College</li>
</ul>
user2511031's solution is almost ideal... it's just not a valid HTML. There should not be any SPAN outside LI, inside UL.
But it doesn't mean that there is no really ideal solution. I found one!
No need to put the spans allover and clean white-spaces in the markup. Place the needed space into the ":after" pseudo element content, apply the background image to it.
It does the same!
ul { max-width: 700px; padding: 0; text-align: center; }
ul li { display: inline; white-space: nowrap; }
ul li:after {
content: " ";
word-spacing: 2em;
background-repeat: no-repeat;
background-position: 50% 60%;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAOElEQVQI113M0Q3AIBRC0aM76P7jmHSmSj/6mibyc4EQkEEWuYtDmU1SXO1d6H7tjgupIl8+P+cD22cff9U1wbsAAAAASUVORK5CYII=);
}
Here's the Fiddle
I just used text-indent to successfully style a bulleted list as follows:
HTML:
<ul class="horizontal">
<li>Payment</li>
<li>Check</li>
<li>Direct Deposit</li>
</ul>
CSS:
ul.horizontal li {
list-style-type:disc;
float: left;
text-indent:-4px;
margin-right:16px;
}
In the simplest of ways, all you would require is setting text-align: center on the ul and display: inline-block on li in your stylesheet.
You can use an image as a separator if you wish by leveraging the :after pseudo class on li.
Here's an example.
http://jsfiddle.net/caramba/tSnnP/
<div>
<ul>
<li><span class="icon bull"></span>xxx</li>
<li><span class="icon bull"></span>xxx</li>
<li><span class="icon bull"></span>xxx</li>
</ul>
<ul>
<li><span class="icon bull"></span>xxx</li>
<li><span class="icon bull"></span>xxx</li>
<li><span class="icon bull"></span>xxx</li>
<li><span class="icon bull"></span>xxx</li>
<li><span class="icon bull"></span>xxx</li>
</ul>
</div>
<style type="text/css">
div {
white-space: nowrap;
width: 100%;
}
span {
display:inline-block;
margin:0 5px;
}
ul {
text-align:center;
}
ul li {
display:inline;
margin:20px;
}
.hide {
display:none;
}
.icon {
position:relative;
display:inline-block;
background-position:-1000px -1000px;
background-image:url(http://www.alexander-bown.com/wp-content/uploads/2011/05/big-black-dot.jpg);
background-repeat:no-repeat;
background-size:5px 5px;
width:5px;
height:5px;
}
.icon {
background-position:0px 0px;
top:-2px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('ul li:first-child').children('span').addClass("hide");
});
</script>
ul li {
display: inline;
text-align: center
}
.separator {
display: inline-block;
background-color: black;
width: 5px;
height: 5px;
border-radius: 45px;
vertical-align: middle;
}
<ul>
<li>item 1</li> <div class='separator'></div>
<li>item 2</li> <div class='separator'></div>
<li>item 3</li> <div class='separator'></div>
<li>item 4</li> <div class='separator'></div>
<li>item 5</li>
</ul>
You can also build this in JavaScript using a loop and concatenating a new li for x amount of list items but seeing as your post doesnt say anything about a dynamically generated list I'll leave it just as this for now.
<table>
<tr>
<td>
<ul>
<li>First menu item</li>
</ul>
</td>
<td>
<ul>
<li>Second menu item</li>
</ul>
</td>
<td>
<ul>
<li>Third menu item</li>
</ul>
</td>
</tr>
</table>
So what I need help with, is how do I remove the newline after a <li> and or <ul>
This is my css:
#ranks li {
background: url(/img.png) no-repeat top left;
}
#ranks .sprite-admin{ background-position: 0 0; width: 157px; height: 44px; }
#ranks .sprite-banned{ background-position: -207px 0; width: 157px; height: 44px; }
and this is the html:
<ul id="ranks"><li class="sprite-admin"></li></ul>
It all works well while only one of the <ul id ="etc"> is there, but if there are multiple, it will make a new line and 'stack' them.. is it possible to make them not stack, and just go left to right?
Thanks
EDIT:
Demo : /removed/
You have a few options:
#ranks li {
float: left;
}
This will float all of your list items to the left, without wrapping, until horizontal screen space is no longer available. Alternatively,
#ranks li {
display: inline-block;
}
Which will also put your elements side-by-side, but handle them as bock level elements. If you don't care about block-level styling, you could go with straight inline-display:
#ranks li {
display: inline;
}
Which will treat the list items like any other inline element (such as <span> or <a>).
There are some other inherent styles that exist on list items, as well as their list parent, that you may need to do away with. Be sure to check out margin, and padding.
Demo: http://jsbin.com/iconud/edit#html,live
Look Out Ahead!
You may find that there is an unsightly gap between your list items when they're positioned side-by-side. This is a common problem with inline-lists. One solution is to remove the newline space between closing and opening list item tags:
<ul id="ranks"><li>
Index</li><li>
Contact</li><li>
Portfolio</li>
</ul>
Or have them all inline, a little less discernible:
<ul id="ranks">
<li>Index</li><li>Contact</li><li>Portfolio</li>
</ul>
This is a little tough on the eyes. With HTML, since closing tags aren't always required, you can also leave off the closing tag (though this makes me a bit nervous):
<ul id="ranks">
<li>Index
<li>Contact
<li>Portfolio
</ul>
Multiple Lists Inline Too!
From some of the OP's comments, it appears they might be trying to get not only list items inline, but lists themselves. If that's the case, apply the same aforementioned rules to the lists themselves:
#ranks,
#specs {
margin: 0;
padding: 0;
display: inline-block;
}
#ranks li,
#specs li {
display: inline-block;
border: 1px solid #CCC;
padding: 5px 10px;
}
Here were have identified two sets of rules using selectors that search for id's, and then tags. You could simplify this by apply a common class to the lists, or by basing the selectors off of a common parent element. Next is the markup:
<ul id="ranks">
<li>Index</li>
<li>Contact</li>
<li>Portfolio</li>
</ul>
<ul id="specs">
<li>Foo</li>
<li>Bar</li>
</ul>
This results in both lists, and their items, being displayed in a horizontal fashion.
Demo: http://jsbin.com/iconud/2/edit
with some css
<style type="text/css">
#ranks li { display:block; float:left; }
</style>
updated as comments: with display:block
ul li{ display:inline;} do the trick?
<li> by default is display:block;
if you give it display:inline; or diplay:inline-block; that should remove the linebreak
This is a basic example of horizontal UL's
HTML
<ul id="list">
<li class="item">Item 1</li>
<li class="item">Item 2</li>
<li class="item">Item 3</li>
</ul>
<span class="clearFloats">
CSS
.item {
float: left;
}
.clearFloats {
clear: both;
}
JSFiddle Example: http://jsfiddle.net/peterf/DEUBf/
Another option is to set font-size: 0 in the ul, then restore the desired font-size in the li tags. I prefer this as it's contained within the ul tag, doesn't need further hacks like clear:both, and explains better what the styling is meant to do (hide anything not inside a list item).
ul {
list-style-type: none;
font-size: 0;
}
li {
display: inline-block; /* Or inline, as you like */
font-size: 16px;
}