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

时间:2016-10-26 15:52:53

标签: css box-sizing

我有一个* {box-sizing:border-box;}属性,可以使联系表单输入保持良好且分离,但它会使小型的#34; 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;
}

3 个答案:

答案 0 :(得分:5)

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

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

.works *部分将覆盖可以逃脱的每个border-box

有了它,它可以完美地运作。

答案 1 :(得分:2)

.works--item {
   box-sizing: content-box;
}

将此属性添加到类

答案 2 :(得分:1)

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

你的列应该只有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>