0

最近在一个网站上工作,并想对其进行调整,以便在图片后面加上右侧的文字给出简要说明。

 <script type="text/javascript">
    function gotofirst()
    {
    alert('This link will be replaced with the appropiate link');
    window.open('http://google.com');
    }
</script>

<tr>
    <td>
        <img src="images/poster2.jpg" onClick="gotosecond()">
    </td>
    <p id="forum">Join us on our forums, chat with staff members and much more!</p>

</tr>

CSS:

#forum
{
font-size: 13px;
}

然后让 CSS 文件右对齐。问题是图像被推下并且文本没有挤在提供的框中,而是在我想要它向右时在图像上方右对齐。

jsFiddle 链接:http: //jsfiddle.net/HCVVp/

谢谢

4

2 回答 2

0

我建议您尽可能不要使用元素。我认为你可以这样做:

HTML

<div id="content">
    <div class="left">
        <img src="images/poster2.jpg" onClick="gotosecond()">
    </div>
    <div class="right">
        <p id="forum">Join us on our forums, chat with staff members and much more!</p>
    </div>
</div>

CSS:

#content{
    position: relative;
    width: 500px;
    margin:0 auto;
}
.left{float:left;}
.right{float:right}

另一种解决方案是删除 div 并将.leftand.right类仅应用于<img>and<p>元素。

于 2013-04-14T10:51:46.730 回答
0
<tr>
    <td>
        <img src="images/poster2.jpg" onClick="gotosecond()" style="float:left;display:block">
        <p id="forum" style="float:right">Join us on our forums, chat with staff members and much more!</p>
    </td>
</tr>

如果它仍然不起作用,请尝试包装在 div 中

<tr>
        <td>
           <div>
            <img src="images/poster2.jpg" onClick="gotosecond()" style="float:left;display:block">
            <p id="forum" style="float:right">Join us on our forums, chat with staff members and much more!</p>
            </div>
        </td>
    </tr>
于 2013-04-14T10:42:28.627 回答