首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不知道为什么我的div之间有空格

我不知道为什么我的div之间有空格
EN

Stack Overflow用户
提问于 2020-01-13 02:22:31
回答 3查看 50关注 0票数 0

我正在做一个有4个不同列(Div)的页脚。这4个divs都在一个容器中。我将这些divs的宽度设置为25%,所以它们应该都可以放在同一条“线”中,但事实并非如此,我给每个divs添加了不同的div,以查看额外的空格来自哪里,我发现在div之间有一个空格,既不是边距也不是填充。我在Stackoverflow上查找了一下,我认为我找到了一个解决方案,但是将父元素的font-size设置为0,然后重置子元素的font-size并不起作用……

代码语言:javascript
复制
footer {
background-color: #000;
color: #BFBFBF;
padding: 60px;
}

.footer-container {
    width: 85%;
    background-color: red;
}

.footer-col {
    display: inline-block;
    width: 25%;
}

.fc-1 {
    background-color: orange;
}

.fc-2 {
    background-color: green;
}

.fc-3 {
    background-color: blue;
}

.fc-4 {
    background-color: yellow;
}

footer a {
    color: #BFBFBF;
    transition: none;
    display: block;
}

footer a:hover {
    color: #BFBFBF;
}
代码语言:javascript
复制
<footer>

    <div class="footer-container">

        <div class="footer-col fc-1">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>

        <div class="footer-col fc-2">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>

        <div class="footer-col fc-3">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>

        <div class="footer-col fc-4">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>

    </div>

</footer>

EN

回答 3

Stack Overflow用户

发布于 2020-01-13 02:29:04

删除所有空格:

代码语言:javascript
复制
footer {
  background-color: #000;
  color: #BFBFBF;
  padding: 60px;
}

.footer-container {
  width: 85%;
  background-color: red;
}

.footer-col {
  display: inline-block;
  width: 25%;
}

.fc-1 {
  background-color: orange;
}

.fc-2 {
  background-color: green;
}

.fc-3 {
  background-color: blue;
}

.fc-4 {
  background-color: yellow;
}

footer a {
  color: #BFBFBF;
  transition: none;
  display: block;
}

footer a:hover {
  color: #BFBFBF;
}
代码语言:javascript
复制
<footer>
  <div class="footer-container">
    <div class="footer-col fc-1">
      <a href="#">Ledmanipulation</a>
      <a href="#">Kinesiotape</a>
      <a href="#">Akut skadesbehandling</a>
      <a href="#">Triggerpunktsbehandling</a>
    </div><div class="footer-col fc-2">
      <a href="#">Ledmanipulation</a>
      <a href="#">Kinesiotape</a>
      <a href="#">Akut skadesbehandling</a>
      <a href="#">Triggerpunktsbehandling</a>
    </div><div class="footer-col fc-3">
      <a href="#">Ledmanipulation</a>
      <a href="#">Kinesiotape</a>
      <a href="#">Akut skadesbehandling</a>
      <a href="#">Triggerpunktsbehandling</a>
    </div><div class="footer-col fc-4">
      <a href="#">Ledmanipulation</a>
      <a href="#">Kinesiotape</a>
      <a href="#">Akut skadesbehandling</a>
      <a href="#">Triggerpunktsbehandling</a>
    </div>
  </div>
</footer>

票数 0
EN

Stack Overflow用户

发布于 2020-01-13 02:31:54

所以我建议在你的容器上使用Flexbox is a useful technique to position elements来解决这个问题,你也可以删除容器中所有的空格,will prevent the spacing from appearing

代码语言:javascript
复制
.footer-container {
    display: flex;
    width: 85%;
    background-color: red;
}

.footer-col {
    display: inline-block;
    width: 25%;
}

.fc-1 {
    background-color: orange;
}

.fc-2 {
    background-color: green;
}

.fc-3 {
    background-color: blue;
}

.fc-4 {
    background-color: yellow;
}

footer a {
    color: #BFBFBF;
    transition: none;
    display: block;
    word-wrap: break-word;
}

footer a:hover {
    color: #BFBFBF;
}
代码语言:javascript
复制
<footer>
    <div class="footer-container">
        <div class="footer-col fc-1">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>
        <div class="footer-col fc-2">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>
        <div class="footer-col fc-3">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>
        <div class="footer-col fc-4">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>
    </div>
</footer>

票数 0
EN

Stack Overflow用户

发布于 2020-01-13 02:32:15

通过使用flex-box,您将能够使用flex-basis: 25%; flex-grow: 0;而不是width: 25%;来解决此问题

代码语言:javascript
复制
footer {
background-color: #000;
color: #BFBFBF;
padding: 60px;
}

.footer-container {
    width: 85%;
    display: flex;
    background-color: red;
}

.footer-col {
    display: inline-block;
    flex-basis: 25%;
flex-grow: 0;
}

.fc-1 {
    background-color: orange;
}

.fc-2 {
    background-color: green;
}

.fc-3 {
    background-color: blue;
}

.fc-4 {
    background-color: yellow;
}

footer a {
    color: #BFBFBF;
    transition: none;
    display: block;
}

footer a:hover {
    color: #BFBFBF;
}
代码语言:javascript
复制
<footer>

    <div class="footer-container">

        <div class="footer-col fc-1">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>

        <div class="footer-col fc-2">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>

        <div class="footer-col fc-3">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>

        <div class="footer-col fc-4">
            <a href="#">Ledmanipulation</a>
            <a href="#">Kinesiotape</a>
            <a href="#">Akut skadesbehandling</a>
            <a href="#">Triggerpunktsbehandling</a>
        </div>

    </div>

</footer>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59706838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档