浮动正确的元素不完全浮动



我有两列框。有左侧和右侧。由于某种原因,右侧并没有一直漂浮到容器的末端。我没有任何保证金可以阻止它这样做,所以我不确定为什么它不会全力以赴。

您可以在小提琴中看到这里:

在这里

如果您查看"单击服务以了解更多"的小文本/注释,则它已将其全部浮动到右侧,并位于容器的末端。右侧标签需要与那些右边的选项卡一样远。

另外,旁注。您会看到我具有悬停效果,从左侧向右拉新的背景颜色。我不确定为什么背景颜色不会像滑动时那样过渡。我将过渡代码到主要元素。

有人知道为什么这两件事不起作用吗?

#service-tabs {
    width: 100%;
    padding: 100px 0;
    height: auto;
    background: #F0F0F0;
    overflow: auto;
}
#service-tabs-container {
    width: 70%;
    margin: 0 auto;
    text-align: center;
}
#service-tabs-container-title {
    color: #404040;
    font-size: 1.3em;
    margin-bottom: 15px;
    text-align: left;
}
#service-tabs-container-title2 {
    color: #578570;
    font-size: 2.8em;
    margin-bottom: 20px;
    line-height: 1.4em;
    text-align: left;
}
#service-tabs-container-note {
    margin: 40px 0;
    font-size: .7em;
    text-align: right;
}
#service-tabs-left {
    float: left;
    width: 50%;
}
#service-tabs-right {
    float: right;
    width: 50%;
}
.service-tab-block {
    position: relative;
    font-size: 1.6em;
    padding: 3.5em 20px;
    /*padding: 1em 25px;*/
    width: 85%;
    text-align: center;
    color: #FFF;
    display: block;
    margin: 30px 0;
    cursor: pointer;
    border: none;
    background-image: linear-gradient(to right, #000 50%, #578570 50%);
    background-size: 201% 100%;
    background-repeat: no-repeat;
    background-position: bottom right;
    transition:width 0.2s ease;
    -webkit-transition:width 0.2s ease;
}
.service-tab-block.active {
    background: #000;
    color: #FFF;
}
.service-tab-block:hover {
    -webkit-transition: all 0.2s ease-in;
    transition: all 0.2s ease-in;
    background-position: bottom left;
    color: #FFF;
    border: none;
}

<div id="service-tabs">
  <div id="service-tabs-container">
    <div id="service-tabs-container-title">WHAT WE OFFER</div>
    <div id="service-tabs-container-title2">Our Services</div>
    <div id="service-tabs-container-note">* Click a service to find out more.</div>
    <div id="service-tabs-left">
        <h1 class="service-tab-block" id="service_tab1">DEMOLITION</h1>
        <h1 class="service-tab-block" id="service_tab2">CONCRETE CRUSHING</h1>
        <h1 class="service-tab-block" id="service_tab3">SCRAP METAL RECYCLING</h1>
    </div>
    <div id="service-tabs-right">
        <h1 class="service-tab-block" id="service_tab4">ASSET RECOVERY</h1>
        <h1 class="service-tab-block" id="service_tab5">FOUNDATION REMOVAL</h1>
        <h1 class="service-tab-block" id="service_tab6">SITE WORK</h1>
    </div>
  </div>
</div>

因为您的CSS规则中有这2个属性

.service-tab-block {
    padding: 3.5em 20px;
    width: 85%;

我更改/添加到此

.service-tab-block {
    width: calc(100% - 60px);   /* compensate for the padding and margin */
    ....
}
#service-tabs-right .service-tab-block {
    margin-left: 20px;
}

对于过渡,更改

transition:width 0.2s ease;
-webkit-transition:width 0.2s ease;

to

transition:all 0.2s ease;
-webkit-transition:all 0.2s ease;

在这里,工作过渡的可能解决方案

CSS

#service-tabs {
    width: 100%;
    padding: 100px 0;
    height: auto;
    background: #F0F0F0;
    overflow: auto;
}
#service-tabs-container {
    width: 70%;
    margin: 0 auto;
    text-align: center;
}
#service-tabs-container-title {
    color: #404040;
    font-size: 1.3em;
    margin-bottom: 15px;
    text-align: left;
}
#service-tabs-container-title2 {
    color: #578570;
    font-size: 2.8em;
    margin-bottom: 20px;
    line-height: 1.4em;
    text-align: left;
}
#service-tabs-container-note {
    margin: 40px 0;
    font-size: .7em;
    text-align: right;
}
#service-tabs-left {
    float: left;
    width: 50%;
}
#service-tabs-right {
    float: right;
    width: 50%;
}
.right1{
margin-right: -3%;
}
.service-tab-block {
    position: relative;
    font-size: 1.6em;
    padding: 3.5em 20px;
    /*padding: 1em 25px;*/
    width: 85%;
    text-align: center;
    color: #FFF;
    display: block;
    margin: 30px 0;
    cursor: pointer;
    border: none;
    background-image: linear-gradient(to right, #000 50%, #578570 50%);
    background-size: 201% 100%;
    background-repeat: no-repeat;
    background-position: bottom right;
    transition:width 0.2s ease;
    -webkit-transition:all 0.2s ease;
}
.service-tab-block.active {
    background: #000;
    color: #FFF;
}
.service-tab-block:hover {
    -webkit-transition: all 0.2s ease-in;
    transition:0.4s all ease-in;
    background-position: bottom left;
    color: #FFF;
    border: none;
}

html

<div id="service-tabs">
  <div id="service-tabs-container">
    <div id="service-tabs-container-title">WHAT WE OFFER</div>
    <div id="service-tabs-container-title2">Our Services</div>
    <div id="service-tabs-container-note">* Click a service to find out more.</div>
    <div id="service-tabs-left">
        <h1 class="service-tab-block" id="service_tab1">DEMOLITION</h1>
        <h1 class="service-tab-block" id="service_tab2">CONCRETE CRUSHING</h1>
        <h1 class="service-tab-block" id="service_tab3">SCRAP METAL RECYCLING</h1>
    </div>
    <div id="service-tabs-right" class="right1">
        <h1 class="service-tab-block" id="service_tab4">ASSET RECOVERY</h1>
        <h1 class="service-tab-block" id="service_tab5">FOUNDATION REMOVAL</h1>
        <h1 class="service-tab-block" id="service_tab6">SITE WORK</h1>
    </div>
  </div>
</div>

尝试此代码

#service-tabs {
  width: 100%;
  padding: 100px 0;
  height: auto;
  background: #F0F0F0;
  overflow: auto;
}
#service-tabs-container {
  width: 100%;
  text-align: center;
}
#service-tabs-container-title {
  color: #404040;
  font-size: 1.3em;
  margin-bottom: 15px;
  text-align: left;
}
#service-tabs-container-title2 {
  color: #578570;
  font-size: 2.8em;
  margin-bottom: 20px;
  line-height: 1.4em;
  text-align: left;
}
#service-tabs-container-note {
  margin: 40px 0;
  font-size: .7em;
  text-align: right;
}
#service-tabs-left {
  float: left;
  max-width: 50%;
}
#service-tabs-right {
  float: right;
  max-width: 50%;
}
.service-tab-block {
  position: relative;
  font-size: 1.6em;
  padding: 3.5em 20px;
  padding: 1em 25px;
  width: 85%;
  text-align: center;
  color: #FFF;
  display: block;
  margin: 30px 0;
  cursor: pointer;
  border: none;
  background-image: linear-gradient(to right, #000 50%, #578570 50%);
  background-size: 201% 100%;
  background-repeat: no-repeat;
  background-position: bottom right;
  transition: width 0.2s ease;
  -webkit-transition: width 0.2s ease;
  -webkit-transition: all 0.2s ease-in;
  transition: all 0.2s ease-in;
}
.service-tab-block.active {
  background: #000;
  color: #FFF;
}
.service-tab-block:hover {
  background-position: bottom left;
  color: #FFF;
  border: none;
}
<div id="service-tabs">
  <div id="service-tabs-container">
    <div id="service-tabs-container-title">WHAT WE OFFER</div>
    < <div id="service-tabs-container-title2">Our Services</div>
  <div id="service-tabs-container-note">* Click a service to find out more.</div>
  <div id="service-tabs-left">
    <h1 class="service-tab-block" id="service_tab1">DEMOLITION</h1>
    <h1 class="service-tab-block" id="service_tab2">CONCRETE CRUSHING</h1>
    <h1 class="service-tab-block" id="service_tab3">SCRAP METAL RECYCLING</h1>
  </div>
  <div id="service-tabs-right">
    <h1 class="service-tab-block" id="service_tab4">ASSET RECOVERY</h1>
    <h1 class="service-tab-block" id="service_tab5">FOUNDATION REMOVAL</h1>
    <h1 class="service-tab-block" id="service_tab6">SITE WORK</h1>
  </div>
</div>
</div>

如何将其添加到您的CSS

#service-tabs-right .service-tab-block{
  float: right;
  margin-bottom:0px;
}

