How can I make these radiobuttons clickable in CSS/HTML? - html

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>

Related

I created a Contact Page in Html and CSS. I want to put ContactForm and ContactInfo side by side, but on mobile devices it adjust itself top-bottom

I just created a contact Us form in HTML and CSS. I want a responsive page. In desktop everything works fine but When I try in mobile or tablet both contactForm and contactInfo shifts itself automatically into top and bottom position. I want to put them side by side in also mobile devices. I don't know why this is happening?
there are two parts in container:
contactForm
ContactInfo
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "poppins", sans-serif;
}
.contact {
position: relative;
min-height: 100vh;
padding: 50px 100px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: lightgreen;
}
.contact .content {
max-width: 800px;
text-align: center;
}
.contact .content h2 {
font-size: 36px;
font-weight: 500;
color: blue;
}
.contact .content p {
font-weight: 300;
color: blue;
}
.container {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
margin-top: 30px;
}
.container .contactInfo {
width: 50%;
display: flex;
flex-direction: column;
}
.container .contactInfo .box {
position: relative;
padding: 20px 0;
display: flex;
}
.container .contactInfo .box .text {
display: flex;
margin-left: 20px;
font-size: 16px;
color: green;
flex-direction: column;
font-weight: 300;
}
.container .contactInfo .box .text h3 {
font-weight: 500;
color: red;
}
.contactForm {
padding: 40px;
background: #fff;
}
.contactForm h2 {
font-size: 30px;
color: #333;
font-weight: 500;
}
.contactForm .inputBox {
position: relative;
width: 100%;
margin-top: 10px;
}
.contactForm .inputBox input,
.contactForm .inputBox textarea {
width: 100%;
padding: 5px 0;
font-size: 16px;
margin: 10px 0;
border: none;
border-bottom: 2px solid black;
outline: none;
resize: none;
}
.contactForm .inputBox input[type="submit"] {
width: 100px;
background: #000;
color: orange;
border: none;
cursor: pointer;
padding: 10px;
font-size: 18px;
}
#media (max-width: 991px) {
.contact {
padding: 50px;
}
.container {
flex-direction: column;
}
.container .contactInfo {
margin-bottom: 40px;
}
.container .contactInfo {
width: 100%;
}
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<section class="contact">
<div class="content">
<h2>Reach Us</h2>
<p>
We would love to respond to your queries and help you succeed.<br />Feel
free to get in touch with us
</p>
</div>
<div class="container">
<!-- contact form -->
<div class="contactForm">
<form action="contact.php">
<h2>Send Query</h2>
<div class="inputBox">
<input type="text" name="" required="required" />
<span>Full Name</span>
</div>
<div class="inputBox">
<input type="email" name="" required="required" />
<span>Email Id</span>
</div>
<div class="inputBox">
<input type="number" name="" required="required" />
<span>Phone</span>
</div>
<div class="inputBox">
<input type="text" name="" required="required" />
<span>Address</span>
</div>
<div class="inputBox">
<textarea name="" id="" required="required"></textarea>
<span>Type your Query</span>
</div>
<div class="inputBox">
<input type="submit" name="" required="required" value="Send" />
</div>
</form>
</div>
<!-- reach us -->
<div class="contactInfo">
<div class="box">
<div class="icon"></div>
<div class="text">
<h3>Address</h3>
<p>AaBbbbbbbb,<br />fdafafdfa,<br />fdafafgafa</p>
</div>
</div>
<div class="box">
<div class="icon"></div>
<div class="text">
<h3>Phone</h3>
<p>+91 91XXXXXXXXXX</p>
</div>
</div>
<div class="box">
<div class="icon"></div>
<div class="text">
<h3>Email</h3>
<p>asdfghjkl.gmail.com</p>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
If you want .contactform and .contactinfo container side by side. You can do it in two simple ways
Instead of flex-direction: column, You can use flex-direction: row.
No need to write unnecessary CSS. Just remove the flex-direction property from the media query.
#media (max-width: 991px) {
.contact {
padding: 50px;
}
/* .container {
flex-direction: column;
} */
.container .contactInfo {
margin-bottom: 40px;
}
.container .contactInfo {
width: 100%;
}
}

HTML template with flexbox

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>

Firefox flexbox space-between bug - item is out of the container

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.)

how do vertically align login form between banner and footer

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;
}

Only CSS Carousel: problems with centering and fixing size

