2013-09-25 60 views
-1

我試圖讓一個標籤垂直排列與div。我認爲一張圖片描述了我想要做的事情;它呈現的方式是它的外觀。藍色的MS Paint-style更正是我想要的。我在下面包含了HTML和CSS,並刪除了儘可能多的無關代碼,以便解決問題。獲取標籤排列頂部的div

如何獲得該標籤以轉到類型選項的頂部?

謝謝!

Screenshot

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Title</title> 
     <style type="text/css"> 
     /* <![CDATA[ */ 

/* from reset.css */ 

/* http://meyerweb.com/eric/tools/css/reset/ 
    v2.0 | 20110126 
    License: none (public domain) 
*/ 

html, body, div, span, applet, object, iframe, 
h1, h2, h3, h4, h5, h6, p, blockquote, pre, 
a, abbr, acronym, address, big, cite, code, 
del, dfn, em, img, ins, kbd, q, s, samp, 
small, strike, strong, sub, sup, tt, var, 
b, u, i, center, 
dl, dt, dd, ol, ul, li, 
fieldset, form, label, legend, 
table, caption, tbody, tfoot, thead, tr, th, td, 
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary, 
time, mark, audio, video { 
    margin: 0; 
    padding: 0; 
    border: 0; 
    font-size: 100%; 
    font: inherit; 
    vertical-align: baseline; 
} 
/* HTML5 display-role reset for older browsers */ 
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section { 
    display: block; 
} 
body { 
    line-height: 1; 
} 
ol, ul { 
    list-style: none; 
} 
blockquote, q { 
    quotes: none; 
} 
blockquote:before, blockquote:after, 
q:before, q:after { 
    content: ''; 
    content: none; 
} 
table { 
    border-collapse: collapse; 
    border-spacing: 0; 
} 


/* from Application.css */ 

html { 
     min-height: 100%;   
     background-color: White; 
     color: Black; 
    } 

    body { 
      margin: 0; 
      margin-left: auto; 
      margin-right: auto; 
      color: #383838; 
      font-family: arial, helvetica, verdana, sans-serif; 
      font-size: 0.8em; 
      background-color: transparent; 
     } 

     input, textarea, select { 
       font-family: inherit; 
       font-size: inherit 
      } 

     div#EverythingDiv { 
       width: 960px; 
       margin-left: auto; 
       margin-right: auto; 
       background: #FFF; 
      }  

      div.MainContent { 
        margin: 0px auto 0px auto; 
        padding: 0; 
        min-height: 425px; 

        text-align: left; 
        clear: both; 
       } 

/* from MyPage.css */ 

div.MainContent div.BasicInformationField { 

    } 

    div.MainContent div.BasicInformationField label { 
      display: inline-block; 
      width: 155px; 
      vertical-align: baseline; 
     } 

    div.MainContent div.BasicInformationField label.RadioLabel { 
      display: block; 
      font-weight: normal; 
      width: auto; 
     } 

    div.MainContent div.BasicInformationField textarea { 
      vertical-align: baseline; 
      font-family: inherit; 
      font-size: inherit; 
     } 

    div.MainContent div.BasicInformationField textarea#AddressTextArea { 
      height: 3.3em; 
      width: 250px; 
     } 

    div.MainContent div.BasicInformationField div#TypeOptionsDiv { 
      height: 3.3em; 
      width: 250px; 
      vertical-align: baseline; 
      font-family: inherit; 
      font-size: inherit; 
      display: inline-block; 
     } 

    div.MainContent div.BasicInformationField input.WebSite { 
      width: 250px; 
     } 

     /* ]]> */ 
     </style> 
    </head> 
    <body> 
     <div id="EverythingDiv"> 
      <h1 id="PageTitleH1">Title</h1> 

      <div class="MainContent"> 
       <!-- view --> 


<form action="MyPage" method="post"> 
<div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li> 
</ul></div> 

<h2>Basic Information</h2> 
<div class="BasicInformationField"> 
    <label for="WebSiteTextBox">Web Site:</label> <input type="text" id="WebSiteTextBox" class="WebSite"/> 
</div> 
<div class="BasicInformationField"> 
    <label for="AddressTextArea">Address:</label> <textarea id="AddressTextArea"></textarea> 
</div> 
<div class="BasicInformationField"> 
    <label for="PhoneNumberTextBox">Phone Number:</label> <input type="text" id="PhoneNumberTextBox" class="WebSite"/> 
</div> 
<div class="BasicInformationField"> 
    <label>Type:</label> 
    <div id="TypeOptionsDiv"> 
     <label class="RadioLabel"><input type="radio" name="Type"/>Type 1 - Lorem ipsum dolor sit amet, consectetur adipiscing elit.</label> 
     <label class="RadioLabel"><input type="radio" name="Type"/>Type 2 - Curabitur non odio hendrerit, hendrerit ante quis, rhoncus neque. Nam ac nisi non lorem accumsan dictum. </label> 
     <label class="RadioLabel"><input type="radio" name="Type"/>Type 3 - Morbi volutpat at eros ut dictum. Nam non arcu ornare, sodales eros nec, semper ante. Nunc tempor augue a est eleifend suscipit. Nam vel ornare leo.</label> 
     <label class="RadioLabel"><input type="radio" name="Type"/>Type 4 - Nam vel ornare leo.</label> 
    </div> 
</div></form> 
       <!-- weiv --> 
       <div class="Clear"></div> 
      </div> 
     </div> 
    </body> 
