What is the point in styling a ul? I Have a following html structure
<div id='container'>
<div id='ui' class='quad'>
<div class='quadNav'>
<span class='quadTitle'>Urgent And Important</span>
<i class="fa fa-plus fa-2x addButton"></i>
</div>
<ul class='taskList'>
<li>Test</li>
<li>Test2</li>
</ul>
</div>
and the following css for styling the list
.taskList{
}
.taskList li{
list-style-type:none;
position:relative;
top:2em;
left:1.2em;
}
with the .taskList section empty the li elements will style as I want them to. But if I remove the .taskList section, the li's no longer style. What gives? What is supposed to go into the styling of a ul element vs a li element, I don't understand.
edit
I may not have properly worded my question, I have the following css
<style>
/* -------- General Styling ---------*/
*{
margin:0;
padding:0;
}
html, body {
font-size:20px;
}
#container{
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
}
/*--------Quadrant Style ------- */
.quad{
position: relative;
width: 49.85%;
height: 49.8%;
font-size: .8em;
border: solid 1px black;
}
#ui{
float: left;
background-color: green;
}
#nui{
float: right;
background-color: red;
}
#uni{
float: left;
background-color: blue;
}
#nuni{
float:right;
background-color:yellow;
}
/*------- Quadrant Navigation Styling ------- */
.quadNav{
position:relative;
width:100%;
top:1em;
}
.quadTitle{
position: relative;
left:1em;
}
.addButton{
position:relative;
float:right;
right: 1em;
}
/*---------- task list styling ----------*/'
.taskList{
}
.taskList li{
list-style-type:none;
position:relative;
top:2em;
left:1.2em;
}
When I remove the empty .taskList{} declaration the .tasklist li styles stop working. I am trying to figure out why.
This could happen if you have an error in the preceding CSS, e.g.
.broken {
something
/* note no closing brace */
.taskList{
}
.taskList li{
list-style-type:none;
position:relative;
top:2em;
left:1.2em;
}
Now, the .taskList { line is actually inside the .broken {...} block, and the closing brace for .taskList closes that, so the following .taskList li { block works ok. But if you remove the .taskList block, you now wind up with the .taskList li styling inside the erroneous block, and your styling stops working.
EDIT: in your updated code, I can see the problem is a stray apostrophe on the line
/*---------- task list styling ----------*/'
Remove the trailing ' and it will fix it
the reason you lose the styling when you take out the taskList is because in your CSS you are targeting any li that is a child of a class called taskList. The reason you should do this is if you choose to have another set of li's on the page or any other page that may share this stylesheet you can style them differently by targeting a different class name. As far as the ul goes, if you do not use normalize or a css reset, ul's indent naturally without having to style it that way.
The li styling you currently have is applied only to the sub elements of the .taskList class.
If you want it to apply to all li's change your css to this:
li{
list-style-type:none;
position:relative;
top:2em;
left:1.2em;
}
You have:
.taskList li{
list-style-type:none;
position:relative;
top:2em;
left:1.2em;
}
So you are able to select lis in the ul with class of taskList and that's why style will be applied on those lis but if you remove the class taskList from the ul then the style won't be applied in the lis inside the ul with class taskList because you didn't add styles to lis directly.
If you want to style lis in any place of your page then you may use something like this:
li {
/*rules*/
}
Also to apply styles on all lis inside ul with class taskList you don't need to add a blank selection like you did in your question which is:
.taskList {
}
This is unnecessary in this case. You can apply stiles on all of your lis inside ul with class taskList even without the blank .taskList{...} in your stylesheet.
The problem is on the comment line right before .taskList{}, here you see:
Then when you keep the .taskList{}, that rule will be seen as invalid, while the next rules are OK, if removing that rule, then the rule .taskList li{} will be invalid, hence your problem.
Demo.
Related
I am trying to create a tabs for my page, but my links are not appearing horizontally. I have used float:left which is used to make links appear horizontally. Please let me know why?
<html>
<head>
<title>Test</title>
<style type="text/css">
#navbar #holder ul {
list-style: none;
margin: 0;
padding:0;
}
#navbar #holder ul li a {
text-decoration:none;
float: left;
line-height:20px;
margin-right:5px;
font-family:Calibri;
color:#000;
}
</style>
</head>
<body bgcolor="SteelBlue">
<div id="navbar">
<div id="holder">
<ul>
<li>Home</li>
<li>Product</li>
<li>Mixers</li>
<li>Others</li>
</ul>
</div>
</div>
</body>
</html>
The float left property needs to be applied to the Li element.
In your code it is being applied to the a element within the Li.
This can work, but if the parent element has any height (or if overflow:hidden is applied to it), they will stack up underneath each other and the starting position for the child elements will be on the left, so float:left won't change their position.
It might be easier to think of the list elements as being for layout and positioning, and the anchor element for visual appearance.
#navbar #holder ul {
list-style: none;
margin: 0;
padding:0;
}
#navbar #holder ul li {
float:left;
}
#navbar #holder ul li a {
text-decoration:none;
line-height:20px;
margin-right:5px;
font-family:Calibri;
color:#000;
display:block;
}
The links are appearing horizontally for me:
JSFiddle
Are you viewing the links in a small viewport?
Also, what browser are you using?
It is also more common for the float: left property to be applied to the li element, not the enclosed a element.
I am getting a problem with my project where our client has used a logo image inside the menu's ul li. He has used a class with li where the logo is placed but I cant use the class with it; I also do not want to use :nth-child because in future we may add a new menu element. I currently have an empty anchor inside the logo li. Is it possible in the CSS to select this anchor which is empty. Please help me.
Thanks in advance
Client Site: http://www.kangaroopartners.com/about/
My Site: http://kangaroopartners-2.hs-sites.com/test1
Demo http://jsfiddle.net/thwkav0e/
CSS and HTML:
ul {
display:block;
width:100%;
text-align:center;
list-style: none;
margin:0;
padding:0;
}
ul li {
display:inline-block;
padding: 10px;
}
ul li:nth-child(4), ul li:last-child {
background:red;
width:50px;
}
<ul>
<li>Hello1</li>
<li>Hello2</li>
<li>Hello3</li>
<li></li>
<li>Hello4</li>
<li></li>
</ul>
:empty selector should be what you are looking for.
ul li a:empty {
background:red;
width:50px;
display: inline-block;
height: 10px;
}
http://jsfiddle.net/thwkav0e/1/
I created a very simple HTML page which has a list and a paragraph. The problem is that the paragraph appears to the right of the list. If I create another paragraph, it is placed correctly. I would like the first one to show in the same manner.
<body>
<ul>
<li>(...)
<li>(...)
<li>(...)
<li>(...)
</ul>
<p>This text is to the right of the list.</p>
<p>This text is in a new line and is left-aligned.</p>
</body>
I don't refer to paragraphs anywhere in my CSS file and this is the part relating lists:
ul {
list-style: none;
margin 0;
}
li {
float: left;
}
Add this
ul:after{
content:'';
display:table;
clear:both;
}
DEMO
This has to be done whenever you use floats. Best practice is to make a class like this -->
.clearfix:after{
content:'';
display:table;
clear:both;
}
and add this class to the parent block if the child is floated .Always try to follow this step.
For more detailed explanation refer this link -- > http://www.impressivewebs.com/clearing-floats-why-necessary/
Don't use float: *; if you don't know what the floating an element does. float takes an element out of the normal flow. However, you want to show the li on a single line without loosing their display: block; properties. That's exactly what display:inline-block; is for (demo):
ul {
list-style: none;
margin 0;
}
li {
display: inline-block;
}
See it in action HERE
The code
HTML
<body>
<ul>
<li>(...)</li>
<li>(...)</li>
<li>(...)</li>
</ul>
<p>This text is to the right of the list.</p>
<p>This text is in a new line and is left-aligned.</p>
</body>
CSS
ul {
list-style: none;
margin 0;
padding: 0;
}
li {
float: left;
margin-right:10px;
}
li:last-child{
margin-right:0;
}
p{
clear: both;
}
Explanation:
you need to add clear:both to your paragraph <p></p> elements.
in ul{...} we set the margin & padding to 0
in li{...} we give some space between the li items by giving margin of 10px to the right.
in li:last-child{...} we removed the margin-right:10px & set it to 0 because it is the last item in the li list.
i am new to css, i have written code to display some text on hover. But it is not working
HTML:
<div id="onHover"> 5
<span>
<ul>
<li>Ankur</li>
<li>Dhanuka</li>
</ul>
</span>
</div>
CSS:
#onHover span:hover
{
bottom:130px;
left:105px;
padding:8px 8px 10px 8px;
display:block;
border:1px dashed #09f;
background-color:#FFF;
min-width:170px;
position:relative;
z-index:101;
}
#onHover span:hover ul {
font-weight:normal;
list-style:none;
margin:10px 0 0 0;
padding:0;
position:relative;
}
span {
display:none;
}
you can also see this fiddle http://jsfiddle.net/ankurdhanuka/ccFxu/
please help
Thanks in Advance
Your HTML should look like this (the span is useless, so I took it out, it also isn't allowed in HTML4. It is in HTML5 tho...):
<div id="onHover"> 5
<ul>
<li>Ankur</li>
<li>Dhanuka</li>
</ul>
</div>
Then you can add a :hover effect on the div, like this:
#onHover ul {
display: none;
}
#onHover:hover ul {
display:block;
}
As you can see, the :hover is on #onHover, but it triggers the ul within it.
DEMO
Nice Try, friend. Give :hover to #onHover as 5 is enclosed within #onHover.
Use position only if it is required.
check this.
http://jsfiddle.net/ccFxu/3/
You are setting display:none to the span through css.
The elements which are set as display:none will not be visible and are actually take no space in the view. Hence you cant able to hover on span which is actually not available because of display:none.
I'm having a problem getting a pseudo class working with my code. The code in question is a horizontal ordered list that's being placed at the top of a slider. The list is stretched out to fill the full horizontal width of the slider. I put a left-border on each of the list elements by assigning a border to the links contained within the list elements (so that the border didn't make the list too wide).
But I wanted to remove the first link's left-border so that borders were only shown between each list element, and not on the first or last list element.
The problem arises though when I add a first-child pseudo class to the link. The pseudo class seems to assign the class to all of the links.
Here's what I have:
CSS
ol.bjqs-markers{
display:inline-block;
list-style:none;
margin:0;
padding:0;
z-index:9999;
width:100%;
position:absolute;
top:0px;
}
ol.bjqs-markers li{
display:inline;
float:left;
height:30px;
width:20%;
background:rgba(0,0,0,0.7);
float:left;
margin:0 0px;
}
ol.bjqs-markers li a{
display:block;
font-size:22px;
color:#FFF;
text-align:center;
text-decoration:none;
height:100%;
display:block;
overflow:hidden;
border-left:1px solid #F00;
}
ol.bjqs-markers li a:first-child{
border-left:none;
}
And HTML:
<ol class="bjqs-markers">
<li class="active-marker">Example</li>
<li class="">Example</li>
<li class="">Example</li>
<li class="">Example</li>
<li class="">Example</li>
</ol>
Can someone point me in the direction of why that a:first-child applies a border of "none" to all the tags?
Thanks guys!
:first-child works just like expected, but every A in your example is a first-child. It is the first child of its parent LI.
What you're looking for is this:
ol.bjqs-markers li:first-child a {}
It is because you apply this pseudo class to first link in li element. Use
ol.bjqs-markers a:first-child {
border-left:none;
}
Or
ol.bjqs-markers li:first-child a {
border-left:none;
}
maybe you want to do
ol.bjqs-markers li:first-child a{
It it because you are applying the border to the first <a> tag in each <li> tag. Try this instead:
ol.bjqs-markers li:first-child a { }