HTML -webkit-center issue - html

I wrote some code and I realize there is an issue. When I use -webkit-center and write something in textbox, all items going to the right. I tried other -webkit align settings but there are no problem, just -webkit-center. I researched about it but I can't find anything. Can anyone explain why?
Here is the code you can also try.
<div id="mainDiv" style="text-align: -webkit-center; display: inline-grid; margin-left: 40%;border-style:double;">
<span>HEADER</span>
<input name="header" type="text" id="header" style="margin: 20px;width:173px;">
<span>CONTENT</span>
<input name="content" type="text" id="content" style="margin: 20px;height:50px;width:350px;">
<span>HEADER COLOR</span>
<input name="headColor" type="text" id="headColor" style="margin: 20px;width:173px;">
<span>CONTENT COLOR</span>
<input name="contColor" type="text" id="contColor" style="margin: 20px;width:173px;">
<input type="submit" name="button" value="SUBMIT" id="button" style="height: 30px;width:173px;margin:20px;">
</div>

-the webkit-center property works differently than the normal text-center property. Instead of aligning the content, block tries to sort the elements.
I got the same look by doing different styling. You can control it. for each input, you will need to type media query to be responsive because you give constant width values.
#mainDiv {
display: flex;
flex-direction: column;
align-items: center;
}
<div id="mainDiv" style=" text-align: center;width: 40%; margin:auto;border-style:double;">
<span>HEADER</span>
<input name="header" type="text" id="header" style="margin: 20px;width:173px;">
<span>CONTENT</span>
<input name="content" type="text" id="content" style="margin: 20px;height:50px;width:350px;">
<span>HEADER COLOR</span>
<input name="headColor" type="text" id="headColor" style="margin: 20px;width:173px;">
<span>CONTENT COLOR</span>
<input name="contColor" type="text" id="contColor" style="margin: 20px;width:173px;">
<input type="submit" name="button" value="SUBMIT" id="button" style="height: 30px;width:173px;margin:20px auto;">
</div>

Hi Göksel ÖZER
You could try to use the code below to experiment with some other features and HTML tags for this type of scenarios.This will include separating the inline style and include it in a tag in the head section of the HTML or if possible, save it in a separated CSS file to include it on the head of the html file as well for best practices.
I kindly invite you to start digging more about the fantastic world of CSS, Please have a look at this link for more information regarding this amazing world.
input[type=button], input[type=submit], input[type=reset] {
background-color: #9F9F9F;
border: 2px solid gray;
color: white;
padding: 0 10px;
text-decoration: none;
margin: 4px;
cursor: pointer;
}
#mainDiv {
text-align: center;
text-align: -moz-center;
text-align: -webkit-center;
display: inline-grid;
width:55%;
border-style:double;
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -1%);
}
.header{
color:#A9A9A9 !important;
margin-bottom: 5px;
}
#button {
height:30px;
width:173px;
margin:20px;
}
textarea {
width:174px !important;
height:50px !important;
padding: 0;
border: 1px solid #ccc;
text-align: center;
text-align: -moz-center;
text-align: -webkit-center;
}
.myinputs {
height:20px;
line-height:20px;
width:173px;
text-align: center;
text-align: -moz-center;
text-align: -webkit-center;
}
<div id="mainDiv">
<h4 class="header">HEADER</h4>
<input name="header" type="text" id="header" class="myinputs">
<h4 class="header">CONTENT</h4>
<input name="content" type="text" id="content" class="myinputs">
<h4 class="header">HEADER COLOR</h4>
<input name="headColor" type="text" id="headColor" class="myinputs">
<h4 class="header">CONTENT COLOR</h4>
<textarea class="header">
</textarea>
<input type="submit" name="button" value="SUBMIT" id="button">
</div>

Related

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.

How can i place "Comment:" on red line?

How can I place "Comment:" on red line as shown in the above picture? I know it's a little bit of a silly question, but as a beginner it would be helpful for me.
Here is a code snippet:
body {
border: 1px solid black;
height: 550px;
width: 550px;
padding: 5px;
}
h2 {
text-align: center;
}
<h2>FeedBack Form</h2>
<strong>Name:</strong>
<input type="text" />
<br>
<br>
<strong>Comment:</strong>
<input type="text" style="height:100px; width:250px;" />
<br>
<br>
<strong>Email Address:</strong>
<input type="text" />
See this fiddle
Please add vertical-align: text-top; or vertical-align: top; as style for the input.
Add the below given to your CSS
input[type="text"]{
vertical-align: text-top;
}
try with this:
<strong>Comment:</strong> <input type="text" style="height:100px; width:250px; vertical-align:top;"/><br><br>
I just added vertical-align: top to you input text.
But as a suggestion, I think you may want to use textarea instead input text. And inline css styles is not a thing I would recommend.
Add vertical-align css property
<strong style="vertical-align: top;">Comment:</strong>
<html>
<head>
<title>FeedBack Form</title>
<style>
body {
border: 1px solid black;
height:550px;
width:550px;
padding:5px;
}
h2 {
text-align: center;
}
</style
</head>
<body>
<h2>FeedBack Form</h2>
<strong>Name:</strong> <input type="text" /><br><br>
<strong style="vertical-align: top;">Comment:</strong> <input type="text" style="height:100px; width:250px;"/><br><br>
<strong>Email Address:</strong> <input type="text" />
</body>
</html>

