Tips for aligning an input field in the center using HTML, CSS, and Bootstrap

Currently, I am tackling the pomodoro challenge on free code camp and seeking guidance:

I've been attempting to center my input boxes without much success. Does anyone have any suggestions?

    var timeMin = 0;
    var timeSec = 3;
    var timerIntervalID = null;

    function pad (str, max) {
      str = str.toString();
      return str.length < max ? pad("0" + str, max) : str;
    }


    function updateTimer() {
    var displayString = "";

    console.log("Update timer()");
    if (timeSec === 0) {
    timeSec = 59;
    timeMin--;
    } else {
    timeSec--;
    }

    displayString = timeMin + ":" + pad(timeSec, 2);


    $(".timer").html(displayString);

    if (timeMin < 1 && timeSec < 1) {
    $(".timer").css('color', 'red');
    clearInterval(timerIntervalID);
    alert("Pomodoro Over!")
    }
    }

    function test() {
    console.log("Test");
    }

    $(document).ready(function() {
    $("button").click(function() {
    var whichButton = $(this).attr("value");
    console.log("Button pressed");
    switch(whichButton) {
    case "start":
    timerIntervalID = setInterval(updateTimer, 1000);
    break;
    case "reset":
    timeMin = 0;
    timeSec = 3;
    if (timerIntervalID !== null) {
    clearInterval(timerIntervalID);
    }

    $(".timer").css('color', 'black');
    displayString = timeMin + ":" + pad(timeSec, 2);
    $(".timer").html(displayString);
    break;
    }
    });
    });
    .btn-primary {
    width: 15rem;
    margin: 0.2rem;
    height: 5rem;
    }

    .btn-danger {
    width: 15rem;
    margin: 0.2rem;
    height: 5rem;
    }

    input {
            max-width: 4rem;
            text-align:center;
            display:block;
            margin:0;
     } 
    <head>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
      <link rel="stylesheet" type="text/css" href="styles.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
      <script src="main.js"></script>
    </head>

    <html>
    <head>
        <meta charset="utf-8">
        <title>fccPomodoro</title>
    </head>
      <div class="container">
        <div class="jumbotron text-center">
            <h1>fccPomodoro</h1>
              <h2 class="timer">Time Left: 25 minutes</h2>
              <button type="button" class="btn btn-primary" value="start">Start Pomodoro</button>
              <button type="button" class="btn btn-danger" value="reset">Reset</button>
              <div class="form-group">
                <label for="min">Minutes:</label>
                <input type="text" class="form-control" id="min" value="25">
              </div>
              <div class="form-group">
                <label for="sec">Seconds:</label>
                <input type="text" class="form-control" id="sec" value="00">
              </div>
        </div>
      </div>
    </html>

styles.css

.btn-primary {
    width: 15rem;
    margin: 0.2rem;
    height: 5rem;
}

.btn-danger {
    width: 15rem;
    margin: 0.2rem;
    height: 5rem;
}

input {
        max-width: 4rem;
        text-align:center;
        display:block;
        margin:0;
} 

Answer №1

Here is a tip for styling input boxes:

input {
    max-width: 4rem;
    text-align:center;
    display:block;
    margin:0 auto;
} 

Answer №2

Check out the CSS code below;

    var timerMinutes = 0;
    var timerSeconds = 3;
    var intervalID = null;

    function pad (str, max) {
      str = str.toString();
      return str.length < max ? pad("0" + str, max) : str;
    }


    function updateTimer() {
    var displayString = "";

    console.log("Update timer()");
    if (timerSeconds === 0) {
    timerSeconds = 59;
    timerMinutes--;
    } else {
    timerSeconds--;
    }

    displayString = timerMinutes + ":" + pad(timerSeconds, 2);


    $(".timer").html(displayString);

    if (timerMinutes < 1 && timerSeconds < 1) {
    $(".timer").css('color', 'red');
    clearInterval(intervalID);
    alert("Pomodoro Over!")
    }
    }

    function test() {
    console.log("Test");
    }

    $(document).ready(function() {
    $("button").click(function() {
    var clickedButton = $(this).attr("value");
    console.log("Button pressed");
    switch(clickedButton) {
    case "start":
    intervalID = setInterval(updateTimer, 1000);
    break;
    case "reset":
    timerMinutes = 0;
    timerSeconds = 3;
    if (intervalID !== null) {
    clearInterval(intervalID);
    }

    $(".timer").css('color', 'black');
    displayString = timerMinutes + ":" + pad(timerSeconds, 2);
    $(".timer").html(displayString);
    break;
    }
    });
    });
    .btn-primary {
    width: 15rem;
    margin: 0.2rem;
    height: 5rem;
    }

    .btn-danger {
    width: 15rem;
    margin: 0.2rem;
    height: 5rem;
    }

    .form-group {
            text-align:center;
     } 

    .form-group input {
            max-width: 4rem;
            display:block;
            margin:0 auto 0 auto;
     } 
    <head>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
      <link rel="stylesheet" type="text/css" href="styles.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
      <script src="main.js"></script>
    </head>

    <html>
    <head>
        <meta charset="utf-8">
        <title>fccPomodoro</title>
    </head>
      <div class="container">
        <div class="jumbotron text-center">
            <h1>fccPomodoro</h1>
              <h2 class="timer">Time Left: 25 minutes</h2>
              <button type="button" class="btn btn-primary" value="start">Start Pomodoro</button>
              <button type="button" class="btn btn-danger" value="reset">Reset</button>
              <div class="form-group">
                <label for="min">Minutes:</label>
                <input type="text" class="form-control" id="min" value="25">
              </div>
              <div class="form-group">
                <label for="sec">Seconds:</label>
                <input type="text" class="form-control" id="sec" value="00">
              </div>
        </div>
      </div>
    </html>

