使用CSS将图标右侧与文本(RTL站点)对齐

时间:2012-04-29 17:27:06

标签: css wordpress hebrew right-to-left background-position

我正在制作一个从右到左对齐的网站(希伯来语),并希望这些图标显示在文本的右侧。例如:底部的“联系我们”小部件中的http://kaptinlin.com/themes/striking/shortcodes/typography/,图标位于左侧,我希望它位于右侧。

以下是相关代码(HTML):

<section id="contact_info-3" class="widget widget_contact_info">
    <h3 class="widgettitle">Contact Us</h3>

    <p><span class="icon_text icon_phone default">(+40) 111 222 333</span></p>

    <p class="contact_address">
        <span>city,&nbsp;state</span>
        <span class="contact_zip">1111</span>
    </p>
    </div>
</section>

CSS:

.icon_text {
    padding:               0 22px 0 0;
    background-image:      url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons.png");
    background-repeat:     no-repeat;
    background-attachment: scroll;
    background-color:      transparent;
}

#footer .icon_text.default {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/footer_icons.png");
}

.icon_globe {
    background-position: -390px 0px;
}

.icon_home {
    background-position: -360px -30px;
}

.icon_email {
    background-position: -330px -60px;
}

.icon_user {
    background-position: -300px -90px;
}

.icon_multiuser {
    background-position: -270px -120px;
}

.icon_id {
    background-position: -240px -150px;
}

.icon_addressbook {
    background-position: -210px -180px;
}

.icon_phone {
    background-position: -180px -210px;
}

.icon_link {
    background-position: -150px -240px;
}

.icon_chain {
    background-position: -120px -270px;
}

.icon_calendar {
    background-position: -90px -300px;
}

.icon_tag {
    background-position: -60px -330px;
}

.icon_download {
    background-position: -30px -360px;
}

.icon_cellphone {
    background-position: 1px -390px;
}

.icon_text.default {
    background-image: url("http://kaptinlin.com/themes/striking/wpcontent/themes/striking/images/icons_black.png");
}

.icon_text.black {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_black.png");
}

.icon_text.gray {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_gray.png");
}

.icon_text.red {
    background-image: url("../images/icons_red.png");
}

.icon_text.orange {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_orange.png");
}

.icon_text.magenta {
    background-image: url(http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_magenta.png);
}

.icon_text.yellow {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_yellow.png");
}

.icon_text.blue {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_blue.png");
}

.icon_text.pink {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_pink.png");
}

.icon_text.green {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_green.png");
}

.icon_text.rosy {
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons_rosy.png");
}

感谢。

2 个答案:

答案 0 :(得分:1)

您的图标为background-image,因此您需要调整paddingbackground-positiontext-align属性,将其从左侧移动到右侧。< / p>

您需要进行一些调整。首先,您需要确保填充设置在右侧而不是左侧。然后,您需要调整background-position以将图标放在右侧:

.icon_text {
    padding: 0 22px 0 0; /* changed from 0 0 0 22px on live site*/
    background-image: url("http://kaptinlin.com/themes/striking/wp-content/themes/striking/images/icons.png");
    background-repeat: no-repeat;
    background-attachment: scroll;
    background-color: transparent;
}

.contact_info_wrap .icon_text, .contact_info_wrap .contact_address {
    padding-right: 26px; /* changed from padding-left on live site */
}

.icon_phone { /* obviously you would change each of the icons as necessary */
    background-position: -72px -210px; /* changed from -180px -210px */
}

然而,这样做会导致您的图标在右侧不相互对齐。因此,您需要通过调整p标记来对齐文本:

.contact_info_wrap p {
    margin-bottom: 5px;
    text-align: right; /* add this */
}

我猜你也希望你的标题对齐:

#footer h3.widgettitle {
    color: #FFFFFF;
    font-size: 24px;
    text-align: right; /* add this */
}

答案 1 :(得分:0)

如果您在rtl问题上需要任何进一步的帮助,请访问Striking支持论坛,我们将为您提供帮助。 RTL通常很简单。我们可以为您提供将所有正文移动到rtl的代码,并协助您不确定元素移动的任何特定元素。