简体   繁体   English

将span元素对齐div的左侧

[英]Align span element to left of div

Is it possible to align the span "Header" in this fiddle : http://jsfiddle.net/25LjE/37/ to right of text as shown : 是否可以将这个小提琴中的“Header”对齐: http//jsfiddle.net/25LjE/37/到文本右侧,如图所示:

在此输入图像描述

I'm creating the header using jquery. 我正在使用jquery创建标头。

Here is the fiddle code : 这是小提琴代码:

<script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/6352993.js"></script>
<noscript><a href="http://polldaddy.com/poll/6352993/">This is very long test question to test how polldaddy handles questions that exceed that normal length............ yes a very long question indeed..............</a></noscript>

.pds-pd-link {
display: none !important;
}
.pds-box {
    width: 220px !important;
}
.pds-input-label{
    width: auto! important;
}
.PDS_Poll{
    margin-bottom:15px;
}
$(document).ready(function() {

    $('.pds-question-inner').prepend('<center><span style="color:red;font-weight:bold;font-size: 10pt"><u>Header</u></span></center>');
});

When I try proposed solutions in IE8, the text is slightly higher than rest of text : 当我在IE8中尝试提出的解决方案时,文本略高于其他文本:

在此输入图像描述

Can this be fixed ? 这可以修复吗?

It is not really clear to me what you are trying to achive, but adding this CSS seems to get this done: 我真的不清楚你想要实现什么,但是添加这个CSS似乎可以做到这一点:

center span{
    position:relative;
    top:30px;
    left:-70px;
}

You can do that by wrapping your two elements both in a div which float left, then you can append instead of prepend the header. 你可以通过将两个元素都包装在一个向左浮动的div中来实现,然后你可以追加而不是在前面加上标题。

<div class="floatLeft">Your two elements</div>

<style>
.floatLeft {
    float: left;
    display: inline-block;
}
</style>

You may want to set a width and padding/margin on the elements as well so they come out as desired. 您可能还想在元素上设置宽度和填充/边距,以便它们根据需要出现。 If you want the header way to the right you can float it right instead of left. 如果你想把标题放在右边,你可以向右漂浮而不是左边。 If you do that stick with the prepend because some versions of IE screw up floats if the right floating elements are not first in the series. 如果你这样做坚持前置,因为如果正确的浮动元素不是系列中的第一个,某些版本的IE搞砸浮动。

You just have to add float:left in 你只需要添加float:left in

<span style="color:red;font-weight:bold;font-size: 10pt;float:left"><u>Header</u></span>

Check this: 检查一下:

JSFiddle 的jsfiddle

看看这个代码在小提琴我编辑它http://jsfiddle.net/25LjE/46/

I think this is what you want? 我想这就是你想要的?

$('.pds-question-inner').prepend('<center><span style="color:red;font-weight:bold;font-size: 10pt; text-align: right; display: block;"><u>Header</u></span></center>');

http://jsfiddle.net/84fjB/ http://jsfiddle.net/84fjB/

If not it should be, looks better :P 如果不是,那就更好看了:P

You can add float: left to the span (and clean up your HTML). 您可以将float: left添加到span(并清理HTML)。

You can check this: http://jsfiddle.net/ooflorent/zvbzT/ 你可以查看: http//jsfiddle.net/ooflorent/zvbzT/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM