如何覆盖 box-sizing: border-box;在特定部分

How to override box-sizing: border-box; on a specific section

我有一个 * {box-sizing: border-box;} 属性 使联系表单输入保持美观和独立,但它使上面的小 "gallery" 稍微偏离中心向左,我找不到如何为该特定部分覆盖它。我尝试将其作为目标并将框大小设置为内容框,但似乎没有任何效果。我错过了什么..?

抱歉这里的代码太长了,我不想错过任何东西。

这是我的代码和 Codepen:http://codepen.io/anon/pen/zKXzZP

<body>
      <section class="works">
        <div class="works--title">
          Stuff
          <hr class="horizontal">
        </div>
        <div class="works--thumbnails">
          <a href="#" class="works--item">
            <div class="works--itemtext">
              <div class="item--primarytext">
                lorem lorem lorem lorem lorem
              </div>
              <div class="item--secondarytext">
                lorem lorem lorem lorem lorem
              </div>
            </div>
          </a>
          <a href="#" class="works--item">
            <div class="works--itemtext">
              <div class="item--primarytext">
                Lorem ipsum dolor sit amet
              </div>
              <div class="item--secondarytext">
                similique nesciunt sint
              </div>
            </div>
          </a>
          <a href="#" class="works--item">
            <div class="works--itemtext">
              <div class="item--primarytext">
                Lorem ipsum dolor sit amet
              </div>
              <div class="item--secondarytext">
                similique nesciunt sint
              </div>
            </div>
          </a>
        </div>
        <!-- end works-thummbnils -->
      </section>

      <!-- CONTACT FORM -->
      <section class="about-contact">
        <div class="contact-container">

          <h2 class="contact-title">Contact me</h2>

          <form id="contact" action="#" method="post">
            <div class="left">
              <input type="text" placeholder="Name" required="required" />
              <input type="email" placeholder="Email" required="required" />
              <input type="text" placeholder="Subject" required="required" />
            </div>
            <div class="right">
              <textarea placeholder="Message" required="required"></textarea>
            </div>
            <div class="send-button cl">
              <button type="submit">Send</button>
            </div>
          </form>
        </div>
      </section>
</body>

* {
  color: black;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.works {
  padding: 40px 0px;
}

.works--title {
  font-size: 18px;
  text-align: center;
  padding-bottom: 20px;
}

.works--thumbnails {
  max-width: 600px;
  margin: 0 auto;
}

.works--thumbnails::after {
  display: block;
  content: " ";
  clear: both;
}

.works--item {
  max-width: calc(50% - 24px);
  float: left;
  margin-bottom: 20px;
  border: none;
  border-radius: 3px;
  padding: 5px;
  background: lightgreen;
  box-shadow: 0px 0px 1px rgba(0, 0, 255, 0.3);
  transition: all ease-in-out 90ms;
}

.works--item:nth-child(odd) {
  margin-right: 20px;
}

.works--itemtext {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 75px;
}

.item--primarytext {
  font-weight: 500;
  line-height: 1.3;
}

@media (min-width: 830px) {
  .works--item {
    max-width: calc(37.1% - 46px);
    margin-right: 20px;
  }
  .works--item:nth-child(3n) {
    margin-right: 0;
  }
}

@media(max-width: 370px) {
  .works--item {
    max-width: 220px;
    margin-right: auto !important;
    margin: 0px auto 20px !important;
    box-sizing: border-box;
    float: none;
    display: block;
    /*??*/
  }
}


/* CONTACT FORM */

.contact-container {
  width: 100%;
  padding: 1em;
  margin: auto;
}

.contact-container h2 {
  text-align: center;
  text-transform: uppercase;
  color: #f55;
}

#contact input[type="text"],
#contact input[type="email"],
#contact textarea {
  display: block;
  padding: 10px;
  margin: 10px auto;
  width: 100%;
  font-size: 18px;
  color: #777;
  border: 1px solid #ccc;
}

#contact textarea {
  font-size: 16px;
}

#contact input:hover,
#contact textarea:hover {
  border: 1px solid #888;
}

#contact input:focus,
#contact textarea:focus {
  border: 1px solid #777;
}

#contact textarea {
  max-width: 100%;
  min-width: 100%;
  max-height: 180px;
  min-height: 180px;
  resize: none;
}

#contact .send-button {
  text-align: center;
}

#contact .send-button button[type="submit"] {
  color: #fff;
  background: #e74c3c;
  border: none;
  width: 100%;
  padding: 10px 0;
  font-size: 20px;
  text-transform: uppercase;
  transition: .5s all ease;
  cursor: pointer;
}

#contact .send-button button[type="submit"]:hover {
  background: #c0392b;
}

#contact .send-button button[type="submit"]:focus {
  position: relative;
  top: 2px;
}


/*######################################\*
              Responsive
\*######################################*/

@media screen and (min-width: 640px) {
  .contact-container {
    width: 600px;
  }
  #contact textarea {
    max-width: 98%;
    min-width: 98%;
    min-height: 150px;
    margin-right: 0;
  }
  #contact .right,
  #contact .left {
    display: block;
  }
  #contact .right {
    float: right;
    width: 50%;
  }
  #contact .left {
    float: left;
    width: 50%;
  }
  .cl {
    clear: both;
  }
}

.about-contact {
  background-color: lightgrey;
  padding: 40px 0px;
  margin-top: 100px;
}
.works--item {
   box-sizing: content-box;
}

将此 属性 添加到 class

简单。我认为您需要设置 .works 及其所有子项。你在这里:

.works,
.works * {
   box-sizing: content-box;
}

.works * 部分是覆盖每个可以转义的 border-box

有了这个它就完美了。

以上建议可以解决您的问题,但我认为您是在为自己努力。

您的列应该只有 33.3% 宽度,左填充:20px。

然后周围的列应该有-20px的负边距;

像这样:

https://jsfiddle.net/5aeoL9vj/2/

<div class="container">
    <div class="grid">
        <div class="grid__item">
            <div class="grid__item-one">
                <span>Item 1</span>
            </div>
        </div>
        <div class="grid__item">
            <div class="grid__item-two">
                <span>Item 1</span>
            </div>
        </div>
        <div class="grid__item">
            <div class="grid__item-three">
                <span>Item 1</span>
            </div>
        </div>
    </div>
</div>