停用网格内的边框,只留下一个框

我不擅长CSS,我只想只删除框内的边缘,只留下外边缘。


.grid-container {

  display: grid;

  grid-template-columns: auto auto auto;

  background-color: #2196F3;

  padding: 10px;

}


.grid-item {

  background-color: rgba(255, 255, 255, 0.8);

  border: 1px solid rgba(0, 0, 0, 0.8);

  padding: 20px;

  font-size: 30px;

  text-align: center;

}

<h1>Grid Elements</h1>

<p>A Grid Layout must have a parent element with the <em>display</em> property set to <em>grid</em> or <em>inline-grid</em>.</p>

<p>Direct child element(s) of the grid container automatically becomes grid items.</p>

<div class="grid-container">

  <div class="grid-item">1</div>

  <div class="grid-item">2</div>

  <div class="grid-item">3</div>

  <div class="grid-item">4</div>

  <div class="grid-item">5</div>

  <div class="grid-item">6</div>

  <div class="grid-item">7</div>

  <div class="grid-item">8</div>

  <div class="grid-item">9</div>

</div>

白衣染霜花
浏览 107回答 3
3回答

富国沪深

您可以通过以下方法来实现此目的:删除网格项上的边框并使用容器上的大纲属性:.grid-container {&nbsp; display: grid;&nbsp; grid-template-columns: auto auto auto;&nbsp; background-color: #2196F3;&nbsp; padding: 10px;&nbsp; outline: 1px solid black;&nbsp; outline-offset: -10px;}.grid-item {&nbsp; background-color: rgba(255, 255, 255, 0.8);&nbsp; padding: 20px;&nbsp; font-size: 30px;&nbsp; text-align: center;}<h1>Grid Elements</h1><p>A Grid Layout must have a parent element with the <em>display</em> property set to <em>grid</em> or <em>inline-grid</em>.</p><p>Direct child element(s) of the grid container automatically becomes grid items.</p><div class="grid-container">&nbsp; <div class="grid-item">1</div>&nbsp; <div class="grid-item">2</div>&nbsp; <div class="grid-item">3</div>&nbsp; <div class="grid-item">4</div>&nbsp; <div class="grid-item">5</div>&nbsp; <div class="grid-item">6</div>&nbsp; <div class="grid-item">7</div>&nbsp; <div class="grid-item">8</div>&nbsp; <div class="grid-item">9</div></div>

杨__羊羊

这是你想要的?为此,您只需创建一个带边框的容器框。.grid-container {&nbsp; background-color: #2196F3;&nbsp; padding: 10px;}.grid-item {&nbsp; background-color: rgba(255, 255, 255, 0.8);&nbsp; padding: 20px;&nbsp; font-size: 30px;&nbsp; text-align: center;}.container {&nbsp; border: 1px solid rgba(0, 0, 0, 0.8);&nbsp; grid-template-columns: auto auto auto;&nbsp; display: grid;}<h1>Grid Elements</h1><p>A Grid Layout must have a parent element with the <em>display</em> property set to <em>grid</em> or <em>inline-grid</em>.</p><p>Direct child element(s) of the grid container automatically becomes grid items.</p><div class="grid-container">&nbsp; <div class="container">&nbsp; &nbsp; <div class="grid-item">1</div>&nbsp; &nbsp; <div class="grid-item">2</div>&nbsp; &nbsp; <div class="grid-item">3</div>&nbsp; &nbsp; <div class="grid-item">4</div>&nbsp; &nbsp; <div class="grid-item">5</div>&nbsp; &nbsp; <div class="grid-item">6</div>&nbsp; &nbsp; <div class="grid-item">7</div>&nbsp; &nbsp; <div class="grid-item">8</div>&nbsp; &nbsp; <div class="grid-item">9</div>&nbsp; </div></div>

拉丁的传说

您还可以像这样更改您的代码:.grid-container {&nbsp; display: grid;&nbsp; grid-template-columns: auto auto auto;&nbsp; background-color: #2196F3;&nbsp; padding: 0;&nbsp; border: 1px solid rgba(0, 0, 0, 0.8);&nbsp; box-shadow: 0 0 0 10px #2196F3;}.grid-item {&nbsp; background-color: rgba(255, 255, 255, 0.8);&nbsp; padding: 20px;&nbsp; font-size: 30px;&nbsp; text-align: center;}<h1>Grid Elements</h1><p>A Grid Layout must have a parent element with the <em>display</em> property set to <em>grid</em> or <em>inline-grid</em>.</p><p>Direct child element(s) of the grid container automatically becomes grid items.</p><div class="grid-container">&nbsp; <div class="grid-item">1</div>&nbsp; <div class="grid-item">2</div>&nbsp; <div class="grid-item">3</div>&nbsp; <div class="grid-item">4</div>&nbsp; <div class="grid-item">5</div>&nbsp; <div class="grid-item">6</div>&nbsp; <div class="grid-item">7</div>&nbsp; <div class="grid-item">8</div>&nbsp; <div class="grid-item">9</div></div>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5