I am no good in wrinting UIs in pure html... Right now I am trying to create a simple login page in pure html in css, but somehow I cannot get the Login button from here https://jsfiddle.net/2oxz5oja/ to be centered.
p {
display: table-row;
text-align: center;
}
Does this style work for table-row elements?
Could someone here give me an advice?
Sorry I'm having some issues with my Fiddle. So I've copy/pasted it here.
Try this:
HTML
<h3>Login here</h3>
<div id="loginMenu" class="mainDiv">
<form id="login-form" name="login-form" method="post" action="/konferencje-web/login.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="login-form" value="login-form" />
<p>
<label for="login-form:login" class="input-form">Login:</label>
<input id="login-form:login" type="text" name="login-form:login" class="input-form" />
</p>
<p>
<label for="login-form:password" class="input-form">Password:</label>
<input id="login-form:password" type="password" name="login-form:password" value="" class="input-form" />
</p>
<p>
<input id="login-form:button" class = "login" type="submit" name="login-form:button" value="Login" />
</p>
<p>
Info page
</p>
</form>
</div>
</html>
CSS
body {
background-color: #6B2424;
}
form {
display: table;
}
input {
display: table-cell;
margin: 0 auto;
}
label {
display: table-cell;
}
p {
display: table-row;
text-align: center;
}
li {
list-style-type: none;
line-height: 150%;
}
a {
color: #000000;
line-height: 30px;
vertical-align: middle;
text-align: center;
}
h1, h3 {
color: wheat;
font-size: 18px;
font-weight: bold;
text-align: center;
}
td {
text-align: center;
}
select {
min-width: 150px;
}
#login-form {
margin:0 auto;
text-align: center;
width: 50%
}
.mainDiv {
text-align: center;
background-color: bisque;
width: 500px;
border:2px solid;
border-radius:25px;
line-height: 30px;
vertical-align: middle;
margin:0 auto;
}
.login
{
position: relative;
left: 120px;
}
}
Related
I'm designing an online clothing store, and on the product's page I want the product info (on the right) to align with the center of the image (on the left) while both of the divs are centered with the page. However, it seems that no matter what I do, the product info is always pushed down to the bottom corner of the image. It works when the image is removed completely, but unless that happens no formatting in CSS will affect the product-info div.
I've tried floating the elements to the left but that negates the text-align that keeps them centered, and any padding, margin, or dimension changes I make to the product-info only adds to the bottom of the div rather than shifting it up. There's probably something obvious that I'm overlooking, but I've been working on this problem for so long and just can't seem to find a fix.
Can someone please help me?
> Screenshot of how it looks <
* {
margin: 0px;
padding: 0px;
}
.product {
text-align: center;
}
.product-view {
top: 40px;
padding: 10px;
margin: 10px;
display: inline-block;
}
#product-image {
width: 400px;
height: 40%;
min-width: 40%;
min-height: 40%;
padding: 20px;
}
.product-info {
display: inline-block;
padding: 10px;
margin: 10px;
}
#product-name {
font-size: 25px;
text-transform: uppercase;
text-align: left;
}
#product-price {
font-size: 20px;
padding: 20px 0px;
text-align: left;
}
.product-info hr {
width: 278px;
opacity: 0.4;
}
#product-sizes {
padding: 5px;
text-align: center;
text-transform: uppercase;
width: fit-content;
}
#size-radio-btn {
display: inline-block;
width: 40px;
height: 40px;
text-align: center;
font-size: 15px;
border: 1px solid black;
margin: 5px 10px;
margin-left: 5px;
margin-right: 5px;
line-height: 40px;
color: black;
cursor: pointer;
}
#add-to-cart {
width: 278px;
height: 40px;
margin: 0 5px;
cursor: pointer;
background-color: black;
color: white;
text-transform: uppercase;
font-size: 15px;
float: left;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<div class="content">
<div class="product">
<div class="product-view">
<img id="product-image" src="/Media/hoodieblack.png">
</div>
<div class="product-info">
<div id="product-name">
<h3>Hoodie - Black</h3>
</div>
<div id="product-price">
<p>$80.00</p>
</div>
<hr>
<div id="product-sizes">
<label for="size-select">Size</label>
<div id="size-select">
<input type="radio" name="size" value="s" hidden id="s-size">
<label for="s-size" id="size-radio-btn">S</label>
<input type="radio" name="size" value="m" hidden id="m-size">
<label for="m-size" id="size-radio-btn">M</label>
<input type="radio" name="size" value="l" hidden id="l-size">
<label for="l-size" id="size-radio-btn">L</label>
<input type="radio" name="size" value="xl" hidden id="xl-size">
<label for="xl-size" id="size-radio-btn">XL</label>
<input type="radio" name="size" value="xxl" hidden id="xxl-size">
<label for="xxl-size" id="size-radio-btn">XXL</label>
</div>
</div>
<button type="button" id="add-to-cart">Add to Cart</button>
</div>
</div>
</div>
</body>
</html>
Simply add display: flex; to the main parent, in this case, .product. Then you can use align-items: center; to get them in line with one another.
You can also add max-width: 100%; to the image so it resizes accordingly.
* {
margin: 0px;
padding: 0px;
}
.product {
text-align: center;
}
.product-view {
top: 40px;
padding: 10px;
margin: 10px;
display: inline-block;
}
#product-image {
width: 400px;
height: 40%;
min-width: 40%;
min-height: 40%;
padding: 20px;
}
.product-info {
display: inline-block;
padding: 10px;
margin: 10px;
}
#product-name {
font-size: 25px;
text-transform: uppercase;
text-align: left;
}
#product-price {
font-size: 20px;
padding: 20px 0px;
text-align: left;
}
.product-info hr {
width: 278px;
opacity: 0.4;
}
#product-sizes {
padding: 5px;
text-align: center;
text-transform: uppercase;
width: fit-content;
}
#size-radio-btn {
display: inline-block;
width: 40px;
height: 40px;
text-align: center;
font-size: 15px;
border: 1px solid black;
margin: 5px 10px;
margin-left: 5px;
margin-right: 5px;
line-height: 40px;
color: black;
cursor: pointer;
}
#add-to-cart {
width: 278px;
height: 40px;
margin: 0 5px;
cursor: pointer;
background-color: black;
color: white;
text-transform: uppercase;
font-size: 15px;
}
.product {
display: flex;
align-items: center;
justify-content: center;
}
#product-image {
max-width: 100%;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<div class="content">
<div class="product">
<div class="product-view">
<img id="product-image" src="https://dummyimage.com/800/000/fff">
</div>
<div class="product-info">
<div id="product-name">
<h3>Hoodie - Black</h3>
</div>
<div id="product-price">
<p>$80.00</p>
</div>
<hr>
<div id="product-sizes">
<label for="size-select">Size</label>
<div id="size-select">
<input type="radio" name="size" value="s" hidden id="s-size">
<label for="s-size" id="size-radio-btn">S</label>
<input type="radio" name="size" value="m" hidden id="m-size">
<label for="m-size" id="size-radio-btn">M</label>
<input type="radio" name="size" value="l" hidden id="l-size">
<label for="l-size" id="size-radio-btn">L</label>
<input type="radio" name="size" value="xl" hidden id="xl-size">
<label for="xl-size" id="size-radio-btn">XL</label>
<input type="radio" name="size" value="xxl" hidden id="xxl-size">
<label for="xxl-size" id="size-radio-btn">XXL</label>
</div>
</div>
<button type="button" id="add-to-cart">Add to Cart</button>
</div>
</div>
</div>
</body>
</html>
I'm making an email form where people can submit their emails and be part of an email list, in order to do this I have made an input and a button that go side by side. The issue that I am getting is that even though the button and inputs are the exact same height, and should be aligned horizontally perfectly it instead has a pixel difference with the button being a pixel higher than the input. How can I fix this?
#form {
display flex;
align-items: center;
justify-content: center;
flex-direction: row;
}
.email-form {
padding: 60px;
margin-top: 85px;
color: #fff;
background: #000;
text-align: center;
}
.form input {
width: 300px;
height: 30px;
margin: 0;
display: inline;
outline: 0 none;
}
.form button {
height: 30px;
width: 90px;
margin: 0;
background: #707070;
color: #fff;
font-weight: 700;
text-transform: uppercase;
text-align: center;
border: none;
cursor: pointer;
display: inline;
outline: 0 none;
}
<div class="form">
<form action="" id="email">
<input type="email" placeholder="Email" /><button type="submit" class="submit"><p>Sign up</p></button>
</form>
</div>
If you change
<p>Sign up</p>
To
<div>Sign up</div>
Or just
Sign up
It should work.
There's a bunch of margin settings on the <p> element that are overflowing and messing up your alignment.
Just remove p tag around the Sign up text.
<button type="submit" class="submit">Sign up</button>
#form {
display flex;
align-items: center;
justify-content: center;
flex-direction: row;
}
.email-form {
padding: 60px;
margin-top: 85px;
color: #fff;
background: #000;
text-align: center;
}
.form input {
width: 300px;
height: 30px;
margin: 0;
display: inline;
outline: 0 none;
}
.form button {
height: 30px;
width: 90px;
margin: 0;
background: #707070;
color: #fff;
font-weight: 700;
text-transform: uppercase;
text-align: center;
border: none;
cursor: pointer;
display: inline;
outline: 0 none;
}
<div class="form">
<form action="" id="email">
<input type="email" placeholder="Email" />
<button type="submit" class="submit">Sign up</button>
</form>
</div>
Okay, so maybe I'm not searching properly but I can't seem to find exactly what I'm looking for.
I have a form, let's say something like this:
div.some_form {}
div.some_form>span {
font-weight: bold;
position: relative;
text-align: left;
}
div.some_form>form {
text-align: center;
font-size: 16px;
width: 100%;
margin-left: auto;
margin-right: auto;
}
div.some_form>form>input.txtfield {
padding: 13px;
width: 25%;
}
.button {
background-color: #7AB55C;
border: none;
color: white;
text-align: center;
padding: 15px 32px;
}
<div class="some_form">
<form>
<span class="some_class">Some text</span>
<br>
<input type="text" class="txtfield" />
<input type="button" class="button" value="Submit" onclick="doSomething()" />
</form>
</div>
what I want it to do is pretty much keep the inputs centred (which I'm able to do), which is why everything is in a div, I used text-align: center to centre everything, but I want the span element to be stuck to the top left corner of the first input, which I can't seem to do properly.
I mean, I get it, but then once I resize the window, the span shoots off into space (i.e. the text field will expand at a lower rate than the span is, which is great because the text stays centred even with the button attached) and I can't seem to get it to just stick.
(also this seriously isn't homework, I'm just getting into CSS and this is really bothering me..)
any help is obviously very much appreciated!
Thanks in advance :)
Adding a display: block to your span will work. And remove the <br />. You have the class specification wrong. The <span> isn't a direct child there. So > doesn't work:
body {
text-align: center;
}
div.some_form span.some_class {
font-weight: bold;
position: relative;
text-align: left;
display: block;
padding: 0 4.5%;
}
div.some_form>form {
text-align: center;
font-size: 16px;
width: 100%;
margin-left: auto;
margin-right: auto;
}
div.some_form>form>input.txtfield {
padding: 13px;
width: 45%;
}
.button {
background-color: #7AB55C;
border: none;
color: white;
text-align: center;
padding: 15px 32px;
}
div.some_form {
display: inline-block;
}
<div class="some_form">
<form>
<span class="some_class">Some text</span>
<input type="text" class="txtfield" />
<input type="button" class="button" value="Submit" onclick="doSomething()" />
</form>
</div>
Preview
Here the answer hope it can help you
.container{
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-top: -100px;
margin-left: -150px;
}
.txtfield {
padding: 13px;
width: 25%;
}
.button {
background-color: #7AB55C;
border: none;
color: white;
text-align: center;
padding: 15px 32px;
}
<div class="some_form">
<form>
<div class="container">
<span class="some_class">Some text</span>
<div class="input_container">
<input type="text" class="txtfield" />
<input type="submit" class="button" value="Submit" onclick="doSomething()" />
</div>
</div>
</form>
</div>
I have an authentication panel that looks as follow:
As you can see the red box is displayed to small.
The code behind the source:
HTML
<!-- Add your site or application content here -->
<div class="container">
<div class="message">
<h2 class="title">AUTHENTICATION</h2>
<p class="info">Please sign in with username and password.</p>
<br />
<br />
<div class="ui red message error">Wrong username or password.</div>
</div>
<div class="sign-in">
<form class="ui form">
<div class="field ui big left icon input">
<input type="text" placeholder="Username">
<i class="user icon"></i>
</div>
<div class="field ui big left icon input">
<input type="password" placeholder="Password">
<i class="lock icon"></i>
</div>
<div class="fluid ui blue button">Sign In</div>
</form>
</div>
</div>
CSS
.container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
}
.message {
display: block;
width: 20%;
height: 25%;
background: #bbd0e6;
font-family: 'Montserrat', sans-serif;
margin-right: 6px;
}
.message, h2 {
color: #FFFFFF;
padding-left: 5px;
padding-top: 5px;
}
.message, .info {
color: #FFFFFF;
padding-left: 5px;
padding-top: 5px;
}
.message, .error {
}
.sign-in {
display: flex;
align-items: center;
width: 15%;
height: 25%;
margin-left: 3px;
}
I tried to set the width of the red box to
.message, .error {
width: 80%;
}
After it changes to:
It seems to be, that the width of the red box is proportional to whole screen not to the AUTHENTICATION box.
How can I determine the width to be proportional to the AUTHENTICATION box?
Try this instead:
.message > error {
width: 80%;
}
When you use , when assigning a style in CSS, you're telling the browser to assign that style to a list of things. Example from your code:
.message {
display: block;
width: 20%;
height: 25%;
background: #bbd0e6;
font-family: 'Montserrat', sans-serif;
margin-right: 6px;
}
.message, h2 {
color: #FFFFFF;
padding-left: 5px;
padding-top: 5px;
}
.message, .info {
color: #FFFFFF;
padding-left: 5px;
padding-top: 5px;
}
That snip defines .message, then redefines it two more times, while also defining h2 and .info. I assume in all cases you're actually trying to get at the children of .message (but I could be wrong). Follow the link for more information: http://www.w3schools.com/css/css_combinators.asp
I solved the problem with:
.message {
display: block;
width: 20%;
height: 25%;
background: #bbd0e6;
font-family: 'Montserrat', sans-serif;
margin-right: 6px;
}
.message > h2 {
color: #FFFFFF;
padding-left: 5px;
padding-top: 5px;
}
.message > .info {
color: #FFFFFF;
padding-left: 5px;
padding-top: 5px;
}
.message > .error {
width: 80%;
}
Thanks everyone.
I can't figure out how to get a gap between
<div class="info">
<p>Location:</p>
<p>Dominion Theatre, W1T 7AQ</p>
</div>
and
<form>
<label>Name (Required)
<input type="text" placeholder="Name" required>
</label>
</form>
How would I go about doing it. I've tried using margin/padding without any luck?
HTML
<div class="bt fbCenter">
<div class="fb">
<div class="info">
<p>Event Starts:</p>
<p>25th December 2014 19:00</p>
</div>
<div class="info">
<p>Event Ends:</p>
<p>25th December 2014 21:00</p>
</div>
<div class="info">
<p>Location:</p>
<p>Dominion Theatre, W1T 7AQ</p>
</div>
<form>
<label>Name (Required)
<input type="text" placeholder="Name" required>
</label>
</form>
</div>
</div>
CSS
.bt input {
border: 1px solid #ccc;
color: rgb(60, 60, 60);
display: block;
width: 70%;
padding: 1em;
text-align: left;
margin-bottom: 2.5em;
}
.bt button {
width: 100%;
padding: 1.5em;
background-color: #1f1f1f;
color: #fff;
border: 0;
}
.bt button:hover {
background-color: #818181;
cursor:pointer;
}
.fbCenter {
text-align: center;
}
.bt .fb {
border: 1px solid #818181;
padding: 2em;
color: #585858;
display: inline-block;
text-align: left;
width: 75%;
}
.fb .info {
width: 100%;
margin-bottom: 1em;
}
.fb p {
float: left;
}
.fb p:nth-of-type(even) {
width: 80%;
}
.fb p:nth-of-type(odd) {
width: 20%;
}
.fb p.last {
width: 100%;
font-weight: 100;
}
Fiddle here.
Be aware of margin collapsing and float collapsing.
Add a marging to the top of the from and clear the floats in the info divs
.fb form{
margin-top:2em;}
.fb .info {
width: 100%;
margin-bottom: 1em;
clear:both;
}
.fb form{
margin-top:5em;}
.bt input {
border: 1px solid #ccc;
color: rgb(60, 60, 60);
display: block;
width: 70%;
padding: 1em;
text-align: left;
margin-bottom: 2.5em;
}
.bt button {
width: 100%;
padding: 1.5em;
background-color: #1f1f1f;
color: #fff;
border: 0;
}
.bt button:hover {
background-color: #818181;
cursor:pointer;
}
.fbCenter {
text-align: center;
}
.bt .fb {
border: 1px solid #818181;
padding: 2em;
color: #585858;
display: inline-block;
text-align: left;
width: 75%;
}
.fb .info {
width: 100%;
margin-bottom: 1em;
clear:both;
}
.fb p {
float: left;
}
.fb p:nth-of-type(even) {
width: 80%;
}
.fb p:nth-of-type(odd) {
width: 20%;
}
.fb p.last {
width: 100%;
font-weight: 100;
}
<div class="bt fbCenter">
<div class="fb">
<div class="info">
<p>Event Starts:</p>
<p>25th December 2014 19:00</p>
</div>
<div class="info">
<p>Event Ends:</p>
<p>25th December 2014 21:00</p>
</div>
<div class="info">
<p>Location:</p>
<p>Dominion Theatre, W1T 7AQ</p>
</div>
<form>
<label>Name (Required)
<input type="text" placeholder="Name" required>
</label>
</form>
</div>
</div>
Note that the margin on the top of the form needs to be bigger than the margin on the bottom of the .info class. This is due to Margin Collapsing (https://developer.mozilla.org/en-US/docs/Web/CSS/margin_collapsing & http://www.sitepoint.com/web-foundations/collapsing-margins/)
You should probably also become familiar with Clearfix, how it works, why and when it is needed.
I'm not a fan of float so here as an alterate version that utilises display:table, display:table-row and display:table-cell
You could create another class to insert between both of them like this example http://jsfiddle.net/2kkep4qs/8/
HTML
<div class="info">
<p>Location:</p>
<p>Dominion Theatre, W1T 7AQ</p>
</div>
<div class="bt-space"></div>
<form>
<label>Name (Required)
<input type="text" placeholder="Name" required>
</label>
</form>
CSS New class
.bt-space{padding:25px;}
you can do <hr> and color it white, or
you could always add an empty div between div and form:
<div class="info">
</div>