Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使一个div在9个可能的位置中有两个图像_Html_Css - Fatal编程技术网

Html 如何使一个div在9个可能的位置中有两个图像

Html 如何使一个div在9个可能的位置中有两个图像,html,css,Html,Css,我绞尽脑汁,在网上读过的所有东西都试过了,但都想不出来 在HTML4和CSS 2.1(供SharePoint 2010使用)中介绍如何实现这一点 我有一个已知高度和宽度的div,还有两个未知高度和宽度的图像。我们可以假设图像比div小。我希望能够将两个图像定位在以下位置之一: 左上角 中上部 右上角 中间偏左 中间 中右翼 左下角 中下部 右下角 两个图像中的每一个都可以位于不同的位置 有什么想法/帮助吗 <div style="width: 500px; height: 500px"

我绞尽脑汁,在网上读过的所有东西都试过了,但都想不出来 在HTML4和CSS 2.1(供SharePoint 2010使用)中介绍如何实现这一点

我有一个已知高度和宽度的div,还有两个未知高度和宽度的图像。我们可以假设图像比div小。我希望能够将两个图像定位在以下位置之一:

  • 左上角
  • 中上部
  • 右上角
  • 中间偏左
  • 中间
  • 中右翼
  • 左下角
  • 中下部
  • 右下角
两个图像中的每一个都可以位于不同的位置

有什么想法/帮助吗

<div style="width: 500px; height: 500px">
    <img src="..." />
    <img src="..." />
</div>

我只需要创建6个类来描述所有位置,然后对每个图像应用2个类

。左{
左:0;
}
.中心{
左:0;
右:0;
左边距:自动;
右边距:自动;
}
.对{
右:0;
}
.顶{
排名:0;
}
.中{
排名:0;
底部:0;
页边顶部:自动;
页边距底部:自动;
}
.底部{
底部:0;
}

这太棒了!非常感谢你。它适用于img标签。无论如何,要使其适用于文本元素,例如,?只需确保您选择的任何元素都为其提供
内联块
显示属性,以便您可以设置其宽度。如果我不知道宽度怎么办?就像我不知道img的宽度或者我想定位的跨度一样。
.left {
    left: 0;
}
.center {
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
}
.right {
    right: 0;
}
.top {
    top: 0;
}
.middle {
    top: 0;
    bottom: 0;
    margin-top: auto;
    margin-bottom: auto;
}
.bottom {
    bottom: 0;
}

<img class="left middle" />