ul {
width: 250px;
}
li {
margin: 10px;
}
ul.illuminations {
list-style-position: outside;
}
ul.season {
list-style-position: inside;
}
ul.2 {
list-style: inside circle;
width: 300px;
}
li.3 {
margin: 100px;
}
<ul class="illuminations">
<li>That idol, black eyes and yellow mop, without parentsw our court ...</li>
<li>Gracious son of Pan! Around your forehead crowned with flowerets ...</li>
<li>When the world is reduced to a single dark wood for our four...</li>
</ul>
<hr />
<ul class="season">
<li>Once, if my memory serves me well, my life was a banquet...</li>
<li>Hadn't I once a youth that was lovely, heroic, and fabulous...</li>
<li>Autumn already! - But why regret the everlasting sun if we are</li>
</ul>
<hr />
<h1>Quotes from Edgar Allan Poe</h1>
<ul class="2">
<li class="3">I have great faith in fools; self-confidence my friends call it.</li>
<li class="3">All that we see or seem is but a dream within a dream.</li>
<li class="3">I would define, in brief, the poetry of words as the rhythmical creation of beauty.</li>
</ul>
The first two lists do acquire the different marker positions. However, the last list doesn't acquire the list style and width attributes that I intend it to by using the more specific declarations. This is a problem I've encountered many times now. Why is this and how am I supposed to target specific elements in order to override attributes?
CSS identifiers can't begin with a digit. So .2 and .3 are invalid selectors. You can escape them as .\32 and .\33.
ul {
width: 250px;
}
li {
margin: 10px;
}
ul.\32 {
list-style: inside circle;
width: 300px;
}
li.\33 {
margin: 100px;
}
<ul class="2">
<li class="3">I have great faith in fools; self-confidence my friends call it.</li>
<li class="3">All that we see or seem is but a dream within a dream.</li>
<li class="3">I would define, in brief, the poetry of words as the rhythmical creation of beauty.</li>
</ul>
Related
I have a site which lists the line of succession to the British crown. As the line of succession is an ordered list, the main part of the site is in an <ol>.
However, there's a wrinkle. People occasionally drop out of the line of succession (most commonly for marrying a Catholic). For example, see Prince Michael of Kent is listed as 16th in line on 1978-06-29, but the next day he has vanished from the list as he married a Catholic on that date.
Currently, as you see, I just drop people from the list when they are excluded from the succession. But actually, I'd like to include them, but use a "dimmed" typeface for their entries in the list. But that gives me another problem. I can then no longer use an ordered list as excluded people don't have a position in the succession. So I need to omit the number from some items in an ordered list.
So I'm looking for the best approach to simulate an ordered list, but with the ability to omit the numbers on some list items. I have a few ideas:
Switch to a <ul> and add my own numbers. Can I style it to remove the bullets and outdent the numbers?
Switch to just using outdented paragraphs.
Use a table with a very narrow first column.
But I wonder if there's a CSS and/or HTML trick that I'm missing. Is there any easier way to achieve what I'm looking for?
Update: The current HTML looks like this:
<ol>
<li itemscope itemtype="http://schema.org/Person"><span itemprop="name">The Prince Charles, Prince of Wales</span>
<br><span class="small">Age 69
(born <a title="Line of Succession on 14 November 1948" href="/1948-11-14">14 November 1948</a>),
<br>Son of the sovereign</span></li>
<li itemscope itemtype="http://schema.org/Person"><span itemprop="name">Prince William, Duke of Cambridge</span>
<br><span class="small">Age 35
(born <a title="Line of Succession on 21 June 1982" href="/1982-06-21">21 June 1982</a>),
<br>Grandson of the sovereign</span></li>
<li itemscope itemtype="http://schema.org/Person"><span itemprop="name">Prince George of Cambridge</span>
<br><span class="small">Age 4
(born <a title="Line of Succession on 22 July 2013" href="/2013-07-22">22 July 2013</a>),
<br>Great grandson of the sovereign</span></li>
<li itemscope itemtype="http://schema.org/Person"><span itemprop="name">Princess Charlotte of Cambridge</span>
<br><span class="small">Age 2
(born <a title="Line of Succession on 02 May 2015" href="/2015-05-02">02 May 2015</a>),
<br>Great granddaughter of the sovereign</span></li>
...
</ol>
The CSS is all standard Bootstrap 4.0. Oh, except this bit:
span.small {
font-size: 75%;
}
You can use css counters. Also you have to add a class to the omitted element.
Stack Snippet
ul {
font: 13px Verdana;
list-style: none;
counter-reset: list;
padding: 0;
}
ul>li:not(.disable):before {
counter-increment: list;
content: counter(list) ": ";
position: absolute;
left: 0;
}
ul>li {
position: relative;
padding-left: 20px;
}
ul>li.disable {
opacity: .5;
}
<ul>
<li>Text</li>
<li>Text</li>
<li class="disable">Text</li>
<li>Text</li>
<li>Text</li>
<li>Text</li>
<li>Text</li>
<li>Text</li>
</ul>
You could use css counters
ol {
counter-reset: item;
list-style: none;
margin: 0;
padding: 0;
}
ol li {
display: block;
padding: 0 0 0 2.5em;
margin: 0;
position: relative;
}
ol .counted:before {
content: counters(item, ".") " ";
counter-increment: item;
position: absolute;
left: 0;
top: 0;
display: inline-block;
width: 2.5em;
}
ol .level1>li {
margin: 0;
padding-left: 0;
}
ol .level1>.counted:before {
left: -2.5em;
font-weight: normal;
}
ol .level2>.list-item {
padding-left: 2.5em;
}
ol .level2>.list-item:before {
left: -1em;
width: 3.5em;
}
.not-counted {color:green;}
<ol>
<li class="counted">
this is counted
<ol class="level1">
<li class="counted">
this is counted
</li>
<li class="not-counted">
this is not counted
</li>
<li class="counted">
this is counted
<ol class="level2">
<li class="counted">
this is counted
</li>
<li class="not-counted">
this is not counted
</li>
<li class="counted">
this is counted
</li>
</ol>
</li>
</ol>
</li>
<li class="not-counted">
this is not counted
</li>
<li class="counted">
this is counted
</li>
</ol>
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>
I'm trying to build a drop-down menu using CSS, and I've successfully hidden the drop down menu, but haven't been able to make it reappear. I'm pretty sure that the problem is with the :hover tag, which I've taken out of the css here because I haven't been able to make it work. Help with the CSS? PLEASE? Desperate.
HTML Code:
<div id="navigation">
<ul id="menu">
<li class="menu">Home</li>
<li class="menu">About Us</li>
<ul class="sub_menu">
<li>Our Mission Statement</li>
<li>How Funds Are Spent</li>
<ul class="sub_sub_menu">
The Founders
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
</ul>
</ul>
<li class="menu">What We Do</li>
<ul class="sub_menu">
<li>T-Shirt Designs</li>
<li>Future Design Ideas</li>
<ul class="sub_sub_menu">
Fact Sheets
<li>How Our Fact Sheets Work</li>
<li>Fact Sheet 1</li>
</ul>
</ul>
<li class="menu">Media</li>
<li class="menu">Contact Us</li>
</ul>
</div>
CSS is as follows:
ul {
position: absolute;
list-style-type: none;
margin: 0;
padding: 0;
padding-top: 0px;
padding-bottom: 0px;
}
li.menu {
display: inline
}
a:link, a:visited {
font-weight: bold;
font-size: 14px;
color: #FFFFFF;
background-color: #B4B7BD;
text-align: center;
padding-top: 3px;
padding-bottom: 3px;
padding-right: 20px;
padding-left: 20px;
text-decoration: none;
text-transform: uppercase;
}
a:hover, a:active {
background-color: #B4B7BD
}
ul.sub_menu li {
position: relative;
display: none;
width: 100%;
}
ul.sub_sub_menu {
position: relative;
display: none;
}
ul.sub_sub_menu li {
position: relative;
display: none;
width: 100%;
left: 100%;
}
HTML issues
First of all
<ul class="sub_sub_menu">The Founders
It's illegal to have text inside an unordered list tag, if this is meant to the the title of the list, then the title needs to be the text/link in the list item that the unordered list is nested inside of.
Also, you've done this several times:
<li class="menu">About Us</li>
<ul class="sub_menu">
<li>Our Mission Statement</li>
<li>How Funds Are Spent</li>
</ul>
where your code needs to be:
<li class="menu">About Us
<ul class="sub_menu">
<li>Our Mission Statement</li>
<li>How Funds Are Spent</li>
</ul>
</li>
You can see, the unordered list is nested properly in the second example, however in the first on it's not, causing you issues.
Those are the HTML problems I think, now to the css.
CSS issues
You should only have to add code to your css to make that work, here is an example of how to make the first submenu show up when you rollover a menu item.
li.menu:hover ul li {
display: block;
}
Just repeat that for the various sub & sub-sub menues you have.
The last thing is your use of selectors is a little sketchy, if you have ".sub_menu" as a class, then you don't need to prefix it with the element type unless multiple types of elements with the class and you want to select a single one, which is something I can't see you doing with your site, so instead of:
li.menu
ul.sub_menu
ul.sub_sub_menu
just use the class as a selector:
.menu
.sub_menu
.sub_sub_menu
This practice is faster for rendering in modern browsers, and clearer to read in many ways.
And there you go! it should all work nicely now.
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;
}
Ok, so i have an unordered list with a background applied to it.
I also have list items with classes so
i can specify the width of each one individually.
Why can i not see the changes like width i added to the classes on each list?
although i do see it in Dreamweaver design view.
<ul id="graph">
<li class="1"><span>HTML</span></li>
<li class="2"><span>CSS</span></li>
<li class="3"><span>Javascript</span></li>
<li class="4"><span>SEO</span></li>
<li class="5"><span>Photoshop</span></li>
</ul>
#graph li {
list-style-type: none;
display: block;
background-image: url(../img/graph_bg.gif);
background-repeat: repeat-x;
margin-top: 20px;
}
#graph li .1 {
height: 35px;
display: block;
width: 85%;
}
etc , etc
I believe that 1, etc are not valid class names. I suspect they need to start with a letter.
Edit: on an unrelated note, is there any reason why you have <span> tags inside the <li> tags?