简体   繁体   English

带有div样式(html / css)的div内的线/边距/边框

[英]line / margin / border inside of the div with div styling (html / css)

For some practical reasons, I need to achieve the center / middle line inside of the div with div styling. 出于某些实际原因,我需要使用div样式实现div内部的中心/中线。

<div style="position: relative; left: 0px; top: 0px; width: 80px; height: 90px; border-left: solid 1px black;" onclick="this.style.background='rgba(0, 0, 0, 0.5)';" oncontextmenu="return false;"></div>

div in action -> http://jsfiddle.net/ZkC68/ div的作用-> http://jsfiddle.net/ZkC68/

How to achieve this? 如何实现呢? If there isn't a better way, I was thinking to move for ex. 如果没有更好的方法,我正在考虑搬迁。 left border inside, but I don't know how... 左边界在里面,但我不知道如何...

If you want to style the center line directly I think that's not possible. 如果您想直接设置中心线的样式,我认为那是不可能的。 (no such css selector exists) However, you can do something like this: (不存在这样的CSS选择器)但是,您可以执行以下操作:

<div id="container">
<div id="center-line">Center line</div>
</div>

And the CSS for styling as requested: 以及样式要求的CSS:

#center-line
{
text-align: center;
vertical-align: middle;
padding: 20px; //not necessary, but makes it look good imo
}

See: http://jsfiddle.net/cdkyZ/1/ 请参阅: http//jsfiddle.net/cdkyZ/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM