skip to Main Content

so I’d like the below button to have a small annotation (smaller font) below its main text but for the solutions, I’ve tried to resize the entire button and put

.kafelek {
            background-color: #C3CECB;
            border-radius: 5px;
            text-align: center;
            width: 230px;
            height: 100px;
            font-family: 'Open Sans';
            font-size: 20px;
            color: #003C3D;
            margin-top: 15px;
            margin-bottom: 1px;
            margin-right: 10px;
            margin-left: 0px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

            .kafelek:nth-child(5) {
                margin-right: 150px !important;
            }

            .kafelek:nth-child(6) {
                margin-left: 150px !important;
            }

            .kafelek:hover {
                border: 2px solid #7EDF00;
                transition: 0.3s;
                cursor: pointer;
            }
  <div class="kafelek">COMING SOON <div class="smallannot"> (Annotation) </div> </div>

the text on the right side instead of just starting a new line.

I’ve tried defining a new class with a smaller font size but it breaks the button entirely (the text doesn’t align properly)

2

Answers


  1. Use this CSS, adding flex-direction: column to the code helps to align the text vertically.

    .kafelek {
            flex-direction : column;
        }
    

    After doing so you will get this result,

    .kafelek {
      background-color: #C3CECB;
      border-radius: 5px;
      text-align: center;
      width: 230px;
      height: 100px;
      font-family: 'Open Sans';
      font-size: 20px;
      color: #003C3D;
      margin: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
    }
    
    .kafelek:nth-child(5) {
      margin-right: 150px !important;
    }
    
    .kafelek:nth-child(6) {
      margin-left: 150px !important;
    }
    
    .kafelek:hover {
      border: 2px solid #7EDF00;
      transition: 0.3s;
      cursor: pointer;
    }
    <div class="kafelek">COMING SOON
      <div class="smallannot"> (Annotation) </div>
    </div>
    Login or Signup to reply.
  2. If you don’t want to use flex simply create a container representing the button and then avoid nesting the divs. They’ll be displayed one under the other.

    You can tweak padding/margin to get the design you want. Furthermore, the transition doesn’t go on the hover, it goes on the element being hovered.

    .kafelek {
        background-color: #C3CECB;
        border-radius: 5px;
        text-align: center;
        width: 230px;
        padding: 20px 0;
        font-family: 'Open Sans';
        font-size: 20px;
        color: #003C3D;
        border: 2px solid transparent;
        transition: 0.3s;
    }
    
    .soon {
      margin-bottom: 10px;
    }
            
    .kafelek:hover {
        background-color: #c6f7ea;
        border: 2px solid #7EDF00;
        cursor: pointer;
    }
    <div class="kafelek">
      <div class="soon">COMING SOON</div>
      <div class="smallannot"> (Annotation) </div>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search