Hi I am new to HTML and CSS so I was wondering what the difference was between
putting all of my paddings, display, list-style-types under
ul#tabs. For example if I put display:inline; inside ul#tabs, my text wont appear in the same line. I am confused as too what the difference is between putting values under #tabs li, and #tabs li a and #tabs. My guess is that any property under #tabs, will happen to anything inside including a's, p's or whatever else I included within the ID of tag and #tabs li a, does things only to <a>'s within the tab id. If this is the case what does ul#tabs li do, and why cant i put display: inline , in my ul#tabs{} portion of the code. Sorry for the long questions. Thank you.
body{
}
#Title{
position: absolute;
top:5px;
right:600px;
}
ul#tabs {
list-style-type: none; margin: 30px 0 0 0; padding: 0.2em 0.5em 0.3em 0; /* takes off bullets (list-style..) */
}
ul#tabs li {
display: inline; /* puts them on same line */
}
ul#tabs li a {
color: #42454a; text-decoration: none; /* take off underline */
padding: 0.6em 0.7em 0.8em 0.9em; /* padding within a makes space between a */
}
Drew is correct, you are looking at specificity in this example and what it applies to. Think of CSS as boxes and, in most cases, what gets changed in the outer box affects the inner boxes, too. :) If you want to affect the middle box with padding, you place your padding there, but keep in mind the inner most box will be affected as well. In that sense, you can apply values very broadly:
body{
}
#Title{
position: absolute;
top:5px;
right:600px;
}
ul#tabs {
list-style-type: none; margin: 30px 0 0 0; padding: 0.2em 0.5em 0.3em 0; /* takes off bullets (list-style..) */
color: #42454a; text-decoration: none;
padding: 0.6em 0.7em 0.8em 0.9em;
}
ul#tabs li {
display: inline; /* puts them on same line */
}
This is one way you could affect all text, and lists under #tabs, but make sure individual lists are inline.
Adding things like:
ul#tabs li {
Just makes it even more specific, as you are targeting individual list items under a list parent with the ID "tabs."
A better way to write this is:
#tabs li
It would look for an element with the ID "tabs" and see if there is list items under it. Now, if you want to be really technical, you could use a class for list items as well, such as "mylistitems," then write:
#tabs.mylistitems
This would search for an element (in this case ul) with ID "tabs," then begin looking for another element under it with the class "mylistitems." Technically, you can also do:
ul li {
}
This would target all list items. Sorry it was a long response, hopefully this gives you some unique ways to write CSS selectors.
Related
Fallout
Yes; you should go to the links Howzieky provided. When in doubt, w3schools is right. Codeacademy is great, but teaches some bad practices.
However, that doesn't help you right now. So, I'll try to nudge you along.
First: look up how to link an external style sheet. Keeping your code clean is good when you're just learning.
Now, assuming you have a list of links that will be displayed as a list, you need to remember that code semantics is important for accessibility and seo. So, if it's a list of any kind, it goes inside a list element.
So, start with:
<ol>
<li>link text</li>
<li>link text</li>
</ol>
ol is better accessibility than ul, but both work.
Now, first style your list so you get rid (visually) of the bullits/numbers, and have a block that will play nice:
ol {
display: block;
width: 100%;
height: auto;
overflow: hidden;
/* This sets you up with a block that will scale down nicely if your text is too long. */
margin: 0;
padding: 0;
/* Because it's a headache to find where whitespace is coming from later, I always advise to null the padding and margin and use a container if you need gutters later. This also nixes the space reserved for the bullits/numbers. */
list-style-type: none;
/* Get rid of the bullits/numbers for realsies */
}
Now, to style the list items:
ol li {
display: block;
width: 100%;
height: auto;
padding: 0;
margin: 0;
list-style-type: none; /* For IE 9 and lower. */
text-align: center; /* Here's your centered links */
}
Just one more step:
ol li a,
ol li a:link {
color: red;
}
ol li a:hover,
ol li a:focus,
ol li a:active {
/* do something here to change the links visually when hovered/clicked/tabbed to, be nice to your users. */
}
HTH. Have fun & good luck.
Good afternoon,
I am trying to create a menu bar with a sub-nav under some parents, however the childs are not aligning.
I have change the child bicolour to red to highlight the concern.
There is a chance that by entering the sub-nav text may cure the concern.
I have listed below the CSS and HTML.
Kind regards
Gary.
Danceblast
Your problem is this:
#dropnav ul li {
margin-left: 20px;
}
It's being applied to the subnav's child li's aswell, you can target the subnav directly and set the margin to 0
#subnav li {
margin-left:0px !important;
}
OR
#dropnav #subnav li {
margin-left:0px;
}
if you dont want to use !important.
#dropnav ul li {
margin-left: 20px;
}
You want to remove the margin as well as you want to check for your text-alignment.
At the moment your elements use
text-align: center;
on all its parents and childs. You probably want that to be:
text-align: left;
Hope that helps.
I have spent a while trying to find out how to make text links sit horizontally on a navigation bar, but to no success.I am EXTREMELY new to coding so this is probably extremely easy to do, i am using html and CSS, i have tried just putting them on the same line. Also using:
#nav li a {
color: black;
display: inline;
list-style-type: none;
}
#nav li a {
color: black;
position: relative;
}
i have tried to find the answer on the site but i cant see one, so i thought i might as well just ask people. Thank you for reading.
You are targeting the wrong element, it should be
#nav li {
display: inline;
}
You were selecting a element, you need to target the li, a is an inline element by default, li renders one below the other, so to make them inline, we target li
I would suggest you to use
#nav li {
display: inline-block;
margin-left: -4px; /* If that white space matters to you */
}
As you will get same effect, but with some additional bonus like margins padding to space up your element. Alternatively, you can also use float: left; but you will need to clear your floats so stick with inline-block
I have this website I'm working on:
https://dl.dropbox.com/u/10264776/Web%20sustn.sk/odbory/fotograficky_dizajn.html
For some reason right of this box (Ctrl+F 1992) presents a weird behavior where the content of the li is pushed by few pixels, it's not is the styles, they're same for all of them, however I noticed that it's the only ul that doesn't have it's content push from one line to another like the others in the table do.
Any ideas how to fix this? All help will be greatly appreciated.
Just try to comment on style.css line 119
.list {
border-color: #BBBBBB;
border-style: solid;
border-width: 1px 0;
margin-bottom: -1px;
/*width: 560px;*/
}
By doing this your problem will solve only for that element but your width will remove from entire elements where .list is applied so you need to tweak on that particular table where 1992 is mention. It is table behavior it expands the table cells as per the text and layout or breathing space. So you need to put the width on that particular table cells.
Use like this
.list ul li
{
list-style: none;
padding:0;
margin:0;
padding-left: 1em;
text-indent: -.7em;
}
li:before
{
content: "• ";
color: red; /* or whatever color you prefer */
}
for a detailed explanation look here
I just wonder where is this space between the end of the image and the end of the li's are coming from:
http://bluesys.ch/lussy/
its just a simple UL > li > img
spacing from hell http://bluesys.ch/lussy/spacingfromhell.jpg
code:
div#slider {
border: 5px solid #fff;
}
div#slider ul li {
border-bottom: 1px solid pink;
}
div#slider ul li img {
border-bottom: 1px solid green;
margin: 0;
}
note that all margins and paddings are set to 0 by my reset.css
can someone help me out? I colored the borders that you can see the spacing i speak of. I use firefox.
Try setting the line-height to 0 for those images and/or LI elements. Currently you have that set to 1.4 in the body, and the img will inherit that. A brief test of setting line-height: 0 in Firebug made the images stack flush.
If you want to get rid of the gaps, you could try:
li {
margin-bottom: 0;
padding-bottom: 0;
}
You may want a special class for those li elements tho, so that the CSS that gets applied doesn't do it to ALL your li elements on the site.
But, what's wrong w/ the gap? I kind of like it. Helps frame each image...
Images are inline elements just like text and by default they are positioned on the font base line leaving space for the ascender. There are different ways to stop that:
line-height: 0 (as suggested by Robusto)
display: block
vertical-align: bottom