Button from Bootstrap extends beyond the page on mobile devices

I am facing an issue with my button. It looks great on desktop, but when I switch to the mobile version, it goes beyond the screen width like in the image below:

https://i.sstatic.net/69Zbs.png

1) How can I prevent this from happening with the code provided in my bootply?

2) Also, how do I add a top margin to the button?

To view my bootply click here.

This is snippet of my HTML code:

.content-section-d {
  padding: 50px 0 0 0;
}
.centered-text {
  text-align: center
}
/* Buttons */

.btn,
.btn:link,
.btn:visited {
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  padding: 15px 40px;
  background-color: #db4632;
  font-size: 20px;
  letter-spacing: 0;
  text-transform: uppercase;
  border-color: #db4632;
  box-shadow: 0 2px 2px 0 rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2), 0 1px 5px 0 rgba(0, 0, 0, .12)
}

.btn:active,
.btn:hover {
  background-color: #db4632;
}
<div class="content-section-d">

  <div class="container">
    <div class="row centered-text">
      <div class="col-md-4 col-xs-12">
        <h3>4,000,000+</h3>
      </div>
      <div class="col-md-4 col-xs-12">
        <h3>1,500,000+</h3>
      </div>
      <div class="col-md-4 col-xs-12">
        <h3>150,000+</h3>
      </div>
    </div>
    <div class="row centered-text">
      <div class="col-md-4 col-xs-12">
        <h3>68,000+</h3>
      </div>
      <div class="col-md-4 col-xs-12">
        <h3>2,000+</h3>
      </div>
      <div class="col-md-4 col-xs-12">
        <h3>3 years</h3>
      </div>
    </div>
    <div class="col-lg-12 text-center">
      <a href="https://www.apple.com" target="_blank" class="btn btn-primary btn-lg">Register for a Free Account</a>
    </div>

  </div>
  <!-- /.container -->
</div>
<!-- /.content-section-d -->

Answer №1

As mentioned in previous comments, you will need to utilize the @media rule.

Below is the code snippet for styling your button that should be included in your stylesheet:

@media(max-width: 1200px) {
    .btn span {
        display: block;
        max-width: 200px;
        white-space: normal;
    }
}

Make sure to add a <span> element to your button. The updated button code should look like this:

<button href="https://www.apple.com" target="_blank" class="btn btn-primary btn-lg"><span>Register for a Free Account</span></button>

You can view a fully functional example on JSFiddle by clicking here.

P.S. Remember to customize the max-width property within the @media rule according to your needs.

Answer №2

Adjusting text size based on screen dimensions can be easily achieved using vw and vh CSS properties. Simply add the following code snippet:

  font-size:3vw;
  font-size:1.8vh;

Tweak the values to suit your specific requirements and you'll notice a significant improvement in responsiveness.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Switching Text in ReactJS from V to X: A Tutorial

