I am worthless in CSS. My boss doesn't want me to use </br>:(
I have a repeater and a div which is relative, like he said I should have. Then I placed spans which are absolute and with top and left.
It works fine when there is just one row in the table, but when I have more rows, the rows are placed over eachother.

The code:

<asp:DataList ID="rptItems" runat="server" Width ="100%" RepeatDirection="Vertical">
<div style="font-size: x-small; color: Gray; position: relative; width: 100%">			
<div style="color:#ce7300">	
<span style="position:absolute;top:20px;left:0px">Företagsnamn  </span>
<span style="position: absolute; top: 20px; left: 110px">|</span>
<span style="position: absolute; top:20px;left:120px">Kontakt
<span style="position: absolute; top: 20px; left: 210px">|</span> 
<span style="position: absolute; top: 20px; left:220px">
<span style="position: absolute; top: 20px; left: 340px">|</span>
<span style="position: absolute; top: 20px; left:350px">
<span style="position: absolute; top: 20px; left: 450px">|</span> 
<span style="position: absolute; top: 20px; left:460px">
<span style="position: absolute; top: 20px; left: 550px">|</span>
<span style="position: absolute; top: 20px; left:560px">
<span style="position: absolute; top: 20px; left: 650px">|</span>
<span style="position: absolute; top: 20px; left:660px">
<span style="position: absolute; top: 20px; left: 750px">|</span>
<span style="position: absolute; top: 20px; left:760px">
<span style="position:absolute;top:30px;left:0px">
<span style="position: absolute; top: 30px; left: 120px">
<span style="position: absolute; top: 30px; left: 220px">
<span style="position: absolute; top: 30px; left: 350px">
<span style="position: absolute; top: 30px; left: 460px">
<span style="position: absolute; top: 30px; left: 560px">
<span style="position: absolute; top: 30px; left: 660px">
<span style="position: absolute; top: 30px; left: 760px">
<%#Container.DataItem("fldStad")%> </span>

Please help me, as I said I'm worthless in CSS and need throroughly explanation


8 Years
Discussion Span
Last Post by diafol

Yuk! You want to use a separate CSS file not all those horrible style attributes. Keep the logic (html) and presentation (styling) separate.

This looks like data to me - sorry I don't 'do' ASP. If so, data should be stored in a html table. You've probably heard loads of stuff about not using tables in html anymore as EVERYTHING has to be in pure CSS. That's rubbish. Data should always be placed in a table. To me, this is the only acceptable semantic format. Imagine an user using a mobile or a PC with custom CSS styles / no styles / screen reader. Your multiple span might look very odd. Tables keep data format integrity very well.

Your code looks like you're suffering from spanitis.

As for not using </br> - I should hope not - it doesn't exist!

Below is the xhtml I would use:

<table id="mytable">

I don't know how you'd use an ASP repeater with this, but anyway.

CSS can be used to target specific table cells within the xhtml without any spans, divs, classes or ids, leaving a lovely clean logic.

/* this is SPECIFIC to the table where the id = 'mytable' - it makes all cells border-free */

   width: 900px;

table#mytable, table#mytable th, table.data td{
/* change font colour to white and background to blue in table headings only. Changes font to a bigger size and to a specific font. Note if user has 'Calibri' on the device - show this, otherwise headings will show in Arial, and so on. */
table#mytable th{
  color: white;
  background-color: blue;
  font-size: 20px;
  font-family: Calibri, Arial, Verdana, sans-serif;
/* reverse the colour scheme for the data cells in the table */
table#mytable td{
  color: blue;
  background-color: white;
/* this gives the third cell onwards in all rows red font and yellow background*/ 
table#mytable tbody tr td + td + td{
  color: red;
  background-color: yellow;

Styling tables is so much fun (oops - sound like a geek). I find absolute positioning an absolute pain and avoid it if possible. Loads of divs and spans make maintenance VERY difficult.

You can look at advanced selectors like: tr td:nth-child(3), children, siblings etc. Really flexible.

Edited by diafol: n/a


Oh no! Made a mistake. On line 7 of the css above - change to this:

table#mytable, table#mytable th, table#mytable td{
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.