CSS - Css: Class, Id, Div, And Span Confusion
I am having trouble understanding what exactly the CLASS, ID, DIV, and SPAN elements and attributes do.
What are there purposes? How do the relate to each other? When should one be used and not another? In laymens terms please. Thanks Similar TutorialsWhy doesn't the class applied to the span tag do anything? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <style> body { font-family: Georgia, Times, serif; font-size: 12pt; } #main p { padding:0 10px; } .newssubhead { font-size: 124%; color:red; } </style> </head> <body> <div id="header"> <p> <span class="newssubhead">Test test test test test test test test test test test test </span> <br> Something else... </p> </div> </body> </html> Hi, I have this style for font size. I then use span class to use it, but it only works in IE and not FF. Any ideas why? Have i got something wrong with it? PHP Code: .11px { font-family: verdana, arial, tahoma; font-size: 11px; } hi all I've got a styled ul+li element, and I've put a new color class in a span tag, for a link li a, li a:active, etc { color: #00FF00; } li a:hover { color: #00AA00; } spanclass a, span a:active, etc { color: #00FF00; } spanclass a:hover, etc { color: #00AA00; } <li>hello, <span class="spanclass"><a href="#">this is a link</a></span></li> Except it's completely ignoring the span class colors... Anyone know why? Is there a better way to declare custom fonts than doig like such style sheet .bluesmall {font-family: verdana} .bluesmall {color: blue} .bluesmall {font-size: 10px} /style sheet content <span class="bluesmall">example text</span> Hi I'm struggeling with the following: I have some span elements inside a td. If I apply padding to a span then the padding is flowing outside the td (above and below the borders of the td). Why does that happen and is there a way to make the td to autogrow to fit all the span's inside? Se example code below Code: <table border="0" cellpadding="0" cellspacing="0" align="center" style="width:300px; margin-top:50px;"> <tr> <td style="background-color:gray; text-align:center; border:1px solid black;"> <span style="margin-right:20px;">First</span> <span style="margin-right:20px;">1</span> <span style="margin-right:20px;">2</span> <span style="margin-right:20px; background-color:orange; padding:10px;">3</span> <span style="margin-right:20px;">4</span> <span style="margin-right:20px;">5</span> <span style="">Last</span> </td> </tr> </table> ******* UPDATE ******* I found this link today: http://css-discuss.incutio.com/?page=FormattingContexts which says (among other things): ************************* Only one thing impacts the vertical space between inline elements: the line height. Normally, the line height is based upon the line height for the text in that line, or the height/padding/border/margin of any replaced items. The element on a line with the largest line height or replaced height is the one to define the vertical space that line takes up. Height, padding, border or margins on text do not impact the line height or the container height. Instead, borders, padding and margins overlap from line to line. If you want to give an inline text element some padding and border, make sure you give it some extra line height, too, or else it will overlap with whatever else is above or below it. ************************* So does that rule mean that I have no way to make my TD autogrow in relation to the padding applied to the SPAN in the example above? Is there any working workarounds for this...? Hi. See code below. Why does the outer SPAN in TABLE not grow with the image height. If the text is longer so it is forced below image then it looks as it should. Please also read some comments in the code. Code: <html><body><center><br><br> Why does image not force the outermost span to be at least as high as image?<br> If the text are long enough and gets below the bottom border of image it look good though.<br><br> NOTE: I need to put Image and text either within separate span or in same span as the examples below.<br> In my real application I'm using an <a href=" ...> around the outer span in examples below.<br> <br><br> <table border=1 cellpadding=0 cellspacing=0 width=200px><tr><td> <span style="display:block; background-color:#ffa827; padding-top:10px; padding-left:10px; padding-right:10px;"> <span style="display:block; float:left"> <img src="landscape.jpg" height="40px" width="40px" alt="" border="0"> </span> <span style="display: block; color: white;"> Text here. </span> </span> </td></tr></table> <br><br> <table border=1 cellpadding=0 cellspacing=0 width=200px><tr><td> <span style="display:block; background-color:#ffa827; padding-top:10px; padding-left:10px; padding-right:10px; color: white;"> <img src="landscape.jpg" height="40px" width="40px" alt="" border="0" style="float:left"> Text here. </span> </td></tr></table> </center></body></html> Hey, I have the following in a CSS document: Code: /* Link Colors */ a:link { color: #000000; } a:visited { color: #000000; } a:hover { color: #888888; } a:active { color: #000000; } /* User Class colors */ .classadmin { color: #FF0000; font-weight: bold; } .classmod { color: #0066FF; font-weight: bold; } .classmember { color: #00CC00; font-weight: bold; } In the Active Users section of my site, I link to the user's profile, and I would also like the color of the link to be the color of the user's class. My HTML code is: Code: <a class="classmember" href="user.php?id=1">$username</a> But, I also have a Color Key: Code: Color Key: <font class="classmember">Member</font>, <font class="classmod">Moderator</font>, <font class="classadmin">Administrator</font>. I thought I could do something like: a.classmember:link { color: #00CC00; font-weight: bold; } But that messes up the Color Key. So, I don't know how I can have the .classmember, .classmod, and .classadmin override the a:link {} pseudoclasses. Thanks for any suggestions! Hi all, first post to the forum after signing up over two years ago... I work mostly on the server side, so I'm hoping that someone can advise me on the trouble I'm having with CSS. http://www.commafruit.co.uk/play/css/imageplace.html In the link above, I have two images, both with the following css: Code: <img src='planet.png' style='width:5; height:5; position:relative; left:20px; top:10px;' /> <img src='planet.png' style='width:5; height:5; position:relative; left:20px; top:20px;' /> Please could someone explain why they are not in line vertically? They both have left:20px, so surely they should be one on top of the other? The fact that this is not the case in Firefox or IE makes me think I'm really missing the point, and I've been going around and around trying to figure out what. Thanks for any replies. Also, I'd prefer not to use absolute positioning as I'd like to keep the images relative to the div. B. Hi There - Am having some confusion with CSS inheritance. I'm working with a Drupal where I don't have control over the html output and everything seems to have extra layers of divs generated by the cms. I have a large container div with id=forum. Nested inside a table inside that div are more divs. Inside of that I have links inside a div that has class=name. Like this: Code: <div id="forum"> <ul> </ul> <table> <thead> </thead> <tbody> <tr class="odd"> <td class="container" colspan="4"> <div style="margin-left: 0px;"> <div class="name"> </div> <div class="description">Containers that will look OK as and when we decide to use forum Containers.</div> </div> </td> </tr> <tr class="even"> <td class="forum"> <div style="margin-left: 30px;"> <div class="name"> <a href="/forums/samplecontainer/sample-forum-for-sample-container">Sample forum for sample container</a> </div> How do I address these so that only the links within the forum are affected by this rule? The following rule is affecting all of the links in the whole site, no matter what the id or class. I thought I understood how to address these, but it's clear to me now that I don't. I'd appreciate any help I can get with this. Just to be clear, I'm trying to address the text that says 'Sample forum for sample container' in the very last div in the code above. Here's what I was trying to use: Code: #forum .name a:link, a:visited, a:hover { color:#F79239; } I've also tried permutations; #forum.name a:link etc. I don't want to be 'lucking' into something that sorta works. I really want to nail this. I'm trying to align one div to the bottom inside of another, and a third div to just beneath that one. Since the third div will appear on mouseover, it needs to lie on top of other content that will already be there. I've tried various combinations of positioning, setting margins, etc., but I can't figure out a solution that will work in all the browsers. This is just the bare bones so that you can maybe see what I'm trying to achieve here.... Confused? Yes, me too; Here's the html: Code: <html> <head> <link href="test2.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="widebar"> <div id="tabs"> <div class="menu1">I want these</div> <div class="menu2">to align to the</div> <div class="menu3">very bottom </div> <div class="menu4">of this div </div> <div id="tabs2">Align this to the bottom left corner of the Tabs 1 section so that it shows up just below the dark blue area</div> </div> </div> Here is some text that will sit below the these divs and I don't want the mouseover to "push" this text out of the way. The div that appears on mouseover should sit "on top" of this text with no interference. </body> </html> And here's the css, thus far: Code: /* css */ #widebar { width:100%; height: 200px; background: #ffccff; } #tabs { float:right; display:block; #position: absolute; #bottom:0; height: 200px; background:#334ddd; width:50%; } #tabs2 { clear:both; #position: relative; #bottom: 0; background: #567dfe; } .menu1, .menu2, .menu3, .menu4 { float:left; width: 100px; background: #ccc; } Hi there, thanks for reading my post. I am looking to build a website using ASP, with databases. After receiving some advice from some (more experienced) friends, they recommended learning CSS. They said something along the lines of "its better than using frames because Search Engines will index your site better and you will have more control over your pages - changing one style sheet can change your whole site easily". I thought it sounded like what I need as I am hoping to produce a fairly professional looking site, however I am still a little confused. I am unsure if this is a "webdesign" problem, so forgive me if I have posted in the wrong place, but I am interested to know how navigation menus are made. What I mean is, I dont understand how to make a menu on the left of the page control the right panel of a page without using frames . I have spent some time reading the (70) examples on www.w3schools.com but I cannot seem to find the answer - so now I am worried that it cannot be done!! If anyone could perhaps paste some quick code for me to look at/reverse engineer or, equally useful, perhaps give links to a few tutorials/web resources on this I would be very grateful. Another question if I may (?!) - when designing navigation menus (top or left or whatever), is it best to use text that highlights to make the links to navigate the site, or to make the links into pictures (i.e. have a whole menu created from small buttons aligned underneath each other). I hope my question is clear. Thanks to anyone who can help, Regards, Porky Hi everyone! I'm taking my first CSS class and am running into some problems formatting a table. Specifically getting the rows to line up center along with the table headings. Well, except for the first one that should be left aligned. This is my validated CSS code: Code: .cell-alpha { font-size: 25px; background-image: url('headercellbackground.png'); color: #FF9933; width: 85%; } .cell-bravo { font-size: 25px; background-image: url('headercellbackground.png'); color: #FF9933; text-align: center; } tbody tr.odd { background-color:lightyellow; color: red; } tbody tr.even { background-color:red; color: white; } tbody tr.total { background-color:#6699FF; color: yellow; } table { table-layout: fixed; width: 700px; } How would I get each column centered since the data is entered in table row sections? Also, how to get all of the headings to line up baffle me. This is how it SHOULD look : URL And this is how its rendering with my CSS: table Hi I want to create a text rollover menu on the very left hand side only (standard display). I want it in a table so I can have content on right hand side. I don't know whether to have each link in its own cell or 1 big cell and have a list of items. I decided to have a list of items but the items display on right side of the table cell and align left doesn't work. Code: a { display: block; width:100px; text-decoration: none; } #list1 { /* all list items */ background: lightblue; border-width:1px; /* thin is not the same in different browsers */ border-color:black; border-style:solid; /* required */ list-style-type:none; } I just want the list to display on left hand side and have a box around each item which it isn't. I am spending way too long fiddling about with this . Everytime I think I am getting the hang of CSS -- for simple pesonal homepages, etc -- they still always seem to get the worse on me. I am trying to generate a moderately simple page with title, prelude, menu (as per a table) with menu, content and comment box, followed by a quick sumary, etc. I seem to be having troubles getting the three -- menu, content & comment boxes -- to size correctly. I have a surounding box (by a div) for them, but they do not seem to entirely follow/use it as their parent... If I set them to top:0, it is the top of the window frame, but otherwise they seem to position within their more local parent div. Ultimately, I am striving to get into this CSS way of 'life', but it is very difficult as I am working mainly alone. I do have books but perhaps I am not seeing the info entirely correct... Perhaps some of you chaps/gurus can help me here. I have recently gathered that "html" is or should be used in the CSS file too...? Looking for help. My current (broken) home page can be accessed via: "dgringo.homeip.net/~dgringo/index.shtml" Here is the code and the CSS file: <head> <title>...</title> <script language="JavaScript" type="text/javascript" src="main.js"></script> <link rel="stylesheet" href="entry.css" type="text/css" /> </head> <body> <h1>Me (iMac's) Web-space</h1> <div id="prelude"> <!--#include virtual="includes/header.incl" --> </div> <table id="main"> <tr> <td id="menu"> <!--#include virtual="includes/menu.incl" --> </td> <td id="content"> <!--#include virtual="includes/body.incl" --> </td> <td id="topics"> <p> <!--#include virtual="includes/topic1.incl" --> </p> <p> <!--#include virtual="includes/topic2.incl" --> </p> </td> </tr> </table> <div id="footer"> <!--#include virtual="includes/footer.incl" --> </div> <div class="adendeum"> Last updated <!--#echo var="LAST_MODIFIED" --><br /> </div> </body> </html> ------------- The CSS file now follows: a:link {text-decoration:none;color: black;} a:visited {text-decoration:none;color: black;} a {color: black;} a:hover {text-decoration:underline;color: silver;} body { color: #000000; background: #669999; } h1 { text-align: center; } #prelude { width: 80%; background-color: #CCCC99; margin-left: auto; margin-right: auto; padding-top: 3px; padding-bottom: 3px; padding-left: 10px; padding-right: 10px; text-align: center; } #main { display: block; width: 100%; border: silver dotted; height: 16em; } #main td { border: dashed; } #menu { position: absolute; width: 20%; left: 2%; } #content { position: absolute; left: 23%; width: 50%; } #topics { position: absolute; left: 74%; width: 20%; } p:first-line { color: gray; background-color: green; } #footer { text-align: center; width: 80%; background-color: #CCCC99; margin-left: auto; margin-right: auto; padding-top: 3px; padding-left: 10px; padding-bottom: 3px; padding-right: 10px; } .adendeum { font-weight: lighter; color: gray; text-align: center; } hey, I got a table, every <td> in the table got the css class .regular. (<td class='regular'>). When the user moves their mouse over a row, that row should change color. This works with the following code: <tr onmouseover='this.className=\"hoverRow\"'> However, this only works if the td's in that row have no class set yet. And since all td's in my table have a class set allready, i cant use this. How can i overwrite the class of the td's by the class for the whole row? thanks in advance Hi, okay I am working on a website for a friend, and it is peak-performance.biz I want the background image to fill up the page and be unscrollable. I made it work and look very good in chrome but it only takes up half the page in firefox. I was wondering if anyone have any ideas how to fix this. Thanks for your advice in advance. I have used html{ background-color:#000000; background-image:url(images/background.jpg); background-repeat:no-repeat; background-size:1300px; height:1000px; background-attachment:fixed; } and html{ background-color:#000000; background-image:url(images/background.jpg); background-repeat:no-repeat; background-size:100%; background-attachment:fixed; } Using the following example: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test</title> <style type="text/css"> a { display: block; } a.one.on, a:hover.one, a:hover.one.on { color: red; } a.two.on, a:hover.two, a:hover.two.on { color: orange; } a.three.on, a:hover.three, a:hover.three.on { color: green; } </style> </head> <body> <a href="#" class="one">one</a> <a href="#" class="two">two</a> <a href="#" class="three">three</a> <p> </p> <a href="#" class="one on">one</a> <a href="#" class="two on">two</a> <a href="#" class="three on">three</a> </body> </html> Notice how, in IE6 (works fine in FF), when the secondary style named 'on' is added, all 3 links in the 2nd set display the properties of the style: Code: a.three.on, a:hover.three, a:hover.three.on { color: green; } (since it is last in the list) rather than the style specified by their respective numbers (i.e. 'one', 'two' or 'three'). Is there a way to overcome this in IE. I've read several forums and know that the technique I'm trying to achieve is possible, however I can't seem to get it to work. Basically I'm trying to shift the background positions of both the list item I'm hovering over and the next list item. I'm sure its just a syntax error and not a logic error, anyways the code is below - any help would be greatly appreciated! Code: HTML Code <div class="menu"> <ul> <li><a href="#" class="search"></a></li> <li><a href="#" class="battery"></a></li> <li><a href="#" class="cart"></a></li> <li><a href="#" class="contact"></a></li> </ul> </div> CSS .search, .contact, .cart, .battery { width:100px; height:30px; margin-left:-1px; display:block; } .search { background-image:url(Images/search.png); } .contact { background-image:url(Images/contact.png); } .cart { background-image:url(Images/cart.png); } .battery { background-image:url(Images/battery.png); } ul li a.search:hover { background-position:0px 60px; } ul li a.search:hover ul li a[class=battery] { background-position:0px 60px; } Hi, Code: <tr><td colspan="2" height="5"></td></tr> <tr><td width="30%" align="right">City</td><td>This is supposed to be some content</td></tr> How do I imitate structure of the table above. In the example below the text between <span> if too long ends up on new line below <label> How do I make sure that it stay on right side? Code: <div><label>City</label><span>This is supposed to be some content when too long appears below span not below label</span></div> Thank you. hi, i have a chunk of dynamic text coming in. it can have html links in it. so something like: 'blah blah blah <a href="site">link text</a> blah blah' im trying to stylize the dynamic text with CSS. i can get the font size and everything to work but i can't get the link text to behave like i want it to. here's what i have: PHP Code: //the css class .articleDesc { font-family: verdana, arial, geneva, sans serif; font-size: 12px; font-weight: none; text-decoration: none; color: #000000; } //trying to make all links red, doesn't work a.articleDesc { color: #FF0000; } //php print '<span class="articleDesc">' . $dynText . '</span>'; the links just come out default, ie. blue and purple... anyone know what's wrong here? |