簡體   English   中英

如何將div放置在圖片的右側?

[英]how to position div in the right side of the image?

我在頁面中央有圖像。

我想在<div class='contain'>內部顯示文本塊,該文本塊float left到圖像上。 圖片與<div class='contain'>之間的距離為10px

我不想移動圖像,我想圖像將停留在中間,而在右側,我放了<div class='contain'>

我添加屬性clear:both; 圖像或div,我認為我不知道如何使用它。

jsfiddle演示

我怎樣才能做到這一點? 謝謝

我的代碼:

<h1><a id="toptitle" href="http://www.centerwow.com">portfolio</a></h1>
<div id="container">

    <div id="all_pages">

        <div class="page">
            <h1>Home Page</h1>
            <img src="images/yellow_flowers.jpg" width="300px" height="300px">
            <div class='contain'>this is the home page bla bla bla</div>
        </div> <!-- page1 -->
        <div class="page">
            <h1>About Us Page</h1>
            <img src="images/Pink_Flowers.jpg" width="300" height="300px">

        </div> <!-- page2 --> 
        <div class="page">
            <h1>Contact Us Page</h1>
            <img src="images/green_flowers.jpg" width="300" height="300px">

        </div> <!-- page2 --> 

    </div> <!-- #all_pages -->

</div> <!-- #container -->

<div id="menu">
<ul>
    <li id="1" class="link CC3366 active">Home</li>
    <li id="2" class="link 33FF66">About</li>
    <li id="3" class="link FFFF33">Contact Us</li>
</ul>
</div> <!-- #menu -->
<div id="footer"><a class="link" href="http://www.centerwow.com">mysite</a></div>
​
body {
    background: #CC3366 url(images/temp.png) center 130px no-repeat ;
    overflow:hidden;
    margin:0;
    padding:0;
    }
#container { 
    width: 1000px;
    overflow: hidden;
    position: relative;
    height: 450px;
    margin: 0 auto;
 }

#all_pages {
    position: absolute;
    left: 0;
    top: 0;
    width: 3000px;
    }
.page {
    width: 1000px;
    height: 400px;
    float: left;
    text-align: center;
    margin-top: 10px;
    }    
.page img {
    margin-top: 10px;
    }
#menu {
    background: #000;

    }
#menu ul { 
    list-style: none;
    width: 457px;
    height: 35px;
    margin:auto;
    }
#menu ul li {
    float: left;
    color: #FFFF33;
    width: 150px;
    line-height: 35px;
    text-align: center;
    cursor: pointer;
    }
.active {
    color: #fff !important;
    }
#footer a{
    font-size: 25px;
    font-weight: bold;

    }
#footer{
    line-height: 100px;
    background: #CC3366;
    width:100%;
    height:1000px;
    text-align: center;
    display: block;
}
#toptitle {
    position: absolute;
    width:100px;
    top: 30px;
    left: 30px;
    color: #000;
    cursor: pointer;
    z-index:20;
}
a {
text-decoration: none;
}
#contain{
    clear:both;
    float:left;
    margin-left:10px;
    background: blue;
    width:300px;
    height:300px;
}
.clear{

}​


$(".link").click(function(){
        var page = $(this).attr("id");
        var color = $(this).attr("class");
        color = color.substr(5,6);
        $('#all_pages').animate({left: (page-1)*(-1000) }); 
        $("body").animate({backgroundColor: '#'+color});
        $("#menu ul li").removeClass('active');
        $(this).addClass('active'); 
    });

我用桌子做這份工作,看來工作還可以。

<center>
 <table>
  <tr>
   <td valign=top align=right width=50%>Here is the text</td>
   <td width=300px><img src='fun.jpg' width=300px height=300px></img></td>
   <td width=50%></td>
  </tr>
 </table>
</center>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM