2011-08-01 5 views
0
나는이 같은 테이블을 생성 할

를 사용하지만, DIV 대신 테이블사업부

<style type="text/css"> 
    body{ font-family:"Segoe UI", "Tahoma" } 
    td { 
     padding:0px 5px 10px 5px; 
    } 
    .username { 
     white-space:nowrap; 
     vertical-align:top; 
     text-align:right; 
     width:auto; 
     color:DodgerBlue; 
    } 
    </style> 

    <table width="500px" > 
     <tr> 
      <td class="username">copperfield</td> 
      <td>How to create table by using div </td> 
      <td style="vertical-align:top">time </td> 
     </tr> 
     <tr> 
      <td class="username">copperfield</td> 
      <td> 
       How to create table by using div How to create table by sing div How to create table by to create table by using div <img src="images/thinking.gif"> </br> 
      </td> 
      <td style="vertical-align:top"> 8:00 </td> 
     </tr> 
     <tr> 
      <td class="username"> </td> 
      <td> 
       How to create table by using div</br> 
      </td> 
      <td style="vertical-align:top"> 8:00 </td> 
     </tr> 
     <tr> 
      <td class="username"> </td> 
      <td> 
       How to create table by using div</br> 
      </td> 
      <td style="vertical-align:top"> 8:00 </td> 
     </tr> 
     <tr> 
      <td class="username">michael</td> <td><img src="images/thinking.gif"> Gi ku </td> 
      <td style="vertical-align:top"> 8:00 </td> 
     </tr> 
    </table> 

나는 다음과 같은 코드를 시도하지만

<style type="text/css"> 
    body{ 
     font-family:Segoe UI; 
    } 
    .all{ 

    float:left; 
    display:block; 
    } 

    .chat{ 
    width:700px; 
    float:left; 
    display:table-cell; 
    } 

    .us{ 
     color:blue; 
     text-align:right; 
     float:left; 
     margin-right:10px; 

    } 
    .ct{ 
    white-space:normal; 
     float:left; 
     margin-right:10px; 
    } 
    .t{ 
     float:left; 
     width:auto 
    } 
    </style> 
    <div class="all"> 

    <div class="chat"> 
     <div class="us"> userna3 46346346me </div> 
     <div class="ct"> content </div > 
     <div class="t"> time </div> 
    </div> 
    <div class="chat"> 
     <div class="us"> copperfield </div> 
     <div class="ct"> How to create table by using div How to create table by sing div How to create table by to create table by using div</div> 
     <div class="t"> 8:00 </div> 
    </div> 
    <div class="chat"> 
     <div class="us"> copperfield </div> 
     <div class="ct"> How to create table by using div Ho </div> 
     <div class="t"> 8:00 </div> 
    </div> 
</div> 
+11

인기있는 믿음 표와 달리 사용하면 악조건이 아닙니다. 테이블 물건 .... – Josh

+0

css float 속성 (http://www.w3schools.com/cssref/pr_class_float.asp)을 검색해야합니다. –

+0

'

'을 사용하지 않는 이유는 무엇입니까? 이 코드는 작성, 이해 및 유지 관리가 더 쉬울 것입니다. – VIK

답변

2

이 성공하지를 사용하여 테이블을 만드는 방법 당신이 원하는 것 같습니다 : http://jsfiddle.net/ttunW/. 핵심은 .chat를 들어, .all, display:table-row;에 대한 display:table;를 사용하던 모든 div들에 float:left 속성을 제거하기 및 .chatdiv s의 display:table-cell;을 할당.

+0

호환성 모드에서 IE가 제대로 작동하지 않습니다. – Gabe

+1

아니요. IE에서 작동해야하는 경우,이 상황에서 의미 상으로 정확하기 때문에 '

'을 사용해야합니다. –

+0

제대로 작동하지 않습니다. 페이지에 고정 너비가 700px이고 첫 번째 열 이름 및 열 시간에 자동 크기가 있어야하고 줄 바꿈을하지 않아야합니다. – KevinBui

1

플로트에 떠있는 뭔가를 가질 수 없습니다. 그냥 못생긴 브라우저에서 작동하지 않습니다 기침 IE 기침.

그래서 다음과 같이 당신의 CSS에서 당신의 모든 클래스를 변경 :

.all div {float:left;} 

그런 다음 수업에서 다른 모든 수레를 빼앗아. 우리, ct 및 t는 각 채팅 div의 내부에 너비를 설정합니다. 또한 div의 div 태그를 p 태그로 변경하십시오.

+0

열 이름의 너비가 텍스트 사용자 이름과 일치하기 때문에 수정 크기로 너비를 설정해야한다고 생각하지 않습니다. – KevinBui