Space issue in div box alignment

Am designing the 'Login' page, here, the page look okay before I press the submit button, but, just after I pressed the submit button, it looks not okay. The second div moved little bit downward. Any help to solve this issue? pls refer the below image
html
<div class="LogIn">
<form id="UserLogIn" name="loginForm" method="post"> <!-- onsubmit="return validateForm(this);" -->
<label>Firstname Lastname</label><input type="text" name="username" placeholder="Firstname Lastname"/>
<span class="user-name">Name should not be empty</span>
<label>Password</label><input type="password" name="password" placeholder="Password"/>
<label>Confirm password</label><input type="password" name="password1" placeholder="Confirm password"/>
<span class="password">Password does not be match</span>
<label>Email</label><input type="email" name="email" placeholder="Email"/>
<span class="email">Email is not valid</span>
<label>Website</label><input type="url" name="url" placeholder="Website"/>
<span class="urlcontent">Invalid Website URL</span>
<input name="submit" type="submit" value="Submit"/>
</form>
</div>
<div class="BusinessConnect">
<p>Business Unit</p>
<div id="BuCheck" class="BusinessCont">
<p><input type="checkbox" name="checkboxG1" id="checkbox1" class="form-checkbox" value="Sapient"/><label for="checkbox1" class="form-label">Test</label></p>
<p><input type="checkbox" name="checkboxG2" id="checkbox2" class="form-checkbox" value="SapientNitro"/><label for="checkbox2" class="form-label">TestNitro</label></p>
<p><input type="checkbox" name="checkboxG2" id="checkbox3" class="form-checkbox" value="Test Global Market"/><label for="checkbox3" class="form-label">Test Global Market</label></p>
<p><input type="checkbox" name="checkboxG2" id="checkbox4" class="form-checkbox" value="Test Government Services"/><label for="checkbox4" class="form-label">Test Government Services</label></p>
<p><input type="checkbox" name="checkboxG2" id="checkbox5" class="form-checkbox" value="Test (m)PHASIZE"/><label for="checkbox5" class="form-label">Test (m)PHASIZE</label></p>
</div>
</div>
css
.BusinessConnect {
float: left;
font-size: 80%;
height: 30%;
margin-right: 0;
position: relative;
top: 3px;
width: 35%;
}
.LogIn {
float: left;
margin-left: 256px;
margin-top: 15px;
width: 30%;
}
After the 'submit' button pressed,
One of the way you can follow is by seperating the divs like this,
<section>
<div id="LogIn">
You can put your thing here
</div>
<div id="BusinessConnect">
<p>Business Unit</p>
Your second part
</div>
</section>
/// Your CSS
section {
width: 100%;
height: 200px;
margin: auto;
padding: 10px;
}
div#BusinessConnect {
border:1px solid #000000;
margin-left:50%;
height: 200px;
}
div#LogIn {
width: 45%;
float: left;
border:1px solid #000000;
height:200px;
}
Its just a sample, you can further work on it.
And I myself prefer using % instead of pixels, because they are helpful for responsive layouts.
Many different ways to accomplish what you'd like, but if floating isn't a necessity you could try the following:
.BusinessConnect {
display: table-cell;
vertical-align: top;
font-size: 80%;
height: 30%;
margin-right: 0;
position: relative;
top: 3px;
width: 35%;
}
.LogIn {
display: table-cell;
vertical-align: top;
margin-left: 256px;
margin-top: 15px;
width: 30%;
}

Conflicting issues with position: relative;