I have been utilizing a Switch component from react-switch in my project. import Switch from 'react-switch'; render() { return <Switch onChange={this.onChangeStatus} onClick={this.onChangeStatus} c ...

Float a div within text to be positioned vertically

Is there a way to use only CSS to create an article that includes a featured quote section starting around 50px from the top? The section should be half the width of the page with text wrapping around it at the top and bottom. Currently, I am using the fl ...

Tips for Passing On Parent tabindex Value to Children

Is there a way to propagate a parent's tabindex value to all of its children without individually setting tabindex for each child? Here is an example code snippet: <div id="app"> <div tabindex="2" class="parent-sec ...

What is causing the pull-right class to not function correctly in Bootstrap version 4.1.0?

After upgrading from Bootstrap version 3+ to 4.1.0, I encountered an issue with aligning elements using pull-right and pull-left, as well as float-right and float-left. The problem persists despite my efforts. Here is an image (https://i.sstatic.net/Z6ba3. ...

Align an image in the center vertically within a left-floated div with a minimum height

I am currently attempting to vertically align an image within a div that is positioned to the left, and has a minimum height of 150 pixels. The issue I am facing is that none of my attempts seem to be successful. I have tried various methods, including ut ...

Creating rounded buttons with Font Awesome icons and hover effects

I am currently working on creating buttons similar to the design shown in the image below. https://i.sstatic.net/hMqHs.png I have utilized stacked Font Awesome icons to place the icons atop a circle, resulting in this look: https://i.sstatic.net/rtEkP.p ...

Ensure that when adjusting the height of a div, the content is always pushed down without affecting the overall layout of the page

My webpage contains a div element positioned in the middle of the content, with its height being adjustable through JavaScript code. I am seeking a way to manage the scrolling behavior when the height of the div changes. Specifically, I want the content t ...

Rapid processing of JavaScript upon page load

I recently implemented a dark mode feature on my WordPress site. Here are the four modes I included: 1- Automatically based on user's system settings 2- Light mode 3- Semi-lit mode 4- Dark mode The implementation is in place and functioning perf ...

Ways to elevate a tone on an HTML webpage

When I start my Python server from the command prompt, any print statements that are reached will be displayed. How can I make sure these messages show up on the template login.html? Views.py def home(request): templatename="login.html" ...

Unlock the innerHTML of a DIV by clicking a button with ng-click in Angular JS

I am curious about something. There is a <div> and a <button> in my code. I am looking to access the inner markup of the <div> within the ng-click function without relying on jQuery. Can you give me some guidance? <div id = text-entry ...

What is the best way to transform the data received from this function into a DataTable that can be used with the Google Charts API?

Is there a way to easily convert the data returned by this function into a format that Google Charts API can read? public function ajax_get_dates(){ $data = ([['date1' => '04/08/2016'], ['date2' => '05/08/2016& ...

Rendering of @font-face on Windows 7 was executed flawlessly

I have been utilizing @font-face to implement custom fonts on a website. The custom font displays correctly in Firefox, IE, Safari, and Chrome on Mac. However, when viewed on Chrome in Windows 7, the text appears green at 10px instead of black or grey. ... ...

How to show table cell value in Angular 4 using condition-based logic

I am a beginner in Angular development. Here is the HTML code I am working with: <tr *ngFor="let item of calendarTableSelected; let idx = index"> <span *ngIf="idx === 0"> <td style="width:15%;" *ngFor="let name of item.results" ...

Could you please review my PHP code? I encountered a syntax error: unexpected '}' character. Thank you

I encountered an issue in the final line <?php } ?> as it reports a syntax error, unexpected '}' <?php if (isset($_SESSION['u_id'])) { //echo "You are logged in!"; include_once 'database.php&apo ...

Prevent the loading of a <img> element and replace it with a new one using CSS

Is there a way to hide an <img> element without accessing the HTML directly, only by using CSS? The <img> element does not have any specific class. Here is the HTML markup: <img title="Manual" id="imgAjuda" src="images/ico_aj.png" width=" ...

A customizable and adaptable Tetris-inspired CSS design perfect for any screen size

If we imagine having a block like this: <div class="block"></div> There are different sizes of the block: <div class="block b1x1"></div> <div class="block b2x1"></div> <div class="block b1x2"></div> For i ...

sequentially animating elements using animate css in a choreographed manner

I have created a unique jsfiddle with 20 boxes that I am trying to animate using the Animate.css plugin. The plugin can be found at daneden.me/animate. My goal is to animate each box one after the other in a sequential manner, but I seem to be having trou ...

Can microdata be concealed using CSS without any problems?

Imagine having an HTML document filled with a substantial amount of text. Would it be considered "good" (or at least not bad) practice to include elements containing microdata that are hidden from the user's view? For example: <div style="display ...

combine two columns into a single responsive list group item

Using Bootstrap 4, I created an item list and divided it into two columns (see image). However, when I resized the website to a mobile size screen, it displayed like this: https://i.sstatic.net/0iPHm.png My desired outcome is for the list to display in o ...

Tips for centering a horizontal unordered list within a division element

I can't seem to figure out why the text-align center isn't working. I've followed other tutorials and applied the textalign: center to the div, then added display: inline to the ul. Below is a sample of my HTML code from the browser as I am ...