2013-11-20 55 views
0

我在我的CSS有一個小問題,我試圖創建2列布局,我看到內容之間的隨機差距。我無法正確解釋它,請檢查我在jsfiddle中創建的示例。你將能夠理解。右側我想創建2列。通過CSS對齊我的Html內容

這裏是的jsfiddle鏈接 http://jsfiddle.net/QZJJL/3/

HTML

<div class="mainsection"> 
    <div class="visitMainSection"> 
     <div class="VISIT headingsection">Open Site Visits</div> 
     <div class="scrolldiv visit_repeatSection1" style=""> 
     <div class="header sectionheader TODAY">TODAY</div> 
     <div class="content TODAY_1"> 
      <div class="leftColumn"> 
       <div class="ellipsis"> 
        <h3 class="label1"><span class="facid">4002</span><span class="facName"> ABC Comapny Ltd.(Ark Bal Cave)</span></h3> 
       </div> 
       <p class="facLocalName" style="display: none;"></p> 
       <p class="facAddress">Building 5, 6th floor Darjaling Road, Shan District CAV</p> 
       <p class="label4"><span class="city">Shenzhen</span><span class="state"> Gurgao</span><span class="country"> India</span></p> 
       <p class="label5"><span class="longitude" style="display: none;"></span><span class="latitude" style="display: none;"></span></p> 
      </div> 
      <div class="rightColumn"> 
       <div class="rightGroup"> 
        <div class="groupproto"> 
        <h3><span class="protocolname show"> Test Protocol 10</span>      <span class="date_class show"> NOV 18 - NOV 30, 2013</span></h3> 
        </div> 
        <p class="onsiteLead bold" style="display:none;">ONSITE LEAD: <span></span></p> 
        <div class="multirow"> 
        <div> 
         <h5 class="audit_com" style="display:none;">Golder</h5> 
         <h5 class="auditor">J1</h5> 
         <p  class="assignments">Antidsdsdsdsd<br>Labor &amp; Human Rights</p> 
         <h5 class="auditor">Y1 (Lead)</h5> 
         <p class="assignments">dsdsdsdsdsdsdsd</p> 
        </div> 
        <div> 
         <h5 class="audit_com" style="display:none;">Verite</h5> 
         <h5 class="auditor">S1</h5> 
         <p class="assignments">Wages &amp; Benefits<br>Labor &amp; Human Rights</p> 
         <h5 class="auditor">C1 (Lead)</h5> 
         <p class="assignments">antidiscrimas<br>Labor &amp; Human Rights</p> 
         <h5 class="auditor">D1</h5> 
         <p class="assignments">antidiscrimas<br>Labor &amp; Human Rights<br>Wages &amp; Benefits</p> 
        </div> 
        <div> 
         <h5 class="audit_com" style="display:none;">PWC</h5> 
         <h5 class="auditor">L1 (Lead)</h5> 
         <p class="assignments">antidiscrimas<br>Labor &amp; Human Rights</p> 
         <h5 class="auditor">M1</h5> 
         <p class="assignments">Labor &amp; Human Rights<br>Wages &amp; Benefits</p> 
         <h5 class="auditor">M2</h5> 
         <p class="assignments">Antidiscrimination<br>Labor &amp; Human Rights<br>Wages &amp; Benefits</p> 
         <h5 class="auditor">V1</h5> 
         <p class="assignments">Antidiscrimination<br>Labor &amp; Human Rights<br>Wages &amp; Benefits</p> 
        </div> 
        <div> 
         <h5 class="audit_com" style="display:none;">Supplier Responsibility</h5> 
         <h5 class="auditor">G1 (Lead)</h5> 
         <p class="assignments">antidiscrimas<br>Labor &amp; Human Rights<br>Wages &amp; Benefits</p> 
         <h5 class="auditor">R1</h5> 
         <p class="assignments">antidiscrimas<br>Labor &amp; Human Rights</p> 
         <h5 class="auditor">R2</h5> 
         <p class="assignments">Labor &amp; Human Rights<br>Wages &amp; Benefits</p> 
        </div> 
        </div> 
        <div class="footer"> 
        <input type="button" class="setupButton" value="Visit Setup" style="display:none;">      
        <p class="downloadBriefcase"> </p> 
        </div> 
       </div> 
       <div class="linkButton">      <input type="button" class="lplinkbutton" value="&gt;" onclick="top.openPageURL('Pushinfolet?id=101652&amp;proc=146194&amp;flag=1&amp;emd=2&amp;accessflag=2&amp;edit_flag=D&amp;wrapper=no')" style="height: 558px;">     </div> 
      </div> 
     </div> 
     </div> 
    </div> 
