skip to Main Content

How to make this button in CSS. I am able to make a circular button button but not able to style second line of text.

Button needs to two lines of text, each styled differently. Also entire area needs to be clickable.

.drs-button{
  min-width: 240px;
  max-width: 240px;
  text-decoration: none;
  display: inline-block;
  outline: none;
  cursor: pointer;
  border-style: none;
  color: black;
  font-size: 4em;
  background-color: #ffffff;
  border-radius: 100%;
  overflow: none;
  text-align: center;
  padding:0;
}
.drs-button:before {
  content:'';
  display:inline-block;;
  vertical-align:middle;
  padding-top:100%;
}

.drs-button:active{
  background-color: #2980b9;
}

circular button with two lines of text each styled differently

3

Answers


  1. Have you tried wrapping the text(s) you want styled differently in a span element(s) and then giving them a id/class selector to style it?

    Login or Signup to reply.
  2. Buttons are allowed to contain phrasing content, which includes inline child elements such as <span>.

    So, simply wrap the two parts of your button content in <span> elements.

    <button class="drs-button">
      <span>Line One</span>
      <span>Line Two</span>
    </button>
    

    Then you can style each span differently, as illustrated in this snippet.

    body {
      background: navy;
    }
    
    .drs-button {
      font-size: 2em;
      padding: 0.5em;
      aspect-ratio: 1;
      outline: none;
      cursor: pointer;
      border: 0;
      border-radius: 50%;
      color: black;
      background-color: #ffffff;
      overflow: none;
      text-align: center;
    }
    
    .drs-button:hover {
      background-color: yellow;
    }
    
    .drs-button span {
      display: block;
    }
    
    .drs-button span:last-child {
      font-family: serif;
      font-size: 0.5em;
      font-style: italic;
      color: #dd0000;
    }
    <button class="drs-button">
      <span>Line One</span>
      <span>Line Two</span>
    </button>
    Login or Signup to reply.
  3. Another way to do it without aspect ratio and last-child pseudo elements.

    body {
      background: navy;
      font-family: sans-serif;
      font-size: 16px;
    }
    
    .btn-drs {
      font-size: 1.75rem;
      padding: 0.5em;
      cursor: pointer;
      border: 0;
      border-radius: 50%;
      color: black;
      background-color: #ffffff;
      overflow: hidden;
      text-align: center;
      height: 150px;
      width: 150px;
    }
    
    .btn-drs:hover {
      background-color: #333;
      color: #FFF;
    }
    
    .btn-drs span.txt-primary,
    .btn-drs span.txt-secondary{
      display: block;
    }
    
    .btn-drs span.txt-secondary {
      font-family: serif;
      font-size: 0.5em;
      font-style: italic;
      color: #dd0000;
    }
    
    .btn-drs:hover span.txt-secondary {
      color: #EEF;
    }
    <button class="btn-drs">
      <span class="txt-primary">Line One</span>
      <span class="txt-secondary">Line Two</span>
    </button>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search