2012-07-13 35 views
2

我目前有一個表格「解決方案」來格式化AddThis Div按鈕。 你可以看到這個在:http://www.siding4u.com/save-on-siding.php使用AddThis的CSS定位

在頁面它的頂部正確地顯示: AddThis buttons formatted to the right of an image and offset at the top of the page

下面是該代碼(變通):我有

<table align="center" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td width="60%" align="right"><img title="Help us. Help you." src="http://www.siding4u.com/media/shareaholic/img_help-us-help-you_right_yellow-text.png" alt="TEXT: Sharing is caring! Help us. Help you." width="360" height="23" /></td> 
    <td width="40%" align="left"><!-- AddThis Button BEGIN --> 
<div class="addthis_toolbox addthis_default_style"> 
<a class="addthis_button_preferred_1"></a> 
<a class="addthis_button_preferred_2"></a> 
<a class="addthis_button_preferred_3"></a> 
<a class="addthis_button_preferred_4"></a> 
<a class="addthis_button_compact"></a> 
<a class="addthis_counter addthis_bubble_style"></a> 
</div> 
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=siding4u"></script> 
<!-- AddThis Button END --></td> 
    </tr> 
</table> 

/想要將我所有的表格佈局轉換爲CSS,但我似乎無法獲得AddThis按鈕的配合。不管怎麼樣,他們總是看起來像「左邊的爭鬥」或者BREAK。

我猜這是一個簡單的解決方法,但我是那些CSS「塊頭」,似乎無法鞭打CSS的形狀之一。

請幫助...

回答

3

在CSS對準圖像是根據自己的頁面,而不是他們的理由上的位置(與addthis_button_preferred_1...n類的元素也許應該控制此)在一個表,你證明它左/中/正確的等等,而用CSS你的目標是以它的子元素將在中間的方式對齊。

HTML:

<div id='wrapper'> <!-- parent div containing the help-us-help-you image and the buttons--> 
    <div id="help_us"><!-- float:left because we want the image div and the button dive to be besides eachother --> 
     <img title="Help us. Help you." src="http://www.siding4u.com/media/shareaholic/img_help-us-help-you_right_yellow-text.png" alt="TEXT: Sharing is caring! Help us. Help you." width="360" height="23"/> 
    </div> 
    <div id='buttons'><!-- this div should also be floated left and have padding, to align the buttons correctly --> 

     <!-- each of the link elements should get some padding --> 
     <a class="addthis_button_preferred_1 button_preferred"></a> 
     <a class="addthis_button_preferred_2 button_preferred"></a> 
     <a class="addthis_button_preferred_3 button_preferred"></a> 
     <a class="addthis_button_preferred_4 button_preferred"></a> 
     <a class="addthis_button_compact button_preferred"></a> 
     <a class="addthis_counter addthis_bubble_style button_preferred"></a> 
    </div> 
</div> 

整個例子是在線on this fiddle,而且會與對準幫助,是一個純CSS的解決方案,沒有表出現在所有!

p.s.作爲一個方面說明,我建議您使用jsfiddle來解決CSS/HTML/javascript問題,它的確幫助我們更好地瞭解問題,並使更改更快。

EDIT 對於第二個問題:

<div align="center" style="margin-bottom:0; margin-top:5px;"> 
<div id='wrapper'> 
... 
​</div> 
... 
</div> 

對於該元件的高度由於某種原因是48像素,這產生兩個元件之間的間隙。因此,應用高度它,改變:

style="margin-bottom:0; margin-top:5px;"

TO:

style="margin-bottom:0; margin-top:5px;height:23px;"

+0

真棒。謝謝! 謝謝你的jsfiddle建議......我將使用它。如果努力幫助別人,我會在這裏繼續提供一個完整的解決方案,希望可以幫助那些可能會遇到這種問題的人。 我有一個問題。我創建了一個演示頁面:[鏈接](http://www.siding4u.com/_DEMO_header_2012-07-13.php) 問題:無論我做什麼,我似乎都無法擺脫之間的巨大空間包裝div和其他內容。 Ref。圖片:[鏈接](https://plus.google.com/photos/105387763531004182740/albums/5765087861976293505?authkey=COXI9K6ov53ItAE) – Rob 2012-07-14 18:07:10

+0

@Rob你好,搶劫,你可以請過去的CSS和HTML的頁面?我猜這是一個間距問題(沿着下面的div線設置爲從頂部向下50px) – 2012-07-14 23:44:21

+0

@ Lyuben - 我不確定在哪裏提供...這個評論區只允許600個字符。鏈接顯示整個文檔的代碼和一切。這裏又是:http://www.siding4u.com/_DEMO_header_2012-07-13.php – Rob 2012-07-15 05:51:46