开发者

How to position two images in opposite corners of one div

开发者 https://www.devze.com 2023-03-06 19:21 出处:网络
I am not a CSS guy as you can see and I need little help on how to make this div with two images, l开发者_如何学Cike the drawing below

I am not a CSS guy as you can see and I need little help on how to make this div with two images, l开发者_如何学Cike the drawing below

How to position two images in opposite corners of one div


Thomas is right but there's a even better solution:

<style type="text/css">

    #content {width: 500px;}

    .align-left { float: left; }
    .align-right { float: right; }

</style>

<div id="content">

    <img class="align-left" src="link to your image" alt="description of your image" width="100" height="100" />
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    <img class="align-right" src="link to your image" alt="description of your image" width="100" height="100" />
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

</div><!-- end content -->

class are more usefull than ID in this case.


<style type="text/css">
#container {
   width:760px;
   border:1px solid #999;
   margin:20px auto 0;
   overflow:hidden;
 }
#top-left {
   float:left;
 }
#bottom-right {
   float:right;
   clear:both;
 }
</style>

</head>
<body>

<div id="container">
  <img id="top-left" src="" alt="">
  <img id="bottom-right" src="" alt="">
</div>


You need to float the images right and left.

Here is the CSS:

img {width:100px; height:100px; border:1px solid; margin:1em;}

.image1 {float:left;}
.image2 {float:right;}

floats need explicit widths set

Here is a jsfiddle with it all:

EDIT: updated the jsfiddle to include a surrounding div

http://jsfiddle.net/RQp5Z/1/


Since you're not a css guy, just created this example to help you understand what's going on with the div's http://jsfiddle.net/hT9xV/9/


Two images can be displayed opposite to each other using the code shown below. This solution assumes the need for both images to be on the same line.

.section-container {
    width: 100%;

    .align-left {
      float: left;
    }

    .align-right {
      float: right;
    }
}

div class="section-container">
    <img class="align-left" src="assets/images/foo.svg" width="165px" alt="Foo">
    <img class="align-right" src="assets/images/bar.jpg" width="90px" alt="Bar">
</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消