首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AddThis进行CSS定位

使用AddThis进行CSS定位
EN

Stack Overflow用户
提问于 2012-07-14 07:29:02
回答 1查看 2.9K关注 0票数 2

我目前有一个表格“解决方案”来格式化AddThis分区按钮。您可以在以下位置查看:http://www.siding4u.com/save-on-siding.php

在页面的顶部,它正确显示:

下面是这个问题的代码(解决方法):

代码语言:javascript
复制
<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按钮配合使用。它们似乎总是“左对齐”或以某种方式破坏-无论我如何尝试。

我猜这是一个简单的解决方案,但我是那些CSS“块头”之一,似乎不能鞭打CSS的形状。

请帮帮我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-14 08:15:37

在css中,对齐图像是基于它们在页面上的位置,而不是它们的对齐方式(类为addthis_button_preferred_1...n的元素可能会控制这一点),你可以在表格中左对齐/居中/右对齐,而在CSS中,你的目标是使它的子元素在中间对齐。

HTML:

代码语言:javascript
复制
<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解决方案,根本没有表格!

附注:顺便说一句,我建议你使用jsfiddle来解决CSS/HTML/javascript的问题,它确实能帮助我们更好地发现问题,并更快地做出改变。

第二期的编辑

代码语言:javascript
复制
<div align="center" style="margin-bottom:0; margin-top:5px;"> 
<div id='wrapper'> 
...
​</div>
...
</div>

对于这个元素,由于某种原因,高度是48px,这在两个元素之间产生了一个间隙。所以对它应用一个高度,改变:

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

TO:

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11479608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档