Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.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/7/sql-server/27.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 如何写在心上?_Html_Css_Geometry_Css Shapes - Fatal编程技术网

Html 如何写在心上?

Html 如何写在心上?,html,css,geometry,css-shapes,Html,Css,Geometry,Css Shapes,下面是:,我现在有了这个,它有这个HTML: <div id="heart"><span>M + G</span></div> 然而,字母仍然在心脏的后面,而我的目标是将它们放在心脏的中心,首先我认为我必须将它们放在心脏的前面,但是这失败了,你知道吗?z-index只对定位元素有效(位置:绝对,位置:相对,…)您的spanelemet没有position属性 #heart:before, #heart:after { z-index: -

下面是:,我现在有了这个,它有这个HTML:

<div id="heart"><span>M + G</span></div>

然而,字母仍然在心脏的后面,而我的目标是将它们放在心脏的中心,首先我认为我必须将它们放在心脏的前面,但是这失败了,你知道吗?

z-index
只对定位元素有效(位置:绝对,位置:相对,…)您的
span
elemet没有
position
属性

#heart:before, #heart:after {
    z-index: -1; // because the text will be placed behind heart.
}


或者您只需将
position:relative
添加到span中。

z-index
仅对定位元素(position:absolute,position:relative,…)有效,并且
span
元素没有
position
属性

#heart:before, #heart:after {
    z-index: -1; // because the text will be placed behind heart.
}
span {
  position: absolute;
  z-index: 4;
}

或者您只需将
位置:relative
添加到span

span {
  position: absolute;
  z-index: 4;
}
更新到中心文本:

span {
  position: relative;
  line-height: 60px;
  z-index: 4;
}

#heart {
  text-align: center;
  position: relative;
  width: 100px;
  height: 90px;
  margin-top: 10px;
  /* leave some space above */
}
更新到中心文本:

span {
  position: relative;
  line-height: 60px;
  z-index: 4;
}

#heart {
  text-align: center;
  position: relative;
  width: 100px;
  height: 90px;
  margin-top: 10px;
  /* leave some space above */
}
根据z-index只能应用于定位元素

只需将
span
设置为
位置:相对

span {
  position:relative;
  z-index: 4;
}

根据,
z-index
只能应用于定位元素

只需将
span
设置为
位置:相对

span {
  position:relative;
  z-index: 4;
}

请不要使用“有趣的标题”。这样,搜索相同解决方案的人更有可能找到您的问题。因此,我会建议适当的副本。这并不好笑,但如果你有任何建议,请让我知道或随时编辑问题!也许“搞笑”这个词不合适,但“CSS伤了我的心了吗”似乎意味着CSS给你带来了情感上的痛苦。哦,你刚才说的是我的老问题@Oriol,对不起,我没听清楚!我明白你的意思,今后我会更加小心。是的,有一点;pA工作演示:请不要使用“有趣的标题”。这样,搜索相同解决方案的人更有可能找到您的问题。因此,我会建议适当的副本。这并不好笑,但如果你有任何建议,请让我知道或随时编辑问题!也许“搞笑”这个词不合适,但“CSS伤了我的心了吗”似乎意味着CSS给你带来了情感上的痛苦。哦,你刚才说的是我的老问题@Oriol,对不起,我没听清楚!我明白你的意思,今后我会更加小心。是的,有一点;pA工作演示:有没有关于如何使用此解决方案移动心脏文本的想法?将其移动到哪里?居中?是的,你知道在心脏的中心。是的,只需添加
文本对齐:居中;线高:60px
#heart
查看有关如何使用此解决方案移动heart文本的任何想法吗?将其移动到哪里?居中?是的,你知道在心脏的中心。是的,只需添加
文本对齐:居中;线高:60px
#heart
看我先看到了John的解决方案,所以我可能会接受,但我会更新你发布的其他东西,以表示我对你的感谢。请不要,保持干净:)约翰,我很高兴你找到了你想要的东西,不过:)我更新了我读到的东西,认为它值得更新!!我同意你的看法,如果你没有我欣赏的东西,那我就不会投赞成票我首先看到了约翰的解决方案,所以我可能会接受,但我会投票支持你发布的其他内容,以表示我对你的感谢。请不要,保持整洁:)约翰,我很高兴你找到了你想要的,尽管:)我投票支持了我读到的内容,认为值得投票!!我同意你的看法,如果你没有我欣赏的东西,那我就不会投赞成票