I recently edited the way a template was designed for MyBB. Fortunately, I made it exactly how I expected it to look, however, the navigation bar seemed broke. After trying to navigate, I realized that I could only click on the lower half of the navigation.
http://gyazo.com/99337bd5252b37e118ce119d5168bcf3
As you can see where I painted the red boxes is the only place where the link activation works. After about 2 hours I found out my problem was due to a "position: relative;". When I remove it, the navigation works fine but my panel div becomes moved all the way to the right and out of position.
<div class="main-bg">
<div class="main-width">
<a name="top" id="top"></a>
<div class="top-bar blue-texture"></div>
<div id="header">
<div id="panel">
{$welcomeblock}
</div>
<div class="logo" >
<img src="{$theme['logo']}" alt="{$mybb- >settings['bbname']}" title="{$mybb->settings['bbname']}" />
</div>
<hr class="hidden" />
</div>
</div>
</div>
<div id="container">
<div class="bg-img">
</div>
<hr class="hidden" />
<div class="menu blue-texture">
<span class="search">
<form action="search.php" method="post">
<input type="hidden" name="action" value="do_search" />
<input type="hidden" name="postthread" value="1" />
<input type="hidden" name="forums" value="all" />
<input type="hidden" name="showresults" value="threads" />
<input type="text" name="keywords" value="search..." onfocus="if(this.value == 'search...') { this.value = ''; }" onblur="if(this.value=='') { this.value='search...'; }" size="22" />
<input type="submit" value="Go" class="search-button" title="Search the forums" />
</form>
</span>
<ul>
<li>Home</li>
<li>Tournaments</li>
</ul>
</div>
There is the complete code on how I have developed this. However, the problem is mainly in the CSS.
#header {
padding: 60px 0 85px;
height: 56px;
text-align: left;
position: relative;
}
#panel {
background: rgba(0,0,0,0.4);
color: #fff;
border: 1px solid #07090b;
border-radius: 6px;
position: absolute;
top:0;
margin-top: 0px;
right: 0;
padding-top: 4px;
font-size: 12px;
padding-right: 12px;
padding-left: 12px;
height: 130px;
}
.menu {
border-radius: 6px;
-webkit-border-radius: 6px;
border: 1px solid #174d7b!important;
height: 50px;
}
I can't find a way to fix the problem however, because there is no way to add position:relative; and make the navigation links still work as they are intended to.
Without actual link or a working snippet it would be hard to find the issue, but please try this css that may solve your problem:
.menu { width: 100%; }
.menu ul li a { display: inline-block; width: auto; float: left; }
Hope this helps

<center> tags will only center text but not image

I'm trying to center a <div> element containing both text and image using <center> tags, but for some reason it only applies on the text and not the image.
HTML:
<body>
<h1 align="center">Search For a Member</h1>
<br>
<br>
<form action="SearchController" method="get">
Enter the member's first name: <input type="text" style="width: 18em;" name="searchBox">
<input style="width:6em;" type="submit" value="Search">
<input style="width:6em;padding-left:7px;" type="submit" value="Back">
</form>
<center>
<div class="profile">
<img style="float:left;" src="default.jpg"height=100 width=100>
First Name
<br>
Last Name
<br>
</div>
</center>
</body>
CSS:
<style>
body {
background-color: #BCD2EE;
margin-left: 20%;
margin-right: 20%;
border: 1px outset #4876FF;
border-width: 5px;
padding: 10px 10px 30px 10px;
}
.profile {
overflow: hidden;
padding-top: 30px;
}
</style>
But if you'll try it, you'll see that only the text "First Name" and "Last Name" gets centered but not the picture. (I know you won't be able to see the picture default.jpg, but it will show you where the image would be).
Why won't the picture get centered? is it because of the float:left; property, which excludes the picture from the <center> tag?
If so, how can it be fixed?
<img style="float:left;"
You shouldn't have style="float:left;"
Remove that, and also add a line break <br> after the img tag
http://jsfiddle.net/jn8zgszy/
Remove float:left inline styling from img tag
Change:
<img style="float:left;" src="default.jpg"height=100 width=100>
To:
<img src="default.jpg" height="100" width="100"><br />
JSFiddle Demo
An alternative idea without the deprecated <center> tag, external CSS and tweaked form elements.
Centering is done via .wrap { display: table; margin: 0 auto; }
Have a jsBin example!
HTML
<div class="wrap">
<form action="SearchController" method="get">
<legend>Search For a Member</legend>
<label for="firstName">Enter the member's first name:</label>
<input name="searchBox" id="firstName" type="text">
<button type="submit">Search</button>
<button type="submit">Back</button>
</form>
<div class="profile">
<img src="http://www.placehold.it/100" />
<dl>
<dt>First Name</dt>
<dd>Greg</dd>
<dt>Last Name</dt>
<dd>Norman</dd>
</dl>
</div>
</div>
CSS
* {
margin: 0;
padding: 0;
}
.wrap {
display: table;
margin: 0 auto;
}
form {
padding: 10px;
}
legend {
margin: 20px auto;
font-weight: bold;
font-size: 1.4em;
display: table;
}
.profile img {
margin: 10px 0 10px;
}
.profile dt {
font-weight: bold;
}
.profile dd {
padding: 10px 0;
}
If you wanted the Image and those text to be center and one below the other then you could simple give text-align:center; to your .profile
.profile{
text-align:center;
}