How can I add a button with 100% width and position:fixed

Viewed 607

I tried a lot of solutions here at stackoverflow but nothing is working.

a.buttongc {
  border-radius: 5px;
  background: #f5b220;
  color: #fff;
  font-size: 17px;
  height: 44px;
  line-height: 42px;
  color: #fff;
  text-decoration: none;
  text-align: center;
  box-sizing: border-box;
  -webkit-appearance: none;
  -moz-appearance: none;
  -ms-appearance: none;
  appearance: none;
  white-space: nowrap;
  margin: 10px;
  text-overflow: ellipsis;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  overflow: hidden;
  display: block;
}

.gc-button-center {
  position: fixed;
  left: 0;
  right: 0;
  display: block;
  width: 100%;
  bottom: 50px;
  z-index: 999999999;
}
<div class="gc-button-center">
  <a href="#" class="buttongc startgc">test</a>
</div>

screenshot

I want to have a margin left and right but it is only working at the left side and the button goes over the scrollbar. any solution?

2 Answers

Nothing fancy needed. Just remove your width: 100% If display is block, and width is not supplied, the width will auto size to fit the parent.

    a.buttongc{
     border-radius: 5px;
     background: #f5b220;
        color: #fff;
     font-size: 17px;
        height: 44px;
        line-height: 42px;
        color: #fff;
        text-decoration: none;
        text-align: center;
        box-sizing: border-box;
        -webkit-appearance: none;
        -moz-appearance: none;
        -ms-appearance: none;
        appearance: none;
        white-space: nowrap;
     margin:10px;
        text-overflow: ellipsis;
        font-family: inherit;
        cursor: pointer;
     overflow:hidden;
       display: block;
        
    }
    
    .gc-button-center{
      position:fixed;
      left:0;
      right:0;
      display:block;
      width: 100%;
      bottom: 50px;
      z-index:999999999;
    
    }
    <div class="gc-button-center">
    <a href="#" class="buttongc startgc">test</a>
    </div>

Just change width: calc(100% - 20px); for subtract margin

a.buttongc{
    border-radius: 5px;
    background: #f5b220;
    color: #fff;
    font-size: 17px;
    height: 44px;
    line-height: 42px;
    color: #fff;
    text-decoration: none;
    text-align: center;
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-appearance: none;
    appearance: none;
    white-space: nowrap;
    margin:10px;
    text-overflow: ellipsis;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
    overflow:hidden;
    display: block;

}

.gc-button-center{
  position:fixed;
  left:0;
  right:0;
  display:block;
  width: calc(100% - 20px);
  bottom: 50px;
  z-index:999999999;

}
<div class="gc-button-center">
  <a href="#" class="buttongc startgc">test</a>
</div>

Related