I'm not a UI expert and attempting to achieve the below structure with html. the image is pretty much self explanatory of what i am after.
so far i have tried a few things but was unsuccessful and i have posted my mediocre attempt below. any help would be greatly appreciated.
<style>
.field-wrapper{
}
.input-control-container
{
}
.validation-message-container
{
}
.help-icon-container
{
}
.field-description-container
{
}
</style>
<div class="filed-wrapper">
<div class="field-label-container">
#Html.LabelFor(m => m.Email)
</div>
<div class="input-control-container">
#Html.TextBoxFor(m => m.Email)
<div class="field-description-container">
Here goes the description
</div>
</div>
<div class="validation-message-container">
#Html.ValidationMessageFor(m => m.Email)
</div>
<div class="help-icon-container">
<img src="/help-icon.png" /> <!--help popup handle by JavaScript--->
</div>
Alright, I whipped up a quick example of how to do this on JSFiddle.
HTML
<div class="FormElement">
<div>
<label for="test">Feild Label</label>
<input type="text" id="test" name="test" placeholder="Feild Input" />
<i class="fa fa-question">Icon</i>
</div>
<p>
Some description text here
</p>
</div>
All I do is set all the objects in the sub-div of .FormElement to display: inline-block, and set their width to all be ~33% of the page. Then, I can align the text of the label to be near the center, and have a <p> at the bottom span the full width.
CSS
.FormElement label,
.FormElement input,
.FormElement i.fa
{
display: inline-block;
width: 32%;
}
.FormElement label
{
text-align: right;
padding: 0 0 10px 0;
}
.FormElement p
{
text-align: center;
}
Note
The fa fa-question in the <i> is an example FontAwesome icon, so don't be thrown off by that.
Here's how I might go about it:
.field-outer {
display: table;
text-align: center;
margin: 20px auto;
}
.field-wrapper {
display: table-row;
text-align: center;
background: pink;
}
.field-wrapper > div {
display: table-cell;
vertical-align: middle;
padding: 6px 8px;
}
.input-control-container,
.field-label-container {
text-align: right;
}
.help-icon-container {
text-align: left;
min-width: 40px;
}
.help-icon-container img {
display: block;
}
<div class="field-outer">
<div class="field-wrapper">
<div class="field-label-container">
<label for="blah">Label</label>
</div>
<div class="input-control-container">
<textarea id="blah">Textarea</textarea>
</div>
<div class="help-icon-container">
<img src="http://placehold.it/40x40" />
<!--help popup handle by JavaScript--->
</div>
</div>
</div>
<div class="field-description-container">Here goes the description</div>
<div class="validation-message-container">#Html.ValidationMessageFor(m => m.Email)</div>
If you don't know the width of your container or want it to auto, you can use display: inline-block;.
Check this layout:
body {
text-align: center;
}
body * { box-sizing: border-box; }
.wrapper, .label-wrap, .input-wrap, .opt-wrap {
display: inline-block;
vertical-align: top;
padding: 5px 10px;
border: 1px solid #ddd;
}
.input-wrap {
width: 240px;
text-align: left;
}
.input-wrap input {
width: 100%;
display: block;
margin-bottom: 10px;
}
p {
padding: 0;
margin: 0;
}
<div class="wrapper">
<div class="label-wrap">
<span>Lorem ipsum</span>
</div>
<div class="input-wrap">
<input type="text" placeholder="Write here...">
<p>Lorem ipsum dolor sit amet</p>
</div>
<div class="opt-wrap">
<span>?</span>
</div>
</div>
Related
Given I have the html and css in the snippet below the question, how can I vertically centre the login view no matter what screen height is?
I have tried this for the .login-layout__positioner class:
.login-layout__positioner {
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 42%;
transform: translateY(-42%);
}
But this does not centre well in large screen heights?
Is there a better way?
body {
height: 100%;
background-color: #f7f7f4;
}
.app-layout__body {
height: 100vh;
display: flex;
flex-direction: column;
}
.app-layout__container {
flex: 1 0 auto;
}
.banner__container {
background-color: #fff
}
.banner__top {
padding-top: 15px;
}
.login-layout__container {
background-color: #f7f7f4;
width: 100%;
}
.login-layout__positioner {
text-align: center;
margin: auto;
}
footer {
background-color: #0065bd;
}
a {
color: #fff;
}
ul {
list-style: none;
margin-left: 0;
}
li {
display: inline;
}
.form__group {
background-color: #fff;
}
<body>
<div id="root">
<div class="main-content">
<div class="app-layout__body">
<div class="app-layout__container">
<div class="banner__container">
<div class="banner__top">
<div>
<div>
<h2>Banner</h2></div>
</div>
</div>
</div>
<div class="login-layout__container">
<div class="login-layout__positioner">
<div class="form__group">
<div>
<form>
<div class="login__container">
<div class="login__wrapper">
<div>
<div>
<div class="login__form__elements">
<div>
<div>
<h2 class="">Sign In</h2></div>
</div>
<div>
<div>
<div>
<label for="email" id="email-label" class="label__default label__strong label__double-margin">Email</label>
<div>
<input type="text" autocomplete="off" class="input__default form-control" id="email" name="email" aria-invalid="false" aria-describedby="email-error" value="">
</div>
<div id="email-error" aria-hidden="true" role="alert"></div>
</div>
</div>
</div>
<div>
<div>
<div>
<label for="password" id="password-label">Password</label>
<div>
<input type="password" autocomplete="off" id="password" name="password" aria-invalid="false" aria-describedby="password-error" value="">
</div>
<div id="password-error" aria-hidden="true" role="alert"></div>
</div>
</div>
</div>
<div>
<div><a to="/">Forgotten your password?</a></div>
<div>
<button type="submit">LOGIN</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<footer>
<div>
<div>
<div>
<ul>
<li><a target="_blank" href="/static/about">About</a></li>
<li><a target="_blank" href="/static/accessibility">Accessibility</a></li>
<li><a target="_blank" href="/static/cookies">Cookies</a></li>
<li><a target="_blank" href="/static/privacy">Privacy</a></li>
</ul>
</div>
</div>
</div>
</footer>
</div>
</div>
</div>
</body>
When it comes to centering something both vertically and horizontally I like to use css flex. Adding it to the parent container surrounding the element you wish to center will cause it to flex in all screen dimensions and heights. Justify-content centers it horizontally and align-items centers it vertically. Here is a helpful guide to learn more about flex:https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.parent-container{
width:100vw;
height:100vh;
background-color:black;
display:flex;
justify-content:center;
align-items:center;
}
.child{
width:50%;
background-color:white;
text-align:center;
}
<div class="parent-container">
<div class="child">
<h1>Centered</h1>
</div><!-- child -->
</div><!-- parent-container -->
Flexbox and grid work great for this, the difference being that grid is said to be 2 dimensional whereas flexbox is 1 dimensional. See MDN's Relationship of flexbox to other layout methods. BTW: If you want a sticky footer add min-height: 100vh; to your container.
Both Ron and Jeh's answer are correct. Though I'm wondering why do you have so many container wrappers then if you can just use certain wrappers to display your entire login form, banner and footer.
Here's my template for my custom login forms.
You will noticed that I use calc on height to differentiate the height of banner and footer and then less it to the height of your .section-login container, in which it will automatically adjusted the height no matter what the browser height does. And I declared min-height just to avoid overlaying above to each container wrapper.
Hope this helps.
.login {
background: pink;
margin: 0;
padding: 0;
}
.body-wrapper {
background: white;
width: 100%;
height: 100vh;
}
.hero-wrapper,
.globalfooter {
background: #CCC;
text-align: center;
}
.hero-wrapper {
line-height: 200px; /* just for the text v-alignment only */
height: 200px;
}
.globalfooter {
line-height: 100px; /* just for the text v-alignment only */
height: 100px;
}
.section-login {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #EEE;
min-height: calc(100% - (200px + 100px));
padding: 30px;
box-sizing: border-box;
}
.help-text-wrapper {
font: 300 12px sans-serif;
color: red;
text-align: center;
margin: 15px 0 0;
}
.help-text-wrapper.hidden {
/* Remove comment to enable
display: none; */
}
h1 {
font: 600 24px sans-serif;
text-align: center;
text-transform: uppercase;
margin: 0 0 15px;
}
form {
background: #FFF;
font: 300 12px sans-serif;
text-transform: uppercase;
width: 260px;
padding: 30px;
box-shadow: 0 0 5px 0 rgba(0,0,0,0.50);
box-sizing: border-box;
border-radius: 3px;
}
form > fieldset {
margin: 0 0 15px;
padding: 0;
border: 0;
}
form > fieldset label:first-child {
display: block;
margin-bottom: 15px;
}
form input {
display: block;
width: 100%;
height: 30px;
margin: 5px 0;
padding: 6px;
box-sizing: border-box;
}
form button {
display: block;
background: #888;
color: #FFF;
text-transform: uppercase;
height: 30px;
margin: auto;
padding: 7px 15px;
border: 0;
cursor: pointer;
}
<body class="login page">
<div class="body-wrapper">
<header class="hero-wrapper">
Banner
</header>
<section class="section-login">
<h1>Sign In</h1>
<form action="" method="post">
<fieldset>
<label for="username">
Username
<input type="text" id="username" value="" placeholder="Username" autofocus>
</label>
<label for="password">
Password
<input type="password" id="password" value="" placeholder="Password">
</label>
</fieldset>
<button type="submit">Login / Sign In</button>
</form>
<div class="help-text-wrapper hidden">
Something around here after fallback.
</div>
</section>
<footer class="globalfooter">
Footer
</footer>
</div>
</body>
Just change some class properties which I wrote down:
.login-layout__positioner {
display: flex;
align-items: center;
justify-content: center;
}
.form__group {
background-color: transparent;
}
a {
color: #333;
}
footer a {
color: #fff;
}
I've been struggling to have my login box to the right of my header near the top right of the page. I would like the header and everything in blue to be next to each other with the login box in the top right still in the blue, with the rest of the page in white. Through my CSS using the .left and .right div tags I was not able to accomplish that.
* {
color: #000000;
}
body {
margin: 0px 150px 0px 150px;
color: #ffffff;
}
div.header {
background-color: #b3d9ff;
width: 100%;
margin: 10px auto 10px auto;
}
div.page {
color: #e6f2ff;
}
img {
padding: 10px;
}
.left {
width: 200px;
float: left;
}
.right {
margin-left: 2200px;
}
<div id="page">
<div class="header">
<div id="left">
<h1>Welcome to the best blog in the world!</h1>
<h6>I know you're jealous...</h6>
</div>
<div id="right">
<fieldset>
<legend>
<h4>Already a member? Login here:</h4>
</legend>
<form method="GET" action="http://csis.svsu.edu/~cmdewey/thankyou.html">
Login name:
<input type="text" id="uname" name="uname"><br><br> Password:
<input type="password" id="secretpass" name="secretpass"><br><br>
<input type="submit" value="Submit">
</form>
</fieldset>
</div>
</div>
I refactored the html snd css because you were using class selectors in html instead of id selectors.
* {
color: #000000;
}
body {
color: #ffffff;
}
.header {
overflow: hidden;
background-color: #b3d9ff;
width: 100%;
margin: 10px auto 10px auto;
}
div.page {
color: #e6f2ff;
}
img {
padding: 10px;
}
.left {
width: 50%;
float: left;
}
.right {
width: 50%;
float: right;
}
<div id="page">
<div class="header">
<div class="left">
<h1>Welcome to the best blog in the world!</h1>
<h6>I know you're jealous...</h6></div>
<div class="right">
<fieldset><legend>
<h4>Already a member? Login here:</h4></legend>
<form method="GET" action="http://csis.svsu.edu/~cmdewey/thankyou.html">
Login name:
<input type="text" id="uname" name="uname"><br><br>
Password:
<input type="password" id="secretpass" name="secretpass"><br><br>
<input type="submit" value="Submit">
</form></fieldset></div></div>
enter image description here
Just add this to your header class : display:inline-flex
so change it like this :
div.header {
background-color: #b3d9ff;
width: 100%;
margin: 10px auto 10px auto;
display:inline-flex;
}
https://jsfiddle.net/emilvr/rpqzvgwq/1/
Your code is Well,Just you have a few wrong :
1)you use ID in tag html but use . selector in css.
2)you dont need to margin-left: 2200px; in #right.
3)use overflow: auto; in .header.
4)use box-sizing: border-box; in #left and #right.
I Fix them ,I hope help you,
Full Code:
* {
color: #000000;
}
body {
color: #ffffff;
}
div.header {
background-color: #b3d9ff;
width: 100%;
overflow: auto;
}
#page {
color: #e6f2ff;
}
img {
padding: 10px;
}
#left {
width: 50%;
float: left;
box-sizing: border-box;
}
#right{
width: 50%;
float: right;
box-sizing: border-box;
}
<div id="page">
<div class="header">
<div id="left">
<h1>Welcome to the best blog in the world!</h1>
<h6>I know you're jealous...</h6>
</div>
<div id="right">
<fieldset>
<legend>
<h4>Already a member? Login here:</h4>
</legend>
<form method="GET" action="http://csis.svsu.edu/~cmdewey/thankyou.html">
Login name:
<input type="text" id="uname" name="uname"><br><br>
Password:
<input type="password" id="secretpass" name="secretpass"><br><br>
<input type="submit" value="Submit">
</form>
</fieldset>
</div>
</div>
</div>
I'm trying to use images as checkboxes in a grid layout, but the images won't show and I'm at a loss. Here is the relevant css and html. I have double checked the image address as this has been an issue in many other posts here, but it is stored at the address being accessed.
Any help is appreciated.
body{
width: 100vw;
height: 100vh;
margin-left: auto;
margin-right: auto;
}
.container {
width: 100%;
height: 100%;
margin: 0;
}
.jumbotron {
width: 100%;
float: left;
}
.four {
width: 32vw;
float: left;
margin-left: 2%;
/*background-color: #95a5a6;*/
}
.row {
width: 100vw;
height: 20vh;
clear: both;
padding: 0px;
margin: 0px;
}
.buttonLabel {
cursor: pointer;
}
.button input[type="checkbox"] {
display: none;
}
.button input[type="checkbox"] + label {
width: 32vw;
height: 20vh;
display: inline-block;
}
#accomLabel {
background: url('../img/shelter.png') no-repeat;
}
<div class="container">
<div class="row jumbotron heading">
<h1 style="text-align: center;">foo</h1>
<h3 style="text-align: center;">bar</h3>
</div>
<form method="post" id="services_form">
<div class="row">
<div class="four">
<div class="button">
<input type="checkbox" id="accomButton"></input>
<label class="buttonLabel" for="accomButton" id="accomLabel"></label>
</div>
</div>
<div class="four">
<div class="button">
<input type="checkbox" id="foodButton"></input>
<label class="buttonLabel" for="foodButton" id="foodLabel"></label>
</div>
</div>
<div class="four">
<div class="button">
<input type="checkbox" id="medicalButton"> </input>
<label class="buttonLabel" for="medicalButton" id="medicalLabel"></label>
</div>
</div>
</div>
</form>
</div>
Seems fine, although you don't need input closing tags (</input>). Here's a demo with placehold.it image:
body {
width: 100vw;
height: 100vh;
margin-left: auto;
margin-right: auto;
}
.container {
width: 100%;
height: 100%;
margin: 0;
}
.jumbotron {
width: 100%;
float: left;
}
.four {
width: 32vw;
float: left;
margin-left: 2%;
/*background-color: #95a5a6;*/
}
.row {
width: 100vw;
height: 20vh;
clear: both;
padding: 0px;
margin: 0px;
}
.buttonLabel {
cursor: pointer;
}
.button input[type="checkbox"] {
display: none;
}
.button input[type="checkbox"] + label {
width: 32vw;
height: 20vh;
display: inline-block;
}
#accomLabel {
background: url('http://placehold.it/54x54') no-repeat;
}
<div class="container">
<div class="row jumbotron heading">
<h1 style="text-align: center;">foo</h1>
<h3 style="text-align: center;">bar</h3>
</div>
<form method="post" id="services_form">
<div class="row">
<div class="four">
<div class="button">
<input type="checkbox" id="accomButton">
<label class="buttonLabel" for="accomButton" id="accomLabel"></label>
</div>
</div>
<div class="four">
<div class="button">
<input type="checkbox" id="foodButton">
<label class="buttonLabel" for="foodButton" id="foodLabel"></label>
</div>
</div>
<div class="four">
<div class="button">
<input type="checkbox" id="medicalButton">
<label class="buttonLabel" for="medicalButton" id="medicalLabel"></label>
</div>
</div>
</div>
</form>
</div>
I have three adjacent divs of equal width and I'm trying to figure out why the contents of the first, which has an additional button inside, pushes down the other two divs. Is it a display issue? I'd rather understand the cause before trying to manually top-align them. Thanks!
Here is my markup:
<div id="events-cont">
<div class="events-row">
<div class="event-card">
<img src="http://placeholdit.imgix.net/~text?txtsize=36&txt=Event%20Photo&w=382&h=275" />
<div class="event-card-info">
<h1>Event title</h1>
<h2>Event date</h2>
<h2>Event venue</h2>
<p>
Event description
Learn More
</p>
<a class="tickets-button" href="#">Buy Tickets</a>
</div>
</div>
<div class="event-card">
<img src="http://placeholdit.imgix.net/~text?txtsize=36&txt=Event%20Photo&w=382&h=275" />
<div class="event-card-info">
<h1>Event title</h1>
<h2>Event date</h2>
<h2>Event venue</h2>
<p>
Event description
Learn More
</p>
</div>
</div>
<div class="event-card">
<img src="http://placeholdit.imgix.net/~text?txtsize=36&txt=Event%20Photo&w=382&h=275" />
<div class="event-card-info">
<h1>Event title</h1>
<h2>Event date</h2>
<h2>Event venue</h2>
<p>
Event description
Learn More
</p>
</div>
</div>
</div>
</div>
CSS:
* {
box-sizing: border-box;
}
#events-cont {
padding: 30px 0;
.events-row {
.event-card {
padding: 0 15px;
display: inline-block;
width: 33%;
img {
display: block;
width: 100%;
}
.event-card-info {
padding: 15px;
min-height: 300px;
text-align: left;
background: #ededed;
.tickets-button {
display: inline-block;
margin: 30px;
padding: 10px 30px;
font-size: 1.8em;
}
}
}
}
}
Demo: http://codepen.io/ourcore/pen/eBWxLz
Your .event-cards are inline-block so they are by default vertically aligned to the baseline.
Use vertical-align: top on the .event-card class:
.event-card {
vertical-align: top;
}
http://codepen.io/anon/pen/ZBKwPO
Because the default value of vertical-align is baseline. This should fix it.
.event-card {
...
vertical-align: top;
}
I would float the divs. Update this part of your CSS:
#events-cont .events-row .event-card {
padding: 0 15px;
display: inline-block;
width: 33%;
float: left; //added to stop the divs from being pushed down.
}
could someone help me with an example how to accomplish following layout? Is tables the best for this?
https://gyazo.com/80a2f66d280c480c1e6e70637959b271
I do not want to hardcode the width of the elements because I need it to be responsive aswell, thats why I am having a hard time..
So basicly I need it centered but not text-align centered. Appreciate all the help I could get.
Don't use tables, this makes it hard to optimize the website for mobile devices. Here's what I would do:
body {
font-family: Arial, sans-serif;
color: #444444;
}
.info {
border: 1px solid #bbbbbb;
border-width: 1px 0;
padding: 10px;
}
.row {
line-height: 30px;
padding: 10px;
}
.label {
display: inline-block;
width: 30%; /* You may want to adjust this property */
margin: 0 10px;
text-align: right;
font-size: 95%;
color: #888888;
}
button {
border: none;
background-color: #43CEAD;
border-radius: 3px;
padding: 4px 10px;
color: white;
font-size: 90%;
}
.right {
float: right;
}
<div class="info">
<div class="row">
<span class="label">Name:</span>
John Doe
<button class="right">Edit</button>
</div>
<div class="row">
<span class="label">Password:</span>
********
<button class="right">Edit</button>
</div>
<div class="row">
<span class="label">Animus Heart ID:</span>
B0 23459332
<button class="right">Edit</button>
</div>
<div class="row">
<span class="label">E-mail:</span>
john#doe.com
<button class="right">Edit</button>
</div>
</div>
Why tables? You can set div width in percent, isn't it?
.col--first {
width: 40%;
float: left;
text-align: right;
}
.col--second {
margin-left: 1%;
width: 59%;
float: left;
}
.col--second:after {
content: '';
display: table;
clear: both;
}
.right {
float: right;
}
<div>
<div class="col--first">Name:</div>
<div class="col--second">John
<button class="right">Edit</button>
</div>
<div class="col--first">Password:</div>
<div class="col--second">******
<button class="right">Edit</button>
</div>
</div>
Have a look at responsive tables:
.table {
display: table;
}
.table > .row {
display: table-row;
}
.table > .row > .cell {
display: table-cell;
}
<div class="table">
<div class="row">
<div class="cell">
First
</div>
<div class="cell">
Second
</div>
<div class="cell">
Third
</div>
</div>
</div>
#img {
width: 100%;
margin: 0 auto;
}
Width can be changed to reflect the desired size of the image, but this will center the image based on the parent element's size by dividing the two margins equally on the left and right.