I have a carousel created with only CSS, but I have identified some difficulties. All images are in the 4:3 aspect ratio and may have a maximum of 640x480 px (that is, they can be smaller than this value), so:
I can not center the next and previous arrows;
The arrows can not be "floating" on the screen (if the next image is
smaller than the previous one, the arrows should not change
position);
I do not know how to set the size of the carousel according to the
largest image currently used.
The code:
html {
font-size: 10px;
}
body {
padding: 2rem;
background: #F8F8F8;
font-size: 16px;
}
.wrap {
max-width: 70rem;
margin: auto;
padding: 2rem;
background: #FFF;
}
.carousel {
position: relative;
display: -webkit-box;
display: flex;
max-width: 64rem;
min-height: 40rem;
margin: auto;
background: red;
-webkit-box-pack: center;
justify-content: center;
}
.group {
display: -webkit-box;
display: flex;
background: blue;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
align-items: center;
}
.group input {
position: absolute;
top: -100%;
left: -100%;
display: none;
}
.group input ~ .content {
/* tentar fixar tamanho aqui */
display: none;
-webkit-box-ordinal-group: 3;
order: 2;
}
div.group input:checked ~ div.content {
display: block;
}
div.group input:checked ~ label.previous,
div.group input:checked ~ label.next {
display: block;
}
div.group label {
top: 50%;
display: none;
width: 50px;
height: 50px;
border: solid 1px black;
background-color: #69C;
transform: translateY(-50%);
}
img {
width: 100%;
height: 100%;
}
label {
margin: 125px 0 0 0;
font-size: 4em;
}
label.previous {
padding: 0 0 30px 5px;
-webkit-box-ordinal-group: 2;
order: 1;
}
label.next {
padding: 0 5px 25px 0;
text-align: right;
-webkit-box-ordinal-group: 4;
order: 3;
}
<!DOCTYPE html>
<html>
<head>
<title>Teste 3</title>
<link rel="stylesheet" type="text/css" href="teste3.css">
<meta charset="utf-8">
</head>
<body>
<div class="wrap">
<div class="carousel">
<div class="group">
<input type="radio" name="test" id="0" value="0">
<label for="4" class="previous"><</label>
<label for="1" class="next">></label>
<div class="content">
<img src="https://www.oneperiodic.com/products/photobatch/tutorials/img/scale_original.png" width="200" height="286">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="1" value="1">
<label for="0" class="previous"><</label>
<label for="2" class="next">></label>
<div class="content">
<img src="https://www.ausmedia.com.au/Mmedia/4TO3.gif" width="200" height="139">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="2" value="2">
<label for="1" class="previous"><</label>
<label for="3" class="next">></label>
<div class="content">
<img src="http://www.cegepsherbrooke.qc.ca/~cpi/images/photo_4-3.jpg" width="140" height="200">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="3" value="3" checked="">
<label for="2" class="previous"><</label>
<label for="4" class="next">></label>
<div class="content">
<img src="http://www.projectorcentral.com/images/articles/4-3%20Bristlecone%20Pines.jpg" width="200" height="287">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="4" value="4">
<label for="3" class="previous"><</label>
<label for="0" class="next">></label>
<div class="content">
<img src="http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-for-monitor-4-3-almost-square-awesome/wallpaper-for-monitor-4-3-almost-square-awesome-951.jpg" width="96" height="139">
</div>
</div>
</div>
</div>
</body>
</html>
Can anyone help me find a solution or at least a balance in the measurements?
From what I understood,
You did not add
position: absolute to labels.
changed top to 18% to have them in center.
prev with left:0;
next with right:0;
This will set your labels as per the carousel, as it has the position relative.
html{
font-size: 10px;
}
body {
padding: 2rem;
background: #F8F8F8;
font-size: 16px;
}
.wrap {
max-width: 70rem;
margin: auto;
padding: 2rem;
background: #FFF;
}
.carousel {
position: relative;
display: -webkit-box;
display: flex;
max-width: 64rem;
min-height: 40rem;
margin: auto;
background: red;
-webkit-box-pack: center;
justify-content: center;
}
.group {
display: -webkit-box;
display: flex;
background: blue;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
align-items: center;
}
.group input {
position: absolute;
top: -100%;
left: -100%;
display: none;
}
.group input ~ .content {
/* tentar fixar tamanho aqui */
display: none;
-webkit-box-ordinal-group: 3;
order: 2;
}
div.group input:checked ~ div.content {
display: block;
}
div.group input:checked ~ label.previous,
div.group input:checked ~ label.next {
display: block;
}
div.group label {
position:absolute;
top: 18%;
display: none;
width: 50px;
height: 50px;
border: solid 1px black;
background-color: #69C;
transform: translateY(-50%);
}
img {
width: 100%;
height: 100%;
}
label {
margin: 125px 0 0 0;
font-size: 4em;
}
label.previous {
padding: 0 0 30px 5px;
-webkit-box-ordinal-group: 2;
order: 1;
left:0;
}
label.next {
padding: 0 5px 25px 0;
text-align: right;
-webkit-box-ordinal-group: 4;
order: 3;
right:0;
}
<!DOCTYPE html>
<html>
<head>
<title>Teste 3</title>
<link rel="stylesheet" type="text/css" href="teste3.css">
<meta charset="utf-8">
</head>
<body>
<div class="wrap">
<div class="carousel">
<div class="group">
<input type="radio" name="test" id="0" value="0">
<label for="4" class="previous"><</label>
<label for="1" class="next">></label>
<div class="content">
<img src="https://www.oneperiodic.com/products/photobatch/tutorials/img/scale_original.png" width="200" height="286">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="1" value="1">
<label for="0" class="previous"><</label>
<label for="2" class="next">></label>
<div class="content">
<img src="https://www.ausmedia.com.au/Mmedia/4TO3.gif" width="200" height="139">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="2" value="2">
<label for="1" class="previous"><</label>
<label for="3" class="next">></label>
<div class="content">
<img src="http://www.cegepsherbrooke.qc.ca/~cpi/images/photo_4-3.jpg" width="140" height="200">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="3" value="3" checked="">
<label for="2" class="previous"><</label>
<label for="4" class="next">></label>
<div class="content">
<img src="http://www.projectorcentral.com/images/articles/4-3%20Bristlecone%20Pines.jpg" width="200" height="287">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="4" value="4">
<label for="3" class="previous"><</label>
<label for="0" class="next">></label>
<div class="content">
<img src="http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-for-monitor-4-3-almost-square-awesome/wallpaper-for-monitor-4-3-almost-square-awesome-951.jpg" width="96" height="139">
</div>
</div>
</div>
</div>
</body>
</html>
Couple issues with your code Bianca. First off when we write HTML, it's best to leave out width and height properties within the actual html. The reason for this is that the browser will consider anything in your html as more important than external css files. We call this inline-styling or inline-styles when CSS is written directly into HTML. (Here's a good explanation of the hierarchy of CSS: Inline <style> tags vs. inline css properties )
Secondly, I updated your code, and included a max-width property to the content div, wherein your images are wrapped (the controlling css). So you can set that max-width to whatever you need, and it happens to work in this case.
Here's a Codepen: http://codepen.io/0rfila/pen/JbKrwj
And your updated code:
CSS:
html {
font-size: 10px;
}
body {
padding: 2rem;
background: #F8F8F8;
font-size: 16px;
}
.wrap {
max-width: 70rem;
margin: auto;
padding: 2rem;
background: #FFF;
}
.carousel {
position: relative;
display: -webkit-box;
display: flex;
max-width: 64rem;
min-height: 40rem;
margin: auto;
background: red;
-webkit-box-pack: center;
justify-content: center;
}
.group {
display: -webkit-box;
display: flex;
position: relative;
background: blue;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
align-items: center;
}
.group input {
position: absolute;
top: -100%;
left: -100%;
display: none;
}
.group input ~ .content {
/* tentar fixar tamanho aqui */
display: none;
-webkit-box-ordinal-group: 3;
order: 2;
}
div.group input:checked ~ div.content {
display: block;
}
div.group input:checked ~ label.previous,
div.group input:checked ~ label.next {
display: block;
}
div.group label {
top: 50%;
display: none;
width: 50px;
height: 50px;
border: solid 1px black;
background-color: #69C;
transform: translateY(-50%);
}
img {
width: 100%;
height: 100%;
}
label {
margin: 125px 0 0 0;
font-size: 4em;
}
label.previous {
padding: 0 0 30px 5px;
-webkit-box-ordinal-group: 2;
order: 1;
}
label.next {
padding: 0 5px 25px 0;
text-align: right;
-webkit-box-ordinal-group: 4;
order: 3;
}
.content {
max-width: 400px;
}
HTML:
<!DOCTYPE html>
<head>
<title>Teste 3</title>
<link rel="stylesheet" type="text/css" href="teste3.css">
<meta charset="utf-8">
</head>
<body>
<div class="wrap">
<div class="carousel">
<div class="group">
<input type="radio" name="test" id="0" value="0">
<label for="4" class="previous"><</label>
<label for="1" class="next">></label>
<div class="content">
<img src="https://www.oneperiodic.com/products/photobatch/tutorials/img/scale_original.png">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="1" value="1">
<label for="0" class="previous"><</label>
<label for="2" class="next">></label>
<div class="content">
<img src="https://www.ausmedia.com.au/Mmedia/4TO3.gif">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="2" value="2">
<label for="1" class="previous"><</label>
<label for="3" class="next">></label>
<div class="content">
<img src="http://www.cegepsherbrooke.qc.ca/~cpi/images/photo_4-3.jpg">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="3" value="3" checked="">
<label for="2" class="previous"><</label>
<label for="4" class="next">></label>
<div class="content">
<img src="http://www.projectorcentral.com/images/articles/4-3%20Bristlecone%20Pines.jpg">
</div>
</div>
<div class="group">
<input type="radio" name="test" id="4" value="4">
<label for="3" class="previous"><</label>
<label for="0" class="next">></label>
<div class="content">
<img src="http://www.wallpaperawesome.com/wallpapers-awesome/wallpapers-for-monitor-4-3-almost-square-awesome/wallpaper-for-monitor-4-3-almost-square-awesome-951.jpg">
</div>
</div>
</div>
</div>
</body>
</html>