Centered checkbox instead of left-aligned

Can someone help me troubleshoot an issue with my sign-in form? I can't seem to get the remember me checkbox aligned to the left, it keeps centering in the middle of the form. Any advice on what might be causing this?

On a side note, I'm also curious why my submit button is not the same size as the other input text boxes. Is there a specific reason for this discrepancy?

#sign-in-form {
width: 400px;
height: auto;
padding: 50px 30px;
margin: auto;
border-radius: 3px;
background: rgba(115,155,175,0.2);
}
#sign-in-form input {
width: 100%;
padding: 8px 6px;
margin: 22px auto;
display: block;
font-size: 1.4em;
border-radius: 3px;
border: none;
}
#sign-in-form input[type="checkbox"] {
padding: 7px;
text-align: left;
}
#sign-in-form input[type="submit"] {
background: #4FCBFE;
color: #FFF;
border: none;
border-radius: 3px;
}
<div id="sign-in-form">
<input type="text" name="username" placeholder="User Name" autocomplete="on" required>
<input type="password" name="password" placeholder="Password" autocomplete="off" required>
<label><input type="checkbox" name="remember" id="remember">Remember me</label>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="submit" value="Sign In">
</div>

Answer №1

Ensure the width is set to auto and include margin-left: 0

#sign-in-form input[type="checkbox"] {
    padding: 7px;
    text-align: left;
    width: auto;
    margin-left: 0;
}

See the functional code snippet below.

#sign-in-form {
width: 400px;
height: auto;
padding: 50px 30px;
margin: auto;
border-radius: 3px;
background: rgba(115,155,175,0.2);
}
#sign-in-form input {
width: 100%;
padding: 8px 6px;
margin: 22px auto;
display: block;
font-size: 1.4em;
border-radius: 3px;
border: none;
}
#sign-in-form input[type="checkbox"] {
padding: 7px;
text-align: left;
    width: auto;
    margin-left: 0;
}
#sign-in-form input[type="submit"] {
background: #4FCBFE;
color: #FFF;
border: none;
border-radius: 3px;
}
<div id="sign-in-form">
<input type="text" name="username" placeholder="User Name" autocomplete="on" required>
<input type="password" name="password" placeholder="Password" autocomplete="off" required>
<label><input type="checkbox" name="remember" id="remember">Remember me</label>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="submit" value="Sign In">
</div>

This revised code should meet your requirements:

#sign-in-form {
width: 400px;
height: auto;
padding: 50px 30px;
margin: auto;
border-radius: 3px;
background: rgba(115,155,175,0.2);
}
#sign-in-form input {
width: 100%;
padding: 8px 6px;
margin: 22px auto;
display: block;
font-size: 1.4em;
border-radius: 3px;
border: none;
}
#sign-in-form input[type="checkbox"] {
padding: 7px;
text-align: left;
    width: auto;
    display: inline-block;
    margin: 5px 5px 0 0;
}
#sign-in-form input[type="submit"] {
background: #4FCBFE;
color: #FFF;
border: none;
border-radius: 3px;
}
<div id="sign-in-form">
<input type="text" name="username" placeholder="User Name" autocomplete="on" required>
<input type="password" name="password" placeholder="Password" autocomplete="off" required>
<label><input type="checkbox" name="remember" id="remember">Remember me</label>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="submit" value="Sign In">
</div>

Answer №2

To adjust the layout, you should eliminate the 100% width and auto margin from the checkbox, but most importantly, add display: inline-block; to have the Remember me text appear inline with the checkbox.

Take a look at the modified snippet provided below!

#sign-in-form {
width: 400px;
height: auto;
padding: 50px 30px;
margin: auto;
border-radius: 3px;
background: rgba(115,155,175,0.2);
}
#sign-in-form input {
width: 100%;
padding: 8px 6px;
margin: 22px auto;
display: block;
font-size: 1.4em;
border-radius: 3px;
border: none;
}
#sign-in-form input[type="checkbox"] {
margin-right: 7px;
text-align: left;
    width: auto;
    display: inline-block;
    
}
#sign-in-form input[type="submit"] {
background: #4FCBFE;
color: #FFF;
border: none;
border-radius: 3px;
}
<div id="sign-in-form">
<input type="text" name="username" placeholder="User Name" autocomplete="on" required>
<input type="password" name="password" placeholder="Password" autocomplete="off" required>
<label><input type="checkbox" name="remember" id="remember">Remember me</label>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="submit" value="Sign In">
</div>

Answer №3

The issue arose due to the CSS property #sign-in-form input {}. To resolve this, you can modify it as follows: #sign-in-form input[type="text"],[type="password"],[type="submit"]{}. If you have any questions, feel free to ask in the comments section. :)

#sign-in-form {
width: 400px;
height: auto;
padding: 50px 30px;
margin: auto;
border-radius: 3px;
background: rgba(115,155,175,0.2);
}
#sign-in-form input[type="text"],[type="password"],[type="submit"] {
width: 100%;
padding: 8px 6px;
margin: 22px auto;
display: block;
font-size: 1.4em;
border-radius: 3px;
border: none;
}
#sign-in-form input[type="checkbox"] {
/*ADD YOUR CSS FOR CHECK BOX*/
}
#sign-in-form input[type="submit"] {
background: #4FCBFE;
color: #FFF;
border: none;
border-radius: 3px;
}
<div id="sign-in-form">
<input type="text" name="username" placeholder="User Name" autocomplete="on" required>
<input type="password" name="password" placeholder="Password" autocomplete="off" required>
<label><input type="checkbox" name="remember" id="remember">Remember me</label>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="submit" value="Sign In">
</div>

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

