Multiple ID selectors aren't working - html

So i have two Divs like this:
<div id="first_content">
<ul>
<li>This</li>
<li>text</li>
<li>should</li>
<li>be</li>
<li>displayed</li>
<li>in</li>
<li>one</li>
<li>line</li>
</ul>
</div>
<div id="second_content">
<ul>
<li>This</li>
<li>text</li>
<li>should</li>
<li>be</li>
<li>displayed</li>
<li>in</li>
<li>one</li>
<li>line</li>
</ul>
</div>
And CSS:
#first_content, #second_content ul {
list-style: none;
}
#first_content, #second_content ul li {
display: inline;
}
It doesn't work (at least on firefox 34). Style applies only to one ID.
When i remove one of these ID selectors, another one works fine.
I guess it should work? what's wrong?

try:
#first_content ul, #second_content ul {
list-style: none;
}
#first_content ul li, #second_content ul li {
display: inline;
}
if you are trying to select the ul's and li's of both containers you need to specify this with both selectors.

Basic CSS
.foo, .bar { ... }
are two separate selector chains. You have:
#first-content, #second_content ul
^--- applies to <div id="first-content">
^^^^^^^^^^--- applies to any <ul> inside <div id="second-content">
<div> tags do not have a list-style, so your first rule doesn't do anything for the first <div> set. For your other rule set, display-inline will apply to the parent div for first-content, and to the <li> tags in the second-content area.

Here is some css:
#navcontainer ul
{
margin: 0;
padding: 0;
list-style-type: none;
text-align: center;
}
#navcontainer ul li { display: inline; }
#navcontainer ul li a
{
text-decoration: none;
padding: .2em 1em;
color: #fff;
background-color: #036;
}
#navcontainer ul li a:hover
{
color: #fff;
background-color: #369;
}
And some HTML:
<div id="navcontainer">
<ul>
<li>Milk</li>
<li>Eggs</li>
<li>Cheese</li>
<li>Vegetables</li>
<li>Fruit</li>
</ul>
</div>
These should produce the desired effect. Source: http://css.maxdesign.com.au/listutorial/horizontal_master.htm

Multiple id concatenation has never worked in Firefox. For example, I am using 67.0 (64-bit) and the following CSS works as intended:
#noDisplay {
display: none;
}
#togForm {
display: none;
}
...but if I concatenate that, as shown below, it does not work (one id working, the other not working), and this has always been the case.
#noDisplay,#togForm {
display: none;
}
I know that sometimes the reason is because of conflicting entries, but display: none on its own? - Argue with that if you can!

Related

Why a white-space is occuring before a direct child in li tag if I use list-style:inside decimal?

This is my following CSS piece of code
ol{
padding-left:0;
list-style: inside decimal;
}
ol li :first-child{
display: inline;
}
<ol>
<li>
<p>Item 1</p>
</li>
<li>
Item 2
</li>
</ol>
Whenever HTML is rendered into a browser there is a white-space being added, Any specific reason for that?
There are a few ways of getting around this problem:
Use Flexbox to create the horizontal list of items instead of trying an inline-block solution. This handles everything for you, and is definitely the preferred solution:
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
}
If you need to rely on inline-block, you could set the font-size of the list to 0. This only works if your blocks are not sized with ems (based on the font-size, so the block size would also end up being 0). rems would be a good choice here:
ul {
font-size: 0;
...
}
li {
display: inline-block;
width: 2rem;
height: 2rem;
...
}
Or you could set negative margin on the list items:
li {
display: inline-block;
width: 2rem;
height: 2rem;
margin-right: -0.25rem;
}
You can also solve this problem by putting your list items all on the same line in the source, which causes the whitespace nodes to not be created in the first place:
<li></li><li></li><li></li><li></li><li></li>
Credits :https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace
display:inline is not apply to p tag
ol{
padding-left: 0;
list-style: inside decimal;
}
ol li:first-child{
display: inline;
background: red;
}
ol li:first-child > p {
background: blue;
}
<ol>
<li>
<p>Item 1</p>
</li>
<li>
Item 2
</li>
</ol>
use display:inline to p tag also..
ol{
padding-left:0;
list-style: inside decimal;
}
ol li :first-child{
display: inline;
background: red;
}
ol li:first-child > p{
display: inline;
background: blue;
}
<ol>
<li>
<p>Item 1</p>
</li>
<li>
Item 2
</li>
</ol>
also you can add below code for removing default margin & padding for all html tag ...
*,*::after, *::before{
box-sizing: border-box;
margin: 0;
padding: 0;
}

Put a <br> only within inline list element itself

