How to centre elements in a div - html

I try to bring input fields in to the centre of the page. For some reasons the padding that I have set for the input fields moves them to right and I don't want this. Could please somebody help me to fix this? Here is the code.
.BeWeird_register_container {
display: flex;
justify-content: center;
}
.BeWeird_register_wrapper {
width: 60%;
}
input[type=text],
select {
border: none;
width: 100%;
padding: 30px 20px;
margin: 8px 0;
display: inline-block;
background-color: #000;
color: #BBFB34;
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
font-size: 1.2vw;
}
<div class="BeWeird_register_container">
<div class="BeWeird_register_wrapper">
<div class="BeWeird_login_wrapper">
<div class="login_image"><img src="Images/LoginImage.png" alt="" /></div>
<form method="post" action="BeWeird_login.php">
<?php include('errors.php'); ?>
<div class="login_form_wrapper">
<div class="input-group">
<input class="login" type="text" placeholder="Username" name="username">
</div>
<div class="input-group">
<input class="login" type="password" placeholder="Password" name="password">
</div>
<div class="input-group">
<button class="login" type="submit" class="btn" name="login_user">Login</button>
</div>
</form>
</div>
</div>
</div>
Help would much appreciated. Thanks for in advance.

In my opinion, you put display: flex in styles of the wrong container.
You want to center the DOM of login_form_wrapper.
Remember that flex-direction is set to row` as default.
Here's a nice explanation of how to use flex.
A Complete Guide to Flexbox
Correct me if I am wrong but as far as I understand that's what you are looking for:
JsFiddle
David

To center inputs in your form, add style="text-align:center;" to the parent element that contains the inputs, in this case that is the login_form_wrapper class.
Also, if you check the boxes in the browser (F12), you will see that the div BeWeird_login_wrapper shows larger than it should be. For simplicity, just make use of the structure above this heading MDN web docs and nest the divs.

thanks for your help guys. The code was fine. It just needed in the input css code box-sizing:border-box;
like this:
input.login[type=text], select {
border:none;
width: 100%;
padding: 30px 20px;
margin: 8px 0;
box-sizing:border-box;
background-color: #000;
color:#FEA6E5 !important;
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
font-size:1.2vw;
}

You can mention use:
outer-element{
display:flex;
justify-content:center;
align-items:center;
}

Related

How to position elements in a webpage CSS

How would I be able to position all these elements in the middle of the webpage?
for example the h1 a bit above the input, but all relative to each other, also taking into account that it should be responsive. I know how to position them using position: absolute; but I'd like to know what a better practice would be.
https://jsfiddle.net/w75ksg69/3/
html {
background-color: rgb(171, 248, 235);
font-family: sans-serif,Tahoma, Verdana, 'Times New Roman';
}
h1#maintitle {
margin: 0 0 0 0;
text-align: center;
}
div#info {
font-size: 1em;
margin: 0.5em;
}
<body>
<h1 id="maintitle">Find your new abcde</h1>
<div id="info">
<input name="arrive" type="date" placeholder="Arrival date:">
<input name="departure" type="date" placeholder="Departure date:">
<input name="guests" type="number" placeholder="Guests:">
<button id="search_button" type="button">Search</button>
</div>
</body>
I made all your inputs on the center using just text-align: center:
div#info {
font-size: 1em;
text-align: center;
}
Hope, it helps

Trying to center a div but nothing can't get anything to work [duplicate]

This question already has answers here:
CSS center display inline block?
(9 answers)
Closed 4 years ago.
I am trying to center a simple div but I am failing miserably. Nothing I try works, including many examples here on Stack Overflow. Here is (the main part of) my CSS:
body {
min-height: 640px;
background: #282a36;
color: #bcc3cd;
font-size: 12px;
margin: 0;
font-family: 'Source Sans Pro', sans-serif;
}
#nickbox {
border: 1px solid white;
display: inline;
padding: 5px;
background-color: #ffffff00;
}
<div id="welcome">
<p tabindex="0" class="title">
Cards Against Oakbank
</p>
<p class="subtitle">A Cards Against Humanity clone.</p>
<div id="nickbox">
<label for="nickname">Nickname:</label>
<input type="text" id="nickname" value="" maxlength="20" role="textbox"
aria-label="Enter your nickname." data-lpignore="true" />
<input type="button" id="nicknameconfirm" value="Set" />
<span id="nickbox_error" class="error"></span>
</div>
</div>
There's no attempt at centering in there right now as I've run out of ideas. What should I use? I just want the #nickbox to be centered horizontally on every screen. I don't really care about supporting older browsers, it's varying resolutions that I care about. Thanks.
For layout, it's better to use FlexBox. It's more, well....flexible :) . It's very easy to use and understand.
For example, use display:flex on parent #welcome . Together with flex-direction:column so the child elements don't stay on one line but one below the other. Then on your desired element use align-self:center to center it inside the parent container.
Read more about FlexBox
body {
min-height: 640px;
background: #282a36;
color: #bcc3cd;
font-size: 12px;
margin: 0;
font-family: 'Source Sans Pro', sans-serif;
}
#nickbox {
border: 1px solid white;
display: inline;
padding: 5px;
background-color: #ffffff00;
align-self:center;
}
#welcome {
display:flex;
flex-direction:column;
}
<div id="welcome">
<p tabindex="0" class="title">
Cards Against Oakbank
</p>
<p class="subtitle">A Cards Against Humanity clone.</p>
<div id="nickbox">
<label for="nickname">Nickname:</label>
<input type="text" id="nickname" value="" maxlength="20" role="textbox"
aria-label="Enter your nickname." data-lpignore="true" />
<input type="button" id="nicknameconfirm" value="Set" />
<span id="nickbox_error" class="error"></span>
</div>
</div>
OBS With flexbox to align items horizontally you use justify-content on parent or justify-selfon the desired child. To align them vertically you use align instead of justify. In the above example i used align to align horizontaly because of the flex-direction:column which changes the default direction of the elements. That's why the align and justfy styles are reversed
The problem is related to the following line of code:
#nickbox {
...
display: inline; \
...
}
An 'inline' element behaves like Text.
Most solutions on Stack Overflow about 'centering' a DIV use the 'Block' display. So those solutions are not going to work for you.
But there is hope yet! Because text elements are easily centered with a 'text-align: center' line. Add this line to body and it should fix your problem.
This should fix your problem. See the following JS Fiddle:
http://jsfiddle.net/jcolicchio/kNB3c/
body {
min-height: 640px;
background: #282a36;
color: #bcc3cd;
font-size: 12px;
margin: 0;
font-family: 'Source Sans Pro', sans-serif;
text-align:center;
}
When i comes to positioning something, always use flexbox
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Live working example: https://jsfiddle.net/ty6zcsw9/
html: surround div with id nickbox with div with nickbox-container
<div class='nickbox-container'>
<div id="nickbox">
<label for="nickname">Nickname:</label>
<input type="text" id="nickname" value="" maxlength="20" role="textbox" aria-label="Enter your nickname."
data-lpignore="true" />
<input type="button" id="nicknameconfirm" value="Set" />
<span id="nickbox_error" class="error"></span>
</div>
</div>
css: add following to your css
.nickbox-container{
display: flex;
justify-content: center;
}
Yu can try this
body {
min-height: 640px;
background: #282a36;
color: #bcc3cd;
font-size: 12px;
margin: 0;
font-family: 'Source Sans Pro', sans-serif;
}
#nickbox {
border: 1px solid white;
display: inline;
padding: 5px;
background-color: #ffffff00;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div id="welcome">
<p tabindex="0" class="title">
Cards Against Oakbank
</p>
<p class="subtitle">A Cards Against Humanity clone.</p>
<div id="nickbox">
<label for="nickname">Nickname:</label>
<input type="text" id="nickname" value="" maxlength="20" role="textbox"
aria-label="Enter your nickname." data-lpignore="true" />
<input type="button" id="nicknameconfirm" value="Set" />
<span id="nickbox_error" class="error"></span>
</div>
</div>
hi can you check this https://jsfiddle.net/fnq9v4s5/1/ , you can adjust vertically giving proper vertical height to .nickcontainer
<div id="welcome">
<p tabindex="0" class="title">
Cards Against Oakbank
</p>
<p class="subtitle">A Cards Against Humanity clone.</p>
<div class="nickcontainer">
<div id="nickbox">
<p class="filed">
<label for="nickname">Nickname:</label>
<input type="text" id="nickname" value="" maxlength="20" role="textbox"
aria-label="Enter your nickname." data-lpignore="true" />
<input type="button" id="nicknameconfirm" value="Set" />
<span id="nickbox_error" class="error"></span>
</p>
</div>
</div>
</div>
css
body {
background: #282a36;
color: #bcc3cd;
font-size: 12px;
margin: 0;
font-family: 'Source Sans Pro', sans-serif;
}
#nickbox {
padding: 5px;
background-color: #ffffff00;
display: table-cell;
vertical-align: middle;
}
.nickcontainer{
display: table;
height: 82vh;}
p.filed{
border:solid 1px #fff;
display:block;
padding:5px;
}
There are many ways to fix your little problem.
The easiest way is to change display:inline of #nickbox to display:block and set text-align:center. All elements in the div will automatically flow to the center.
You could, alternatively set the width of #nickbox and set margin:0 auto.
Or, set #nickbox to display: flex justify-content: center.

Trying to align upload button with a Textarea in HTML and CSS

I'm making a webpage for one of my projects and I'm trying to align the Upload buttons beside a text field. Maybe better explained as a picture. You can see that the two buttons are aligned on the bottom left of the submit button. I want it to be aligned on the left of the device Id text field. I've tried setting the display attributes for the text field, as well as the two buttons but it didn't work. I tried setting the float properties, which also didn't work. I was looking at grids I could possibly use from Purecss.io, but I'm not sure if that would fix the problem. I've tried using vertical-align attribute, still no dough.
I'm using a plain bootstrap theme. My HTML skills are pretty basic coming from Java. Anyone know what I can do here?
Here is my main container:
<div class="container">
<!-- Main content here -->
<div id="main">
<h1 id="mainheader">Send an image to a Wearable device</h1>
<hr>
<form method="post" action="/gcm/gcm.php/?push=true" onsubmit="return checkTextAreaLen()">
<textarea id="deviceID" rows="1" name="message" cols="25" placeholder="Device ID"></textarea> <br/>
<button type="submit" id="mainbutton" class="button-xlarge pure-button">Send Image</button>
</form>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<div id="filebutton">
<input type="file" name="fileToUpload" id="fileToUpload">
</div>
<input type="submit" value="Upload Image" name="submit">
</form>
</div>
Here are my styles
#main {
vertical-align: middle;
}
#status{
text-align: center;
background-color: #FFFFFF;
padding: 10px;
margin-top: 25px;
}
#mainheader{
margin-bottom: 20px;
text-align: center;
font-family: 'Raleway', sans-serif;
}
#deviceID {
display: block;
margin-left: auto;
margin-right: auto;
}
#mainbutton {
display: block;
margin-left: auto;
margin-right: auto;
}
.button-xlarge {
font-size: 125%;
width:350px;
background: rgb(66, 184, 221); /* this is a light blue */
}
Here is a preview image: (Having trouble uploading it directly)
http://tinypic.com/view.php?pic=1z499gw&s=8
EDIT:
I somewhat fixed this by applying "float:right" on the first whole form, the text area and the button. There is still a huge horizontal between the two.
#main {
float:right;
}
#main {
text-align: center;
}
#mainheader{
margin-bottom: 20px;
text-align: center;
font-family: 'Raleway', sans-serif;
}
#mainbutton {
display: block;
margin: 35px auto;
}
.button-xlarge {
font-size: 125%;
width:350px;
background: rgb(66, 184, 221); /* this is a light blue */
}
input[type="submit"], #deviceID {
display: inline;
vertical-align: middle;
margin-top: 35px;
}
.left{
float: left;
text-align: left;
}
<div id="main">
<h1 id="mainheader">Send an image to a Wearable device</h1>
<hr>
<form method="post" action="/gcm/gcm.php/?push=true" onsubmit="return checkTextAreaLen()">
<textarea id="deviceID" rows="1" name="message" cols="25" placeholder="Device ID"></textarea>
<input type="submit" value="Upload Image" name="submit">
<button type="submit" id="mainbutton" class="button-xlarge pure-button">Send Image</button>
</form>
<form class="left" action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<div id="filebutton">
<input type="file" name="fileToUpload" id="fileToUpload">
</div>
</form>
</div>
i think this is what you are asking for.
i rearranged your html a little and added a couple of css rules.
by setting the display on the device id field and the upload button to inline instead of block i got them to be on the same line.
i used vertical-align to... well... align them. and gave them a margin-top.
then floated your second form to the left.

Just lost with a CSS style

Sorry, I feel like making someone else to do my job but I feel really lost here, here's an image of what I got now:
Where the two "Anonomymos" are is ment to be the place for tha active users in the chat, however, the more people I add to the chat the <div> tag where the message is posted goes under the <div> tag for the active users and obviously I want to be shown next to each other.I use a premade CSS style sheet for this, and hope that it could be changed in way to work for my needs, but I have poor knowledge about CSS so I'm not even sure if it is usable in my case, anyways, here is the CSS style that I use at the moment:
#ActiveUsers
{
clear:both;
border: 1px solid #cccccc;
width: 356px;
background: #E9ECEF;
font-family: Arial, Helvetica, sans-serif;
font-weight:bold;
font-size : 12px;
padding:2px;
margin-bottom:10px;
margin-top:10px;
margin-left: 60px;
}
#chat
{
margin: auto;
border: 1px solid #cccccc;
width: 356px;
background: #E9ECEF;
text-align:left;
font-family: Arial, Helvetica, sans-serif;
font-weight:bold;
font-size : 12px;
padding:2px;
height:400px;
overflow:auto;
}
#main {
margin: auto;
border: 1px solid #cccccc;
width: 600px;
min-height:150px;
background: #F1F3F5;
font-family: Arial, Helvetica, sans-serif;
font-weight:bold;
font-size : 12px;
border-collapse:collapse;
}
#sender
{
margin-left: 125px;
}
And here is the structure in the .php file :
<div id="main">
<div id="ActiveUsers"></div>
<div id="chat"></div>
<div id="sender">
Your message: <input type="text" name="msg" size="30" id="msg" />
<button onclick="doWork(document.getElementById('msg').value);">Send</button>
</div>
<span id="logOut">
<form action="logout.php">
<input type="submit" value="Logout"/>
</form>
</span>
</div>
P.S Just to mention, now the #ActiveUsers width is more than the free space but even if I make it 30px, the #chat <div> still goes under and under with every new user that is logged.
The issue might be that your Active Users are wrapped in some block-element when they are dynamically added to your markup. Based on how it is displayed, I'm guessing that
<div id="ActiveUsers"></div>
turns into
<div id="ActiveUsers"><div>Anonymos</div> <div>Anonymos</div></div>
Check to see if your active users are wrapped by any tag. If they're wrapped with a <div> tag, you'll need to add this to your CSS:
#ActiveUsers div {
display: inline;
.
. /* Your styles here */
.
}

HTML Label widths, want fixed but it keeps auto-sizing according to text?

I am creating some tabs using labels, then im going to add some simple hover over javascript. However i want all the labels to be of fixed size with the text in the centre. This is what i have:
<style>
.button
{
border-style:solid;
border-width:1px;
background-color:rgb(193,203,225);
font: normal 14px arial, sans, sans-serif;
text-align:center;
color: rgb(54,95,145);
width:100px;
margin: 0px;
padding: 0px;
padding-top: 3px;
padding-bottom: 3px;
text-align: center;
}
</style>
<label id='Label5' class='button'> Personal Details </label>
<label id='Label1' class='button'> Education </label>
<label id='Label2' class='button'> Achievements </label>
<label id='Label3' class='button'> Work Experience </label>
<label id='Label6' class='button'> IT Skills </label>
<label id='Label4' class='button'> Languages </label>
but its not working? Could someone please help?
a layer is a inline-element, and you can't give a width to inline-elements. try to set display:inline-block for .button (note that this isn't supported by IE6)
you need to add display:block to get widths to work, and then add float:left to get them to layout the way you want
Set display: inline-block to the .button class as labels are inline elements so it does not recognize your width.
label.button {
display: block;
text-align: center;
width: 100px;
}