Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.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
Css 边距而非元素的边框颜色_Css - Fatal编程技术网

Css 边距而非元素的边框颜色

Css 边距而非元素的边框颜色,css,Css,我是否可以设置边距框边框的样式,而不是元素框本身的样式 例如: |-------------------------------| | | | |--------------------| | | | | | | |---box-color: red---| | | | |---margin-bor

我是否可以设置边距框边框的样式,而不是元素框本身的样式

例如:

|-------------------------------|
|                               |
|    |--------------------|     |
|    |                    |     |
|    |---box-color: red---|     |
|                               |
|---margin-border-color: blue---|

如果你需要这样的东西,你应该使用填充物

例如:

<div class="box-around">
    <div class="box">
         some text here
    </div>
</div>
如果你想把这个元素放在中心,那么这是另一个问题

可以使用其他方法使图元居中。像这样:

.box-around {
    text-align: center;
}
.box {
    display: inline-block;
}

JsFiddle补充道:

好的,边距没有边框。如果由于要使用
margin:0 auto
,因此要将边框设置为外部框,则需要包装元素并向父元素添加边框。例如:

.wrapper{
宽度:100%;
边框:1px纯蓝色;
填充:10px;
框大小:边框框;
}
.内部{
宽度:200px;
背景:红色;
保证金:0自动;
文本对齐:居中;
}

同侧阴唇

您也可以使用伪元素:

.borders {
  position: relative;
  border: 5px solid #f00;
}
.borders:before {
  content: " ";
  position: absolute;
  z-index: -1;
  top: 5px;
  left: 5px;
  right: 5px;
  bottom: 5px;
  border: 5px solid #ffea00;
}

不要这样认为,使用填充物instead@Tasos问题是我不能做
padding:auto代替
页边距:自动,我正在使用它来居中放置box元素的内容。一个插图中的边距、填充和边框:。编辑:虽然“边距框”上不能有边框,但可以用另一个
div
将其包装并设置边框。顺便说一句,考虑添加一个JScDeld.你真的不清楚你想要做什么……需要更好的解释。对我来说,这听起来更像是你应该给父元素的背景上色,而不是元素本身。@Ofir Baruch:如果OP能够创建一个工作小提琴,那么他们会回答自己的问题。很明显,OP为什么选择使用ASCII艺术而不是小提琴来说明他们想要的结果;而不是边距:自动;,我用它来居中方框元素的内容我更新了我的答案-它包括如何居中方框的说明。@alexandernst现在还有一个JSFIDLE附在答案上。它使用固定高度,我不能使用。固定高度有什么问题?固定高度的问题是。。。好。。。固定高度本身。固定值在大多数情况下是无用的;在这种特殊情况下,我不知道内容会有多高。这可能会奏效,我需要试试。将在完成测试后提供反馈。
.borders {
  position: relative;
  border: 5px solid #f00;
}
.borders:before {
  content: " ";
  position: absolute;
  z-index: -1;
  top: 5px;
  left: 5px;
  right: 5px;
  bottom: 5px;
  border: 5px solid #ffea00;
}