I would like to put a line break into an inline list to produce this result:
However when I put a line break into my basic list, this is the result I get:
How would I make it so that I can put a br within the li element only without, messing up the horizontal list itself.
li {
list-style-type: none;
display: inline;
}
<ul>
<li>Hello</li>
<li>Bonjour</li>
<li>Longer<br>text</li>
<li>Aloha</li>
</ul>
Use display: inline-block; instead:
li {
list-style-type: none;
display: inline-block;
}
<ul>
<li>Hello</li>
<li>Bonjour</li>
<li>Longer<br>text</li>
<li>Aloha</li>
</ul>
Instead of styling the li with
display:inline;
You could achieve the desired effect by
float:left;
Use display: inline-block
Here is working snippet
ul{
list-style:none;
}
ul li{
padding:20px;
display:inline-block;
}
<ul>
<li>Hello</li>
<li>Bonjour</li>
<li>Longer<br>text</li>
<li>Aloha</li>
</ul>

Why is my unordered navigation list not displaying as inline?

I have tried creating a div, deleting the div, trying to get the ul displayed as inline, everything, but my unordered list is still not displaying as inline. What am I missing?
p {
font-family: orbitron;
}
h1 {
color: black;
text-align: center;
font-family: orbitron;
}
ul {
dispaly: inline;
}
<nav>
<ul id="navigation_bar">
<li class="About">About Game</li>
<li>Screenshots</li>
<li>About creator</li>
<li>Forums</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
Not the ul should be inline, the lis in the ul should be. Change your selector like this:
ul li {
display: inline;
}
or this:
ul > li {
display: inline;
}
Also, you’ve got a typo: dispaly should be display.

CSS-how to text-indent a nested unordered list

I do not know if this is possible, but I'm trying to indent the <li> in red to wrap underneath itself with CSS. I've used text-indent, padding, margin, and cannot get it to work. The <li> in red seems to be set at the same x/y coordinate as the green text. It only lets me push it away from the time (in green).
I can use a table, but I'm trying to accomplish this with CSS.
The image above is where I am at. The image below is what I am after.
HTML
<div class="agendaList">
<ul>
<li>Day, Month Date</li>
<ul>
<li>0:00 am</li>
<li>This is where the event description will appear. I would like for it to wrap under itself and not under the time. How do I start the wrap at the first word in the first sentence (This) of this <li>.</li>
</ul>
</ul>
<ul>
<li>Day, Month Date</li>
<ul>
<li>0:00 am</li>
<li>This is where the event description will appear. I would like for it to wrap under itself and not under the time. How do I start the wrap at the first word in the first sentence (This) of this <li>.</li>
</ul>
</ul>
</div>
CSS
.agendaList ul ul {
list-style: disc;
/* list-style-image: url(bullet.gif); */
margin-left: 0;
padding-left: 0;
}
.agendaList ul ul li {
display: inline;
list-style: none;
color: green;
}
.agendaList ul ul li:last-child {
display: inline;
color: red;
list-style-position: inside;
padding: 10px 0 10px 20px;
text-indent: -1em;
}
Here are two options:
Absolutely position the first li element and then use a margin to add space to the second list item.
Example Here
.agendaList ul ul li:first-child {
position: absolute;
}
.agendaList ul ul li:last-child {
display: inline-block;
color: red;
list-style-position: inside;
margin-left: 65px;
}
Alternatively, a better option would be to set the display of both li elements to table-cell. Add white-space:nowrap to the first li in order to prevent the text from wrapping.
Example Here
.agendaList ul ul li {
display:table-cell;
list-style:none;
color:green;
}
.agendaList ul ul li:first-child {
white-space:nowrap;
}
.agendaList ul ul li:last-child {
color: red;
list-style-position: inside;
padding-left:20px;
}

Spacing between two <li> elements

I've written the folloning code:
<ul>
<li>Text</li>
<li>text</li>
</ul>
and styles:
list-style-type: none;
padding: 5px;
display: inline;
background-color: #A9A9A9;
But i have spacing between two li elements like the following:
How can I remove this spacing?
By put them inline
<ul>
<li>Text</li><li>text</li>
</ul>
Js Fiddle Demo
If you float your li items, it should remove the margin between li output.
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
ul {
list-style-type: none;
}
ul li {
float:left;
padding: 5px;
display: block;
background-color: #A9A9A9;
}
Here are two common ways to avoid the space:
<ul>
<li>
one</li><li> <!-- use this to avoid the linebreak -->
two</li><li>
three</li>
</ul>
Or you can use Comments:
<ul>
<li>one</li><!--
--><li>two</li><!-- Comments so there is no white-space
--><li>three</li>
</ul>
You can check it in this Demo
You get the space because there is some space between the elements.
(Tabs, Newline count as space ). With this Minimized HTML it should work :)
You can read more about it here Examples at CSS-Tricks
try floats and use list-style-type for ul:
ul {
list-style-type: none;
}
li {
padding: 5px;
float:left;
background-color: #A9A9A9;
}
Just Add float:left in your Css
ul li {
background-color: #A9A9A9;
display: inline;
float: left;
padding: 5px;
}
Demo
There are many ways as mentioned above few of them..however you can achieve with another method. using font-size:0
ul
{font-size:0; /*This will remove the space totally*/
list-style-type: none;
}
li{
padding: 5px;
display: inline;
background-color: #A9A9A9;
font-size:16px; /*This is important line so the font come again in same shape*/
}
Here is the Demo.