Real-Time Chat Update Script

Recently, I've been delving into PHP and attempting to create a live chat web application. The data for the chat is stored in a MySQL database, and I have written a function called UpdateDb() that refreshes the chat content displayed in a certain div ...

Is it possible to place the CSS menu on the right side of the screen

Is there a way to reposition the dropdown menu so that it appears on the right side of the title instead of below it? I've checked the CSS code but can't seem to find anything that ties it to the left side of the screen. https://i.sstatic.net/n0 ...

Scrolling horizontally without needing to press the Shift key

I've had no luck finding results in any of my searches so far. Is there a way to implement 'horizontal scrolling' without requiring the user to hold down the shift key while scrolling? ...

Retrieving byte data from an HTML file results in varying byte arrays across different devices

During the process of creating unit tests for a project that utilized the Razor engine to generate HTML, I encountered a peculiar issue. To ensure the accuracy of the unit test, I manually set the model, executed the function, and saved the resulting HTML ...

Turn on and off scrolling of DIV content when hovering over it

How can I create a div that automatically scrolls to the bottom on hover? I tried implementing the code below, but it doesn't work as expected. It jumps to the bottom of the div's height on first hover and transitions smoothly on second hover. . ...

Unlock maximum screen viewing on your custom video player with these steps to activate fullscreen

I'm having an issue with my basic video player - when toggling fullscreen, it doesn't fill the whole screen even though I tried using .fullscreen{width:100%} without success after searching for a solution. html <div class='player-contai ...

Dealing with conditional CSS problems in Angular - a solution needed?

Is there a way to maintain the CSS class for the first property ID even when clicking on a second property ID? Currently, the CSS class is removed from the first property ID when a second one is clicked. How can I make sure the CSS class remains for the fi ...

How can the overflow:hidden be applied to the body after a specified height, rather than the height of the viewport

My page has a <body> element with a height of 800px, however the content exceeds this height. I would like the body to display content up to 800px and then hide the rest, but using overflow:hidden hides all content beyond the viewport height of 678p ...

Incorporate an additional ring around the outer edge of the donut pie chart

I have been attempting to create a donut pie chart similar to the one shown below. The main challenge I am facing is with the outer strip. How can I achieve this effect? Your guidance in the right direction would be greatly appreciated. https://i.sstati ...

Struggling with z-index or float issues on Chrome and Safari with CSS styling

Check out my website at I have incorporated the Easy Slider 1.7 plugin from this source and made some custom JavaScript modifications for a banner rotator. The issue I am facing is that on webkit browsers, the navigation links (1,2,3,4,5) on the banner a ...

Only the first row of the table is responsive to the jQuery click listener

My issue lies in the fact that the code snippet below only triggers the pop-up box for the first delete button selected. Subsequent buttons do not respond. How can I adjust it so that any delete button clicked will activate the script? <a class="btn bt ...

Troubleshooting problem with Z-Index conflict in Flash animation

I am facing an issue with two HTML divs - one containing a flash movie and the other simple text. I want to place the textual div on top of the flash movie div, but no matter how I set their positions in CSS or adjust their Z-Index values, the text keeps ...

Unusual CSS behavior discovered while implementing horizontal scrolling navbar with overflow-x

I've been working on a navbar that will scroll horizontally when it exceeds the width of its parent container. It features a bottom border with a different color for the active link. Using a negative margin to overlap them works well, but as soon as ...

Trouble with displaying <tr> inside <td> element

Why are my internal rows not appearing inside the td element? <tr id="group_1_id"> <th>Group 1</th> <td> <tr id="1"><td>1</td><td>One</td><td><input type="text" name="one" valu ...

Need help modifying a UseStatus to target an axios post response efficiently?

Hey there, back again with a head-scratcher I've been dealing with all day. Almost done with a contact form, just stuck on an animation concept that involves three steps: 1. Prompting the user to contact 2. Making the waiting process user-friendly ...

Step-by-step guide on accessing values from a JavaScript object

I have a dictionary variable declared within a script tag on an HTML page. My goal is to retrieve the values associated with the "Roads" and "Intersections" keys, which change each time the page is refreshed. By capturing these values, I can then use JavaS ...

fetching images from the database

I am currently working on a classified website project where I want to display one photo from the database on the main page, the same photo on a category page, and then all photos when viewing the full item listing page. My goal is to have a similar setup ...

What is an alternative method for incorporating an external webpage into a website without utilizing an iframe

I've been trying to embed the Amazon website into a webpage, similar to what's been done here: Initially, I attempted to use an iframe, but Amazon blocks it from being displayed as a security precaution: <iframe src="http://www.amazon.com/" ...

Navigate through a specific div element

I am facing a dilemma with the following code: #points{ width:25%; background:#2a2a2a; height:20px; color:white; z-index:2; position:absolute; } #areas{ position:absolute; color:white; border-right:2px solid black; height:120%; ...

When you hover over an image, it transforms into the full-screen background

I am looking to add a unique feature to my blog where the background is standard (for example, black color), but when I hover over a random image on the blog, that image will expand and become a full-screen background. Here is the code snippet I have trie ...