pexichdu
pexichdu

Reputation: 899

Broken button with small width

I have a button where if the container width is too small, my button breaks instead of breaking the line of the text. Do you have any idea how I can fix it?

Below is an example of it, along with a JSFiddle link here.

.column {width: 200px; margin-top:100px;}
.btn {font-family: 'futura-pt';	font-size: 16px; text-transform: uppercase; letter-spacing: 1px; font-weight: 500; font-style: normal; color: #444; border: 2px solid #444;
    -webkit-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
    -moz-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
    -ms-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
    -o-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
    transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
    padding-top: 1em;
    padding-right: calc(1.44em - 1px);
    padding-bottom: 1em;
    padding-left: 1.44em}
<div class="column">
  <div class="btn_container">
  <a class="btn" href="#">This is a text button</a>
  </div>
</div>

Upvotes: 0

Views: 55

Answers (2)

Heta
Heta

Reputation: 75

.column {
  width: 200px;
  margin-top: 100px;
}

.btn {
  border: 2px solid #444;
  display: block;
  font-family: 'futura-pt';
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 500;
  font-style: normal;
  color: #444;
  -webkit-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  -moz-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  -ms-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  -o-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  padding-top: 1em;
  padding-right: calc(1.44em - 1px);
  padding-bottom: 1em;
  padding-left: 1.44em;
}
<div class="column">
  <div class="btn_container">
    <a class="btn" href="#">This is a text button</a>
  </div>
</div>

Upvotes: 1

Obsidian Age
Obsidian Age

Reputation: 42304

You need to put the border on the same element that you add the width to. Simply shift it to .column:

.column {
  width: 200px;
  margin-top: 100px;
  border: 2px solid #444;
}

.btn {
  font-family: 'futura-pt';
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 500;
  font-style: normal;
  color: #444;
  -webkit-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  -moz-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  -ms-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  -o-transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  transition: color 170ms ease-in-out, border-color 170ms ease-in-out;
  padding-top: 1em;
  padding-right: calc(1.44em - 1px);
  padding-bottom: 1em;
  padding-left: 1.44em
}
<div class="column">
  <div class="btn_container">
    <a class="btn" href="#">This is a text button</a>
  </div>
</div>

Note that you may also want to remove the padding on the <a> and add text-align: center in order to display the text a bit 'nicer'. I've created an updated fiddle showcasing the change I mean here.

Hope this helps! :)

Upvotes: 1

Related Questions