</div> 

CSS

html{ 
    min-height: 100%; 
} 
.headingsection { 
    font-weight: 600; 
    font-size: 23px; 
    padding-bottom: 5; 
    padding-top: 0; 
    margin-top: 0; 
} 
body { 
    min-height: 100%; 
    font-family: "Avenir Next", "Avenir", "Helvetica Neue", "Lucida Grande", Arial, sans-serif !important; 
} 
.mycustcls{ 
    background-color: white; 
    padding-left: 5; 
} 
.sectionheader{ 
    background-color: #C2C2C2; 
    color: white; 
    padding: 5px; 
    font-weight: 500; 
    font-size: 16px; 
} 
.sectionspacer{ 
    height:20px; 
} 
.sectionrows{ 
    background-color: rgba(240, 240, 240, 0.93); 
    padding: 10; 
    padding-right: 0; 
    overflow: hidden; 
} 
.colsheader{ 
    height: auto; 
    color: white; 
    font-weight: 500; 
    font-size: 14px; 
    float: left; 
    } 
.sectioncols{ 
    width: 300px; 
    height: auto; 
    float: left; 
    color: black; 
    font-weight: normal; 
    font-size: 13px; 
    } 
    .mainsection{ 
    padding:10px; 
    } 
.anotherspacer{ 
    background-color: rgba(231, 231, 231, 0.72); 
} 
.rowseparator{ 
    border: 2px solid #CFCFCF; 
} 
    .content { clear: both; font-size: 13px;} 
    .Separator {border-top: 2px solid #858585;} 
    .date_class { float:right; font-weight: normal; } 
    .rightGroup { float: left; width:80%;} 
    .anchor{cursor:pointer;font-weight:500;} 
    .linkbutton {} 

.lplinkbutton{ 
    float: right; 
    vertical-align: middle; 
    cursor:pointer; 
    border:0; 
    font-weight: 500; 
    font-size: 15; 
    margin: 0; 
    padding:0 10px; 
    background-color: rgba(173, 172, 172, 0.12); } 


.scrolldiv{ 
    overflow-x: auto; 
    background-color: #F0F0F0; 
    color: black; 
    border: 2px solid #858585; 
    width: 1237px; 
} 
.colfacility_id,.colfacility_name{ 
    font-weight:600; 
    text-decoration:underline; 
} 
.colfacility_id,.colfacility_local_name,.colfacility_address,.colcity,.collongitude{width:500px;padding-top:2px;} 
.colprotocol_name{ 
    font-weight:500; 
    margin-left: 50px; 
    width:500px; 
    } 
    .hidden{display:none;} 
    .colname{font-weight:600;} 
    .colfacility_address.colfacility_local_name,.colname{padding-top:5px; width: 235px;} 
    .offlineclass{width:170px;color:black;font-size: 13px;} 
    .downloadasmnt{ 
    width: 73px; 
    height: 29; 
    border: 1px solid rgb(49, 120, 153); 
    border-radius: 6; 
    background-color: rgba(173, 172, 172, 0.94); 
    color: white; 
    font-weight: 500; 
    } 
    .datefloat{ 
    color: #666; 
    font-size: 12px; 
    } 
    .datefloat,.offlineclass{ 
    font-weight:normal; 
    float:right; 
    } 
    /*div.tt_upcoming.sectionheader{ 
    background-color: rgba(240, 240, 240, 0.93); 
    color: black; 
    border: 2px solid rgba(0, 0, 0, 0.25); 
}*/ 
.sectionheader u.anchor{ 
    text-decoration:none; 
    font-size: 17; 
    margin-left: 6; 
} 
.protocoldate{ 
    padding: 0; 
    margin: 0; 
    border-bottom: 1px solid; 
} 
.tt_upcoming.sectionheader{ 
    background-color: rgba(240, 240, 240, 0.93) !important; 
    color: black !important; 
} 
.capMainSection .sectionheader{ display:none;} 
.leftColumn { float: left; width: 45%; padding: 15px 0 10px 20px;} 
.rightColumn { 
    padding: 0; 
    position: relative; /* add this to make linkbutton position relative to parent*/ 
    vertical-align: middle; 
    width: 50%; 
    float: right; 
} 
.rightColumn .rightGroup { padding-top: 10px; } 

.rightGroup .multirow div { float: left; width: 245px; } 


.content p { margin: 5px 0;} 

.groupproto { padding-top: 4px;} 
.groupproto .protocolname{ 
    float: left; 
    width: 313px; 
    overflow: hidden; 
    height: 16px; 
    white-space: nowrap; 
    text-overflow: ellipsis; 
    display: block; } 

.leftColumn .ellipsis { } 

.leftColumn h3.label1 { 
    overflow: hidden; 
    white-space: nowrap; 
    text-overflow: ellipsis; 
    margin-bottom: 7px;} 

.show{ display: block;} 

.groupproto { margin-bottom:5px; } 
.lasActivity ul { padding-left: 18px !important;} 



h3 { font-weight: 500; border-bottom: 1px solid #000; height: 16px; margin:5px 0 10px 0; text-transform: uppercase; font-size: 1.1em;} 
h3.label1 { text-decoration: underline; border: 0;} 
h5 { margin: 5px 0; font-weight: 600; font-size: 13px;} 
.content { overflow: hidden;} 
.downloadBriefcase { float: right;} 
h3.normalCase { text-transform: none; border: 0;} 
p.bold { font-weight: 600; font-size: 13px;} 
.setupButton { 
    cursor: pointer; 
    background: #727272; 
    border: 0; 
    padding: 8px 15px; 
    color: #FFF; 
    margin: 3px 0;} 

.onsiteLead span { font-weight: normal; } 

.UPCOMING { 
    background: none; 
    position: absolute; 
    color: #858585;} 
.UPCOMINGContent .leftColumn { padding-top: 30px;} 
.UPCOMINGContent .rightGroup { padding-top: 27px; } 
+0

ü可以給btwn的colums一些色差問題出在哪裏傳來 – Reshma

+0

@Reshma:你可以看到優思明SGM(鉛)和Leo GSM(主承銷商)之間的差距? –

+0

嘗試在CSS中使用更多有組織的樣式.... HTML5有很多預定義的div來滿足您的需求.... !! :) – NoobEditor

回答

0

您應該使用表而不是DIV爲您的數據佈局,因爲它的表格數據(這不適用於屬l頁面佈局)。問題不是你的兩列布局不起作用,而是你的佈局是一個多行,每行都有兩列。您可以用兩列布局重新組織布局。 一些佈局建議:

<table> 
    <tr> 
     <td> 
      <h3>A title in the first column</h3> 
      <p>some text</p> 
     </td> 
     <td> 
      <h3>A title in the 2nd column</h3> 
      <p>some text</p> 
     </td> 
    </tr> 
    <tr> 
    <!-- put the other lines here --> 
</table> 

使用此佈局,行將對齊。這是表格數據的正確之一。

<div><!-- the container --> 
    <ul style="float:left;"><!-- the left column container, using a class for csss is better --> 
     <li> 
      <h3>A title in the first column</h3> 
      <p>some text</p> 
     </li> 
     <!-- put the other lines for left column here --> 
    </ul> 
    <ul><!-- the right column container --> 
     <!-- same as for the left column --> 
    </ul> 
</div> 

使用此佈局,行將不會被分配。如果你認爲你的數據是一個無序列表,這是正確的。

+0

你絕對不需要爲此使用表或列表。 – Joe

+0

你不這樣做,但它對可讀性和語義來說要好得多。你可以用div做所有事情,尤其是一個不可讀的代碼。 – Pierre

+0

值得商榷的是,當數據包含的數據不適合列表或表格時,如何使表或列表更好地適用於語義?您不應該使用表格來控制頁面的顯示。內容_really_是一個列表嗎? – Joe

0

它看起來就像你在COL2將內容放在COL1,那麼接下來,然後在旁邊的col1等等,等等

如果內容的高度不匹配,這在撥弄他們不這樣做,你」重新獲得兩個內容塊不匹配的「隨機」空間。

最好的解決方法是首先填充第一列,然後填充第二列。這樣,內容高度不會成爲問題。

0

問題:

.leftColumn { float: left; width: 45%; padding: 15px 0 10px 20px;} 

width : 45%走的是看不見的空間,在較小的年齡%分配給它。

解決方案

.leftColumn { float: left; padding: 15px 0 10px 20px;border:1px solid #000}