如何将最后一个div放到父div的右上角? (css) [英] how to place last div into right top corner of parent div? (css)

查看:871
本文介绍了如何将最后一个div放到父div的右上角? (css)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用某种方式使用CSS将 block1 中的右上角放置 block2 >?

Can I somehow use CSS to place the block2 in top right corner of block1?


  • block2 必须是 block1 的(非常)最后一个内部HTML代码,或者可以放在 block1 。我不能使它成为 block1 中的第一个元素。

  • block1 < p> ,图片,文字,这是我无法控制的知道什么和多少。

  • 我需要 block2 流动。

  • block2 must be the (very) last inside HTML code of block1 or it could be placed after block1. I can't make it the first element in block1.
  • Within block1 there could be <p>, images, text and it is beyond my control to know what and how many.
  • Also I need the block2 to flow.

.block1 {
    color: red;
    width: 100px;
    border: 1px solid green;
}

.block2 {
    color: blue;
    width: 70px;
    border: 2px solid black;
    position: relative;
}

<div class='block1'>
    <p>text</p>
    <p>text2</p>
    <div class='block2'>block2</div>
</div>

推荐答案

.block1 {
    color: red;
    width: 100px;
    border: 1px solid green;
    position: relative;
}

.block2 {
    color: blue;
    width: 70px;
    border: 2px solid black;
    position: absolute;
    top: 0px;
    right: 0px;
}

应该这样做。假设你不需要它流动。

Should do it. Assuming you don't need it to flow.

这篇关于如何将最后一个div放到父div的右上角? (css)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