</html> 
+0

這是不正常的,標籤地址是垂直對齊頂部,而標籤類型不是。 –

+1

使用一個有風格的無序列表,而不是DIVS作爲佈局包裝。請參閱:http://alistapart.com/article/prettyaccessibleforms –

+1

我認爲人們經常避免使用表格。我認爲你試圖實現的外觀已經建立在表格中。看看這個例子http://jsfiddle.net/CZyYH/ – jbaum012

回答

0

所以我結束了浮動撇下所有這樣做,有標籤明確雙方,並調整邊距,使基線相匹配。感謝對話和鏈接。

jsfiddle.net/6Zjqh/

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Title</title> 
     <style type="text/css"> 
     /* <![CDATA[ */ 

/* from reset.css */ 

/* http://meyerweb.com/eric/tools/css/reset/ 
    v2.0 | 20110126 
    License: none (public domain) 
*/ 

html, body, div, span, applet, object, iframe, 
h1, h2, h3, h4, h5, h6, p, blockquote, pre, 
a, abbr, acronym, address, big, cite, code, 
del, dfn, em, img, ins, kbd, q, s, samp, 
small, strike, strong, sub, sup, tt, var, 
b, u, i, center, 
dl, dt, dd, ol, ul, li, 
fieldset, form, label, legend, 
table, caption, tbody, tfoot, thead, tr, th, td, 
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary, 
time, mark, audio, video { 
    margin: 0; 
    padding: 0; 
    border: 0; 
    font-size: 100%; 
    font: inherit; 
    vertical-align: baseline; 
} 
/* HTML5 display-role reset for older browsers */ 
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section { 
    display: block; 
} 
body { 
    line-height: 1; 
} 
ol, ul { 
    list-style: none; 
} 
blockquote, q { 
    quotes: none; 
} 
blockquote:before, blockquote:after, 
q:before, q:after { 
    content: ''; 
    content: none; 
} 
table { 
    border-collapse: collapse; 
    border-spacing: 0; 
} 


/* from Application.css */ 

html { 
     min-height: 100%;   
     background-color: White; 
     color: Black; 
    } 

    body { 
      margin: 0; 
      margin-left: auto; 
      margin-right: auto; 
      color: #383838; 
      font-family: arial, helvetica, verdana, sans-serif; 
      font-size: 0.8em; 
      background-color: transparent; 
     } 

     input, textarea, select { 
       font-family: inherit; 
       font-size: inherit 
      } 

     div#EverythingDiv { 
       width: 960px; 
       margin-left: auto; 
       margin-right: auto; 
       background: #FFF; 
      }  

      div.MainContent { 
        margin: 0px auto 0px auto; 
        padding: 0; 
        min-height: 425px; 

        text-align: left; 
        clear: both; 
       } 

/* from MyPage.css */ 

fieldset > label { 
    float: left; 
    display: block; 
    width: 150px; 
    clear: both; 
    margin-top: 5px; 
} 

fieldset > input[type=text] { 
    float: left; 
    margin-top: 1px; 
} 

fieldset > textarea { 
    float: left; 
} 

fieldset > div.Group { 
    float: left; 
    width: 300px; 
    padding-top: 5px; 
} 

fieldset > div.Group input[type=radio] { 
    /*margin: 0; 
    vertical-align: top; 
    padding: 0;*/ 
    margin-top: -3px; 
    vertical-align: middle; 
} 

fieldset > div.Group > label { 
    display: block; 
    margin-bottom: 3px; 
    line-height: 1.2em; 
} 
     /* ]]> */ 
     </style> 
    </head> 
    <body> 
     <div id="EverythingDiv"> 
      <h1 id="PageTitleH1">Title</h1> 

      <div class="MainContent"> 
       <!-- view --> 
       <form action="MyPage" method="post"> 
        <div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li> 
        </ul></div> 

        <fieldset> 
         <legend>Basic Information</legend> 
         <label for="WebSiteTextBox">Web Site:</label> 
         <input type="text" id="WebSiteTextBox" value="http://www.google.com/" /> 
         <label for="AddressTextArea">Address:</label> 
         <textarea id="AddressTextArea" style="float: left; width: 350px; height: 4.4em;">Sample Address</textarea> 
         <label>Type</label> 
         <div class="Group"> 
          <label class="RadioLabel"><input type="radio" name="Type"/>Type 1 - Lorem ipsum dolor sit amet, consectetur adipiscing elit.</label> 
          <label class="RadioLabel"><input type="radio" name="Type"/>Type 2 - Curabitur non odio hendrerit, hendrerit ante quis, rhoncus neque. Nam ac nisi non lorem accumsan dictum. </label> 
          <label class="RadioLabel"><input type="radio" name="Type"/>Type 3 - Morbi volutpat at eros ut dictum. Nam non arcu ornare, sodales eros nec, semper ante. Nunc tempor augue a est eleifend suscipit. Nam vel ornare leo.</label> 
          <label class="RadioLabel"><input type="radio" name="Type"/>Type 4 - Nam vel ornare leo.</label> 
         </div> 
        </fieldset> 
       </form> 
       <!-- weiv --> 

       <div class="Clear"></div> 
      </div> 
     </div> 
    </body> 
</html> 
1

你可以改變這一點:

div.MainContent div.BasicInformationField label { 
     vertical-align: baseline; 
    } 

要這樣:

div.MainContent div.BasicInformationField label { 
     vertical-align: top; 
    }