编辑答案。

尝试以下代码。

如果我们对Div进行了分区,则应给出父宽度的CS:100%之后,每个Div具有50%的宽度。

#service-tabs-container {
    clear: both !important;
    margin: 0 auto;
    text-align: center;
    width: 100%;
}
<div id="service-tabs-container">
        <div id="service-tabs-container-title">WHAT WE OFFER</div>
        <div id="service-tabs-container-title2">Our Services</div>
        <div id="service-tabs-container-note">* Click a service to find out more.</div>

      <div class="" style="width:100%">
            <div id="service-tabs-left">
                <h1 id="service_tab1" class="service-tab-block">DEMOLITION</h1>
                <h1 id="service_tab2" class="service-tab-block">CONCRETE CRUSHING</h1>
                <h1 id="service_tab3" class="service-tab-block">SCRAP METAL RECYCLING</h1>
            </div>
            <div id="service-tabs-right">
                <h1 id="service_tab4" class="service-tab-block">ASSET RECOVERY</h1>
                <h1 id="service_tab5" class="service-tab-block">FOUNDATION REMOVAL</h1>
          <h1 id="service_tab6" class="service-tab-block">SITE WORK</h1>
      </div></div>

希望您对您有帮助。

相关内容

  • 没有找到相关文章

最新更新