Answer №3

Ever attempted to enclose the input tag within a center tag?

<center><input type="text" ></center>

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

Steps to keep the gridlines in the chart from moving

Take a look at the example provided in the following link: Labeling the axis with alphanumeric characters. In this particular instance, the gridlines adjust dynamically based on the coordinate values. How can we modify this so that the chart remains static ...

Check if any element within a class satisfies the specified condition using Jquery

I am looking to determine if any element within a specific class meets a set of conditions. For example: $(document).on('click','.modalInner_form_nav', function(){ var input = $(this).parents('.modalInner_form').find(' ...

Utilizing PHP to share content on Facebook

I am encountering an issue on a particular page of mine where there are multiple images. Each image has its own share and like button. When I click on the share button, I expect to share that specific image but it is not working as expected. Can someone pl ...

Simple guide to identifying when the content of a dropdown option changes using jQuery

I am seeking a solution for detecting changes in the options of a dropdown field that are updated dynamically. Is there a method to capture an event each time the set of options within the dropdown is modified? I am not looking to track individual option ...

Best practice for sending JSON in Formdata using the POST method

Exploring the proper way to submit a form when the server expects JSON data. The backend is built on node.js with express framework, using bodyparser.json() middleware to parse request bodies. Currently, I'm using JavaScript to intercept form submiss ...

What is the best way to retrieve classes from arrays and apply styling to them using javascript?

Imagine having 3 unique classes: alpha, beta, and gamma. Each class contains 3 individual div elements like so: <div class="alpha"></div> <div class="alpha"></div> <div class="alpha"></div> <div class="beta">< ...

Learn how to display or conceal the HTML for 'Share this' buttons on specific routes defined in the index.html file

Currently, I am in the process of updating an existing Angular application. One of the requirements is to hide the "Share this buttons" on specific routes within the application. The "Share" module typically appears on the left side of the browser window a ...

What is the best way to choose a random number using jQuery?

<div class="yyy"></div> <p>...</p> <pre><code>let content = $(".xxx").text(); $(".yyy").html(content); http://jsfiddle.net/tQeCv/ I just require this specific input : Number is {1|2|3|4}, and {one|two|three|four} ...

Table-cell display for spanning columns

Can elements be extended across columns by using the display: table-cell property similar to how <td> is stretched in a table with colspan="100%"? ...

Leveraging R-selenium for extracting information from a website built with aspx technology

As a newcomer to the world of R and Selenium, I hope I can clearly explain my question. I am trying to extract data from a website (.aspx) by inputting a chemical code that will lead me to information on the next page using R-selenium commands. I have mana ...

The hamburger menu in Bootstrap collapses along with the navigation items when viewed on a mobile device

How can I resolve the issue of the hamburger menu icon collapsing with the nav-items when clicked? Navbar <header> <div class="container-fluid"> <div class="row"> <div class="col-12 col-sm-12"> ...

Tips for uploading two different file types using a single PHP form

This is the layout of my form: <form action='uploadFile.php' method='POST'> <p>Choose an image:</p> <p style='font-size: 10px'>280x280px</p> ...

Guide on utilizing a Django login form with Python

I created a login form using Django, but I'm facing an issue with the routing. When I click on the login button, the form doesn't submit the correct answer. I believe that the frontend form is not able to fetch the correct response from the view. ...

Looking to retrieve the dynamic "Publish Date" value from a webpage using HtmlUnit in Java?

As part of a coding exercise, I am currently working on a project that involves comparing the current system date with dates on various web pages to determine if there are any new updates. While most of the pages work as expected, there is one particular p ...

Utilizing div tags for creating backgrounds in HTML

I am currently in the process of developing a website and would like to incorporate particles.js as my background while overlaying the content. However, I'm facing an issue where the content is displaying on top of the page instead of behind it when I ...

Struggling to Find Embedded Frame Components Using Xpath

Encountering an issue with Xpath while attempting to locate nested frame elements. The code in question is as follows: <html> <head> <frameset border="0" framespacing="0" frameborder="0"> <frame noresize="" name="main" src="main.py"&g ...

Unable to automatically play a YouTube video that is covered by a custom thumbnail

Currently, I have set up a custom thumbnail for a YouTube video on my website. However, when the user clicks on the thumbnail, they are directed to the video page and must click again to start playing the video. I would like the video to automatically play ...

Split screen on iPad is detrimental to the user experience of my website

I have developed a responsive website using CSS with media queries. Upon testing it on various devices, I noticed an issue with the iPad split screen feature. When the screen is split with a ratio of 3:1 and my website is opened in the smaller area, it dis ...

From HTML to Python CGI to communication with a Serial port

I am having an issue running a Python CGI script to send data to a serial port. Whenever I try to open and set the serial port to a variable, the HTML server crashes. Below is the code snippet that receives a color (red, blue, green) from the HTML page: ...

Navigating Liferay Portlet in reverse order

I am facing an issue with right to left alignment in my portlet. It displays correctly when tested on a regular HTML page, but switches to left to right alignment when integrated into a Liferay portlet. Below is the code snippet causing this problem: < ...