Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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
Javascript 用divs制作Facebook风格的个人资料图片_Javascript_Html_Css - Fatal编程技术网

Javascript 用divs制作Facebook风格的个人资料图片

Javascript 用divs制作Facebook风格的个人资料图片,javascript,html,css,Javascript,Html,Css,就在昨天,我为我正在设计的新个人资料页面创建了一个计划。计划如下所示。基本上,我想知道如何让个人资料图片漂浮在封面照片和div#背景之上。我唯一知道的两种方法是:#profile_pic{z-index:1500;}或#profile_pic{position:absolute;}。如果其中任何一个能起作用,我如何使它们在两个div之间浮动。谢谢 个人资料页平面图: 可能是这样的: #profile_pic { height:250px; width:250px; pos

就在昨天,我为我正在设计的新个人资料页面创建了一个计划。计划如下所示。基本上,我想知道如何让个人资料图片漂浮在封面照片和div#背景之上。我唯一知道的两种方法是:
#profile_pic{z-index:1500;}
#profile_pic{position:absolute;}
。如果其中任何一个能起作用,我如何使它们在两个div之间浮动。谢谢

个人资料页平面图:


可能是这样的:

#profile_pic {
    height:250px;
    width:250px;
    position:absolute;
    top:350px;
    left:100px;
    z-index:10;
}

应该是这样的:

#profile_pic {
    height:250px;
    width:250px;
    position:absolute;
    top:350px;
    left:100px;
    z-index:10;
}
在两个div之间浮动没有“简单”或默认方法。也就是说,您只需要计算您的个人资料图片的高度,然后相应地调整它

因此,您可以使用绝对定位,结合您提到的
z-index
position:absolute
。。。或者您可以使用相对定位并将轮廓pic向下移动一半高度

 #profile_pic {
   position: absolute;
   height: 200px;  /* it looks like this is your height */
   width: 200px;   /* it looks like this is your height */
   top: 250px;     /* it looks like this is your distance from the top */
   left: 50px;     /* it looks like this is your distance from the left */
   z-index: 99; 
 }
或者使用相对定位(注意:您必须将所有其他div包装在使用默认(静态)定位以外的内容的外部容器中,例如:

 #div_container {
   position: absolute;
   top: 0px;
   left: 0px;
   margin: 0;
   padding: 0;
 }  

 #profile_pic {
   position: relative;
   height: 200px;  /* it looks like this is your height */
   width: 200px;   /* it looks like this is your height */
   top: -100px;    /* shift the profile pic up half it's height */
   left: 50px;     /* it looks like this is your distance from the left  */
   z-index: 99; 
 }

 /* Now, shift the information div up 200px (the height of #profile_pic), 
 *  in order to align to the bottom of the "cover photo" div 
 */
 #information_section {
   position: relative;
   top: -100px;    
 }
在两个div之间浮动没有“简单”或默认方法。也就是说,您只需计算您的个人资料pic的高度,然后相应地进行调整

因此,您可以使用绝对定位,结合您提到的
z-index
position:absolute
,或者您可以使用相对定位,将轮廓pic向下移动一半高度

 #profile_pic {
   position: absolute;
   height: 200px;  /* it looks like this is your height */
   width: 200px;   /* it looks like this is your height */
   top: 250px;     /* it looks like this is your distance from the top */
   left: 50px;     /* it looks like this is your distance from the left */
   z-index: 99; 
 }
或者使用相对定位(注意:您必须将所有其他div包装在使用默认(静态)定位以外的内容的外部容器中,例如:

 #div_container {
   position: absolute;
   top: 0px;
   left: 0px;
   margin: 0;
   padding: 0;
 }  

 #profile_pic {
   position: relative;
   height: 200px;  /* it looks like this is your height */
   width: 200px;   /* it looks like this is your height */
   top: -100px;    /* shift the profile pic up half it's height */
   left: 50px;     /* it looks like this is your distance from the left  */
   z-index: 99; 
 }

 /* Now, shift the information div up 200px (the height of #profile_pic), 
 *  in order to align to the bottom of the "cover photo" div 
 */
 #information_section {
   position: relative;
   top: -100px;    
 }
以下是您想要的: 全屏:

HTML:

以下是您想要的: 全屏:

HTML:


您可以将配置文件图片
img
放在封面照片div区域内。例如,如果您在封面照片div中添加
position:relative
,则可以使用
position:absolute;top:10px;left:10px;
将拇指
relative
定位到该
div
区域。我们将更多地帮助您修复损坏的代码,而不是我们按照您的规范编写代码。换句话说,展示您自己解决此问题的诚实尝试。谢谢你们两位和sparky,唉,我确实尝试过构建此代码,但它不起作用。我决定寻求帮助,并将从中获得的结果用于与我的代码进行比较,以便我现在知道如何在将来更正我的代码。您可以将配置文件图片
img
放在封面照片div区域内。如果您将
position:relative
添加到封面照片div,则可以使用
position:absolute;top:10px;left:10px>将拇指
relative
定位到该
div
例如,我们更多的是帮助您修复损坏的代码,而不是按照您的规范编写代码。换句话说,展示您自己解决此问题的诚实尝试。谢谢你们两位和sparky,唉,我确实尝试过构建此代码,但它没有起作用。与其尝试修复对我收到的一些人来说似乎有点可怜的代码,我更愿意尝试决定寻求帮助,并使用我从中收集的结果与我的代码进行比较,因此我现在知道如何在将来更正我的代码。感谢您在这里提供的帮助Mayank Tripathi,这不仅是我所需要的,而且示例刚刚结束,以显示实际结果。感谢您在这里提供的帮助Mayank Tripathi,不仅仅是w由于这正是我所需要的,所以这个例子只是在最后展示了实际的结果。感谢你给出的答案,你给出的这段代码可以在以后我的项目中使用,因为你对代码进行了详细介绍,感谢你的帮助,如果我能给出我会做的声誉。感谢你给出的答案,t你提供的代码可以在以后我的项目中使用,因为你详细介绍了代码,谢谢你的帮助,如果我能给出我的声誉,我会这么做。为@APAD1的评论干杯,简短,简明扼要,很好,这么小的代码可以做我想要的事情。为@APAD1的评论干杯,简短,简明扼要确切地说,这么小的代码能做我想要的事情真是太棒了。