I created a simple component and when I created a flex container, items inside (for example suffix) are out the box, but only in Firefox. I use space-between in flex item, but item is out of the flex container. It works when I set height with of the Input, but that's what I don't want.
I created a CodePen here, because I can't use Sass here in a Stack Snippet.
Does anybody knows about this?
CodePen: https://codepen.io/ondrejko/pen/wvageWg
// Component local variables
$input-border-color: #D8DADC;
$input-border-disabled-color: #E8EAEC;
$input-text-gray: #979797;
$input-text-color: #457CCC;
$input-focus-color: #0284FF;
$input-border-radius: 8px;
$input-font-size: 16px;
$input-height: 40px;
// Base structure
.Input {
position: relative;
max-width: 200px;
}
// Input container for all elements
.Input__container {
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
height: $input-height;
background-color: #fff;
font-size: $input-font-size;
}
// Fake input, who replaces real input and is in front of input
.Input__fake-input {
position: absolute;
z-index: 1;
top: 0px;
left: 0px;
width: 100%;
height: inherit;
border-width: 1px;
border-style: solid;
border-color: $input-border-color;
border-image: none;
border-radius: $input-border-radius;
font-size: $input-font-size;
transition: all 0.15s ease-in-out 0s;
}
// Input text field for add text
.Input__field {
z-index: 2;
flex: 1 1 20%;
width: 100%;
height: 100%;
padding: 0px 12px;
border: 0;
color: $input-text-color;
background-color: transparent;
font-size: inherit;
-webkit-appearance: none;
&:focus {
outline: none;
&~.Input__fake-input {
outline: none;
border: 1px solid $input-focus-color;
}
}
}
// Input type PREFIX
.Input__prefix {
z-index: 3;
display: flex;
height: 100%;
align-items: center;
justify-content: center;
padding: 0px 0px 0px 10px;
color: $input-text-gray;
pointer-events: none;
}
// Input type SUFFIX
.Input__suffix {
z-index: 3;
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
height: 100%;
padding: 0px 10px 0px 0;
color: $input-text-gray;
}
// Input type ICON
.Input__icon {
position: relative;
z-index: 3;
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 48px;
height: calc(100% - 2px);
color: $input-text-gray;
padding: 0px 10px;
border-left: 1px solid $input-border-color;
cursor: pointer;
& img,
svg {
width: 25px;
}
}
// Input type CONTROLS
.Input__controls {
width: 72px;
height: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 0 0 10px;
&+.Input__fake-input {
width: calc(100% - 80px);
}
}
// Input type BUTTON
.Input__button {
width: 32px;
height: 32px;
background: red;
border-radius: 100px;
border: 0;
color: #fff;
padding: 0;
cursor: pointer;
& .Icon {
display: flex;
align-items: center;
justify-content: center;
}
& img,
svg {
max-width: 16px;
}
}
// Modificator --has-status
.Input--has-status {
position: relative;
}
.Input--has-status::after {
content: '';
position: absolute;
top: -4px;
right: -4px;
z-index: 3;
width: 10px;
height: 10px;
border-radius: 100%;
background: #1A73E8;
}
// --has-status types
.Input--has-status.success::after {
background: #37C9AD;
}
.Input--has-status.warning::after {
background: #FFB000;
}
// Modificator --is-invalid
.Input--is-invalid {
& .Input__fake-input {
border: 1px solid #FF0054; // tady barva bude z global variables
}
& .Input__field {
color: #FF0054; // tato barva bude z global variables
&:focus~.Input__fake-input {
border-color: #FF0054; // tady barva bude z global variables
}
}
}
// Modificator --is-disabled
.Input--is-disabled {
& .Input__fake-input {
background-color: $input-border-disabled-color;
color: #868C92;
cursor: not-allowed;
border: 1px solid $input-border-disabled-color;
}
& .Input__field {
color: #868C92;
cursor: not-allowed;
}
}
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,900&display=swap" rel="stylesheet">
<div class="container">
<form>
<div class="row">
<h1> Types</h1>
<h2>Input - default</h2>
<div class="Input">
<div class="Input__container">
<input class="Input__field" type="text" placeholder="Placeholder">
<div class="Input__fake-input"></div>
</div>
</div>
<h2>Input - prefix</h2>
<div class="Input">
<div class="Input__container">
<div class="Input__prefix">
<span class="Prefix">Prefix</span>
</div>
<input class="Input__field" type="text" placeholder="Placeholder" value="Lorem ipsum dolor">
<div class="Input__fake-input"></div>
</div>
</div>
<h2>Input - suffix</h2>
<div class="Input">
<div class="Input__container">
<input class="Input__field" type="text" placeholder="Placeholder" value="Lorem ipsum dolor">
<div class="Input__suffix">
Suffix
</div>
<div class="Input__fake-input"></div>
</div>
</div>
<h2>Input - icon</h2>
<div class="Input">
<div class="Input__container">
<input class="Input__field" type="text" placeholder="Placeholder">
<div class="Input__icon">
<img src="http://www.ondrejkonecny.cz/assets/svg/calculator.svg">
</div>
<div class="Input__fake-input"></div>
</div>
</div>
<br><br>
<h1>Modificators</h1>
<h2>Input - Load Success</h2>
<div class="Input Input--has-status success">
<div class="Input__container">
<input class="Input__field" type="text" placeholder="Placeholder">
<div class="Input__fake-input"></div>
</div>
</div>
<h2>Input - Load Warning</h2>
<div class="Input Input--has-status warning">
<div class="Input__container">
<input class="Input__field" type="text" placeholder="Placeholder">
<div class="Input__fake-input"></div>
</div>
</div>
<h2>Input - Invalid</h2>
<div class="Input Input--is-invalid">
<div class="Input__container">
<input class="Input__field" type="text" placeholder="Placeholder" value="Lorem ipsum dolor">
<div class="Input__fake-input"></div>
</div>
</div>
<h2>Input - Disabled</h2>
<div class="Input Input--is-disabled">
<div class="Input__container">
<input class="Input__field" type="text" placeholder="Placeholder" value="Lorem ipsum" disabled>
<div class="Input__icon">
<img src="http://www.ondrejkonecny.cz/assets/svg/calendarDay.svg">
</div>
<div class="Input__fake-input"></div>
</div>
</div>
</div>
</form>
</div>
You are using two types of Input types, and you are referring the same CSS classes to achieve (EX .Input.Input__field,.Input__suffix);
one with Prefix,Suffix with Icon (Input box should occupy 75%, Icon should occupy 25%).
Input Modificators. (A default type: Input box should occupy 100%)
Its better you add a class(ex : .default ) to differentiate the input box with Icon and without Icon like above.
I modified code here # code-pen : https://codepen.io/mediraviteja/pen/OJyrozR
Code changes I did below.
a) Added class ".default" to the container div(EX : ) for all the full width inputs like (Default input, Modificator inputs)
b) Do CSS changes in below class
.Input__field{
width: 100%; -- remove css property
max-width: 76%; -- add css property
}
.Input__suffix{
max-width: 26%; -- add css property
}
**Add new class**
.default .Input__field{
max-width: 100%;
}
.default .Input__suffix{
max-width: 100%;
}
change the HTML element
<div class="Input "> to <div class="Input default">
when ever you need full with Input box like(Default input, Input -Warning,Input - Invalid boxes,etc.)
Related
I'm creating a homepage for my website and want a logo (avatar) to appear on the left hand side of the page and a login form to appear on the right hand side. My current code displays a centered login box and avatar. The avatar is directly above the login box (and slightly offscreen).
Ideally I'm looking to replicate facebooks homepage theme (facebook.com)
Any ideas?
html
{% load static %}
{#<link rel="stylesheet" type="text/css" href="{% static 'homepage/style.css' %}">#}
<html lang="">
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="{% static "homepage/style.css" %}">
<body>
<div class="rows">
<div class="logo">
<img src="{% static "homepage/images/my_logo.png" %}"
class="avatar"
alt=""
width=""
height="">
</div>
<div class="login-box">
<h1>Login</h1>
<form>
<p>Username</p>
<input type="text" name="" placeholder="Enter Username">
<p>Password</p>
<input type="password" name="" placeholder="Enter Password">
<input type="submit" name="" value="Login">
Forgot password?<br>
Sign-up<br>
</form>
</div>
</div>
</body>
</html>
css
body {
margin: 0;
padding: 0;
background-size: cover;
background: black center;
font-family: sans-serif;
}
.avatar {
float: left;
width: 200px;
height: 200px;
border-radius: 50%;
position: absolute;
top: -75px;
left: calc(50% - 100px);
}
.login-box{
float: right;
width: 320px;
height: 420px;
background: #000;
color: #fff;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%, -50%);
box-sizing: border-box;
padding: 70px 30px;
}
h1 {
margin: 0;
padding: 0 0 20px;
text-align: center;
font-size: 22px;
}
.login-box p {
margin: 0;
padding: 0;
font-weight: bold;
}
.login-box input {
width: 100%;
margin-bottom: 20px;
}
.login-box input[type="text"], input[type="password"] {
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
}
.login-box input[type="submit"] {
border: none;
outline: none;
height: 40px;
background: #ffc107;
color: #fff;
font-size: 18px;
border-radius: 20px;
}
.login-box input[type="submit"]:hover {
cursor: pointer;
background: lightgray;
color: #000;
}
.login-box a {
text-decoration: none;
font-size: 12px;
line-height: 20px;
color: darkgrey;
}
.login-box a:hover {
color: #ffc107;
}
Here is a basic example of placing two items side by side across the screen. The first uses display grid, and outlines 2 columns, the second is using flex.
img{
height: 50vh;
}
.grid-container{
display: grid;
height: 50vh;
grid-template-columns: auto 1fr;
}
.flex-container{
display: flex;
height: 50vh;
}
.login {
display: flex;
flex-direction: column;
}
<div class="grid-container">
<img src="https://picsum.photos/seed/picsum/200/200" alt="">
<div class="login">
<h1>Login</h1>
<form>
<div>
<label for="email">Email</label>
<input type="text" name="email">
</div>
<div>
<label for="paswd">Password</label>
<input type="password" name="passwd">
</div>
</form>
</div>
</div>
<div class="flex-container">
<img src="https://picsum.photos/seed/picsum/200/200" alt="">
<div class="login">
<h1>Login</h1>
<form>
<div>
<label for="email">Email</label>
<input type="text" name="email">
</div>
<div>
<label for="paswd">Password</label>
<input type="password" name="passwd">
</div>
</form>
</div>
</div>
I try to put "datacontain" div below "blue-div", but when blue-div height ++, it covers the "datacontain" div,
how to make "datacontain" div position responsive to blue-div bottom part position ?
Result :
-> i want to make the phonenumber (datacontain div) below blue-div
//style
<style>
.responsive {
width: 100%;
height: auto;
}
.flex-container {
display: flex;
flex-direction: column;
}
.blue-div {
max-width: 70%;
min-width: 70%;
height: 70px;
display: table;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
top:-12%;
/* /transform: translate(-50%, -50%); */
position: absolute;
background-color: #003777;
z-index: 130;
border-radius: 10px;
}
.white-cont {
width: 80%;
height: 215px;
display: block;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
margin-top: -25px;
/* /transform: translate(-50%, -50%); */
position: absolute;
background-color: white;
z-index: 100;
border-radius: 10px;
vertical-align: middle;
box-shadow: 1px 1px 6px 1px #888888;
}
.container-sk {
position: relative;
}
.input-group-addon {
color: gray;
background-color: #ffffff;
}
.datacontain {
margin-top: 50px;
}
.submitButton{
border-radius: 35px;
display: block;
width: 100%;
border: none;
background-color: #ef7c24;
color: white;
padding: 14px 28px;
font-size: 16px;
cursor: pointer;
text-align: center;
}
</style>
//html
<img src="<?php echo base_url() . 'assets/img/banner.jpg' ?>" alt="Nature" class="responsive">
<div class="container-sk flex-container" style="background-color:#28abe3; min-height:300px">
<div class="white-cont">
<div class="datacontain col-md-12">
<div class="">
<label>phonenumber</label>
</div>
<div class="">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<img style="height:20px;width:20px" src="<?php echo base_url() . 'assets/img/flag.png' ?>">
+62
</div>
<input class="form-control" id="phonenumber" name="phonenumber" type="text" />
</div>
</div>
<div class="col-md-12 mx-auto">
<button class="submitButton" type="button"> KLAIM VOUCHER </button>
</div>
</div>
</div>
<div class="blue-div" style="">
<label style="color:#fff;font-size:14px;display:table-cell;word-wrap: break-word;vertical-align: middle;" >this is voucher 12345 12345 12354 12345 12345 1234 1234 1234 1234 345 345345 345 345 3 </label>
</div>
</div>
</div>
You need to remove position: absolute; on both the blue div and the white container. If you want the blue div to appear first you also need to move it before the white container in your code.
.responsive {
width: 100%;
height: auto;
}
.flex-container {
display: flex;
flex-direction: column;
}
.blue-div {
max-width: 70%;
min-width: 70%;
height: 70px;
display: table;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
top:-12%;
/* /transform: translate(-50%, -50%); */
background-color: #003777;
z-index: 130;
border-radius: 10px;
}
.white-cont {
width: 80%;
height: 215px;
display: block;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
background-color: white;
z-index: 100;
border-radius: 10px;
vertical-align: middle;
box-shadow: 1px 1px 6px 1px #888888;
}
.container-sk {
position: relative;
}
.input-group-addon {
color: gray;
background-color: #ffffff;
}
.datacontain {
margin-top: 50px;
}
.submitButton{
border-radius: 35px;
display: block;
width: 100%;
border: none;
background-color: #ef7c24;
color: white;
padding: 14px 28px;
font-size: 16px;
cursor: pointer;
text-align: center;
}
<div class="container-sk flex-container" style="background-color:#28abe3; min-height:300px">
<div class="blue-div" style="">
<label style="color:#fff;font-size:14px;display:table-cell;word-wrap: break-word;vertical-align: middle;" >this is voucher 12345 12345 12354 12345 12345 1234 1234 1234 1234 345 345345 345 345 3 </label>
</div>
<div class="white-cont">
<div class="datacontain col-md-12">
<div class="">
<label>phonenumber</label>
</div>
<div class="">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
+62
</div>
<input class="form-control" id="phonenumber" name="phonenumber" type="text" />
</div>
</div>
<div class="col-md-12 mx-auto">
<button class="submitButton" type="button"> KLAIM VOUCHER </button>
</div>
</div>
</div>
</div>
</div>
How can I make these radio buttons responsive? I'm not sure what I'm doing wrong. I'd like to be able to click the grid item each option is in and have it behave like a radio button, but I'm not sure what I'm missing. Any recommendations for streamlining this code would also be extremely helpful. Thanks!
body {
font-family: Arial, Helvetica;
font-size: 3vh;
background-color: #b0b0b0;
}
.wrapper {
width: 50%;
margin-left: 25%;
margin-right: 25%;
display: grid;
grid-template-columns: 100px 100px 100px;
grid-gap: 20px;
grid-auto-rows: 100px;
justify-content: center;
background-color: ;
}
.item {
border-radius: 50px;
color: white;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
}
.item input {
opacity: 0;
position: absolute;
/*this makes it not interfere with the text location*/
}
.item:nth-child(odd) {
background: gray;
}
.item:nth-child(odd):hover {
background: limegreen;
cursor: pointer;
}
.item:nth-child(odd):label {}
.wrapper h2 {
grid-row: 1;
grid-column: 1/-1;
}
<div id="trialDiv" style="font-size: 13pt;">
<div id="TrialQuestions">
<div id="Questions" class="wrapper">
<h2 style="text-align:center"><i>What emotion was the face expressing? </i></h2>
<div id="gap" class="item"></div>
<div id="HappyButton" class="item">
<label>
<p><input class="responseButton" id="emotion_1" name="emotion" onclick = "GrabEmotionClickTime()" type="radio" value="1" /> Happiness</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="AngryButton" class="item">
<label>
<p><input class="responseButton" id="emotion_2" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="2" /> Anger</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="FearButton" class="item">
<label>
<p><input class="responseButton" id="emotion_4" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="3" /> Fear</p>
</label>
</div>
<div id="gap" class="item"></div>
<div id="NeutralButton" class="item">
<label>
<p><input class="responseButton" id="emotion_4" name="emotion" onclick = "GrabEmotionClickTime()"type="radio" value="4" /> Neutral</p>
</label>
</div>
</div>
</div>
</div>
Without doing all the work for you, your arrangement of elements is incorrect. Here is a simple example:
https://codepen.io/seanstopnik/pen/8a2ca693e9fe1f1334b921a6d75dbe99
/* For demo only */
body {
font-family: sans-serif;
padding: 40px;
}
/* Emotion button */
.emotion-button {
position: relative;
margin: 20px; /* For demo only */
}
.emotion-button__input {
position: absolute;
left: -9999px;
}
.emotion-button__label {
display: inline-block;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
border-radius: 50%;
background-color: #ccc;
cursor: pointer;
transition: all 0.15s ease-in-out;
}
.emotion-button__input:checked ~ .emotion-button__label {
color: #fff;
background-color: green;
}
<div class="emotion-button">
<input id="r1" class="emotion-button__input" type="radio" name="emotion"/>
<label for="r1" class="emotion-button__label">Happiness</label>
</div>
<div class="emotion-button">
<input id="r2" class="emotion-button__input" type="radio" name="emotion"/>
<label for="r2" class="emotion-button__label">Anger</label>
</div>
Same idea as #SeanStopnik, did all the work for you:
body {
font-family: Arial, Helvetica;
font-size: 13pt;
background-color: #b0b0b0;
}
#Questions h2 {
font-style: italic;
}
.wrapper {
width: 50%;
margin-left: 25%;
margin-right: 25%;
display: grid;
grid-template-columns: 100px 100px 100px;
grid-gap: 20px;
grid-auto-rows: 100px;
justify-content: center;
background-color: ;
}
.item label {
display: block;
border-radius: 50%;
color: white;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
height: 80px;
background: gray;
}
.item label:hover {
background: lime;
}
.item input {
display: none;
}
.item input:checked + label {
background: blue;
}
.wrapper h2 {
grid-row: 1;
grid-column: 1/-1;
}
<div id="trialDiv">
<div id="TrialQuestions">
<div id="Questions" class="wrapper">
<h2 style="text-align:center">What emotion was the face expressing?</h2>
<div class="gap"></div>
<div id="HappyButton" class="item">
<input class="responseButton" id="emotion_1" name="emotion" type="radio" value="1" />
<label for="emotion_1">Happiness</label>
</div>
<div class="gap"></div>
<div id="AngryButton" class="item">
<input class="responseButton" id="emotion_2" name="emotion" type="radio" value="2" />
<label for="emotion_2">Anger</label>
</div>
<div class="gap"></div>
<div id="FearButton" class="item">
<input class="responseButton" id="emotion_3" name="emotion" type="radio" value="3" />
<label for="emotion_3">Fear</label>
</div>
<div class="gap"></div>
<div id="NeutralButton" class="item">
<input class="responseButton" id="emotion_4" name="emotion" type="radio" value="4" />
<label for="emotion_4">Neutral</label>
</div>
</div>
</div>
</div>
Explanation:
radio inputs are made invisible
they are placed right before their labels
labels are associated with them using for="id" attribute, so that clicking the label will check the radio button
I'm using the CSS pseudoclass :checked to target checked radio for styling
the CSS operator + allows to target the label right after the checked radio
Also:
you shouldn't have javascript event handlers in your HTML. Better use addEventListener from javascript for that. Your onclick made the click fail.
you shouldn't repeat ids in html
you shouldn't style your fonts inline
you shouldn't use <i> to make your titles italic. You should use CSS for that
Use font-style: italic; for the h2 element, nowdays <i> is used to insert icons
You can the id value only once in your HTML! Can't give more than one element the same id.
By clicking on the label we check the input, so we hide the input and style the label : width + height = 100%
We give all the inputs the same name to prevent checking more than one input[radio].
AddEventListener for all the inputs to toggle the class active on each one item (depends on which is the checked one).
Print to the console the id of the input that is checked.
var inputs = document.querySelectorAll('.item label');
for (let i = 0; i < inputs.length; i++){
inputs[i].addEventListener('click', (e) => {
checkEmotion(inputs[i], e);
});
}
function checkEmotion(input, e){
for(let i = 0; i < inputs.length; i++){
inputs[i].parentElement.classList.remove('active');
}
e.target.parentElement.classList.add('active');
console.log(input.nextElementSibling.getAttribute("id"));
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica;
background-color: #b0b0b0;
}
h2 {
margin: 20px 0;
font-style: italic;
}
.wrapper {
display: flex;
justify-content: center;
}
.item {
border-radius: 50px;
color: white;
display: flex;
align-items: center;
justify-content: center;
width: 90px;
height: 90px;
margin: 0 10px;
background: gray;
position: relative;
overflow: hidden;
transition: all 0.2s;
}
.item.active {
background: #121212;
}
.item input {
opacity: 0;
display: absolute;
height: 0;
width: 0;
}
.item label {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.item:hover {
background: limegreen;
}
<h2 style="text-align:center">What emotion was the face expressing?</h2>
<div class="wrapper">
<div class="item">
<label for="emotion-happy">Happy</label>
<input type="radio" id="emotion-happy" name="emotion">
</div>
<div class="item">
<label for="emotion-sad">Sad</label>
<input type="radio" id="emotion-sad" name="emotion">
</div>
<div class="item">
<label for="emotion-angry">Angry</label>
<input type="radio" id="emotion-angry" name="emotion">
</div>
<div class="item">
<label for="emotion-confused">Confused</label>
<input type="radio" id="emotion-confused" name="emotion">
</div>
</div>
I would like to succeed in doing this using flexbox, I have already tried something but without success.
You have to put the title, the price and the input in flex-direction column, right?
Css
.container {
display: flex;
flex-direction: column;
width: 80%;
margin: auto;
}
.details {
flex-grow: 2;
}
.center {
text-align: center;
}
.quantity {
display: flex;
justify-content: center;
}
.quantity button {
width: 20px;
height: 20px;
border: none;
border-radius: 0;
}
.quantity input {
width: 20px;
text-align: center;
border: none;
}
<div class="container">
<h2>Mon Panier</h2>
<div>
<div class="details">
<img src="https://aaaestrie.ca/wp-content/uploads/2017/10/livres.jpg" width="150">
<span>title</span>
<span>39 €</span>
<div class="quantity">
<button class="btn-minus">-</button>
<input type="text" id="quantity" value="1">
<button class="btn-plus">+</button>
</div>
</div>
</div>
</div>
expected template
Is this you are trying to get? It's not quite you showed in the image but it's near.
Let me know if it doesn't work for you.
.container {
display: flex;
flex-direction: column;
width: 80%;
margin: auto;
}
.details {
flex-grow: 2;
}
.center {
text-align: center;
}
.quantity {
display: flex;
justify-content: center;
}
.quantity button {
width: 20px;
height: 20px;
border: none;
border-radius: 0;
}
.quantity input {
width: 20px;
text-align: center;
border: none;
}
.details span:nth-child(2) {
position: absolute;
margin-left: 10px;
font-size: 1.3rem;
}
.details span:nth-child(3) {
display: inline;
float: right;
}
.container {
background-color: lightcoral;
}
.details img {
border: 2px solid gray;
padding: 20px;
}
.inc-dec {
border: 1px solid black;
display: flex;
/* transform: translate(-100%,-100%); */
}
<div class="container">
<h2>Mon Panier</h2>
<div>
<hr>
<div class="details">
<img src="https://aaaestrie.ca/wp-content/uploads/2017/10/livres.jpg" width="150">
<span>title</span>
<span>39 €</span>
<div class="quantity">
<div class="inc-dec">
<button class="btn-minus">-</button>
<input type="text" id="quantity" value="1">
<button class="btn-plus">+</button>
</div>
</div>
</div>
</div>
</div>
you added "Angular" tag to your question so I assume you are using Angular.
if that's the case I highly recommend to use the npm package angular-flex-layout so you don't need to write so much CSS.
import the angular-flex-layout module in your app and watch the magic :)
<div>
<h2>Mon Panier</h2>
<div>
<hr>
<div>
<img src="https://aaaestrie.ca/wp-content/uploads/2017/10/livres.jpg" width="150">
// magic starts here
<div
fxLayout="column"
fxLayoutAlign="center center"
fxLayoutGap=".5rem"
>
<span>title</span>
<span>39 €</span>
<div class="inc-dec">
<button class="btn-minus">-</button>
<input type="text" id="quantity" value="1">
<button class="btn-plus">+</button>
</div>
</div> // magic ends here
</div>
</div>
</div>
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;
}