I'm making a simple booking form, it is complete but for some reason every single input is slightly off to the right from being center aligned.
I've wrapped the form because there's multiple sections and the DIVs for inputs make controlling them slightly easier.
The page is complete so needs to follow this layout, the only issue is the alignment as shown in the image and code below.
.booking-wrap {
width: 100%;
padding-top: 3.5vh;
}
#media only screen and (max-width: 500px) {
.booking-wrap {
width: 100%;
padding-top: 3.5vh;
}
}
#media only screen and (max-width: 500px) {
.booking-wrap {
width: 100%;
padding-top: 1.75vh;
}
}
.booking-form {
width: 80%;
display: block;
margin-left: auto;
margin-right: auto;
padding-bottom: 3.5vh;
}
.user-input {
max-width: 60%;
text-align: center;
margin-left: auto;
margin-right: auto;
margin-top: 2.5vh;
}
.responsecontainer {
width: 100%;
margin-left: auto;
margin-right: auto;
}
.user-response {
width: 94%;
margin-left: auto;
margin-right: auto;
}
::placeholder {
color: #FFFFFF;
}
input[type=name], select {
width: 100%;
padding: 2vh;
margin: 0.5vh;
display: inline-block;
border-radius: 2vh;
border: 0;
color: #FFFFFF;
background: #000000;
outline: none;
}
<div class="booking-wrap">
<div class="booking-form">
<p class="form-explainer left textoffblack">Please enter your details</p>
<div class="user-input">
<div class="responsecontainer">
<div class="user-response">
<input type="name" placeholder="First Name" id="forename" name="forename" required>
</div>
</div>
</div>
</div>
</div>
Any help would be appreciated, I assume it's a quick fix but can't quite figure it out.
Your input element has width: 100%; and margin: 0.5vh;. margin is always added to the width, regardless of the box-sizing setting, so the overall width is 100% (of the container's width) plus 2 time 0.5vh. That's why it exceeds the width of its container.
A solution would probably be to apply those 0.5vh as padding to the container and remove the margin setting from the input element/s.
You're setting the width to be 100% of its container, but you're also setting a margination of 1vh in width in total, you can use calc() to avoid that issue: width: calc(100% - 1vh).
And making use of a border-box for the input will make the border part of the box itself.
.booking-wrap {
width: 100%;
padding-top: 3.5vh;
}
#media only screen and (max-width: 500px) {
.booking-wrap {
width: 100%;
padding-top: 3.5vh;
}
}
#media only screen and (max-width: 500px) {
.booking-wrap {
width: 100%;
padding-top: 1.75vh;
}
}
.booking-form {
width: 80%;
display: block;
margin-left: auto;
margin-right: auto;
padding-bottom: 3.5vh;
}
.user-input {
max-width: 60%;
text-align: center;
margin-left: auto;
margin-right: auto;
margin-top: 2.5vh;
}
.responsecontainer {
width: 100%;
margin-left: auto;
margin-right: auto;
}
.user-response {
width: 94%;
margin-left: auto;
margin-right: auto;
}
::placeholder {
color: #FFFFFF;
}
input[type=name], select {
width: calc(100% - 1vh);
box-sizing: border-box;
padding: 2vh;
margin: 0.5vh;
display: inline-block;
border-radius: 2vh;
border: 0;
color: #FFFFFF;
background: #000000;
outline: none;
}
<div class="booking-wrap">
<div class="booking-form">
<p class="form-explainer left textoffblack">Please enter your details</p>
<div class="user-input">
<div class="responsecontainer">
<div class="user-response">
<input type="name" placeholder="First Name" id="forename" name="forename" required>
</div>
</div>
</div>
</div>
</div>
There may be a better solution than this but removing margins from the sides of the inputs seems to work.
input[type=name], select {
width: 100%;
padding: 2vh;
margin-top: 0.5vh;
margin-bottom: 0.5vh;
display: inline-block;
border-radius: 2vh;
border: 0;
color: #FFFFFF;
background: #000000;
outline: none;
}
.booking-wrap {
width: 100%;
padding-top: 3.5vh;
}
#media only screen and (max-width: 500px) {
.booking-wrap {
width: 100%;
padding-top: 3.5vh;
}
}
#media only screen and (max-width: 500px) {
.booking-wrap {
width: 100%;
padding-top: 1.75vh;
}
}
.booking-form {
width: 80%;
display: block;
margin-left: auto;
margin-right: auto;
padding-bottom: 3.5vh;
}
.user-input {
max-width: 60%;
//text-align: center;
//margin-left: auto;
//margin-right: auto;
margin-top: 2.5vh;
}
.responsecontainer {
width: 100%;
margin-left: auto;
margin-right: auto;
}
.user-response {
width: 94%;
//margin-left: auto;
//margin-right: auto;
}
::placeholder {
color: #FFFFFF;
}
input[type=name], select {
width: 100%;
padding: 2vh;
margin: 0.5vh;
display: inline-block;
border-radius: 2vh;
border: 0;
color: #FFFFFF;
background: #000000;
outline: none;
}
<div class="booking-wrap">
<div class="booking-form">
<p class="form-explainer left textoffblack">Please enter your details</p>
<div class="user-input">
<div class="responsecontainer">
<div class="user-response">
<input type="name" placeholder="First Name" id="forename" name="forename" required>
</div>
</div>
</div>
</div>
</div>
I commented out margin-left: auto, magin-right: auto for .responsecontainer and .user-response
However, I am not sure this is what you want.
If it is not, Please let me know more detail so that I can help you.
Related
How would I make it so the image resizes properly when viewed on smaller screens. Right now, the image is over the container when viewed on smaller screens. There are also small gaps between the top/left of the container and the image. Would I have to resize the image in the media query or expand the width of my container in the media query?
.container {
width: 88%;
margin: 50px auto;
margin-top: 0px;
}
.heading {
text-align: center;
font-size: 30px;
margin-bottom: 50px;
}
.row {
display: flex;
flex-direction: row;
justify-content: space-around;
flex-flow: wrap;
}
.card {
width: 30%;
background: #fff;
border: 1px solid #ccc;
margin-bottom: 50px;
}
.image {
width: fit-content;
height: fit-content;
}
.card-body {
padding: 30px 10px;
text-align: left;
font-size: 18px;
}
.card-body .btn {
display: block;
color: #fff;
text-align: center;
background: black;
margin-top: 30px;
text-decoration: none;
padding: 10px 5px;
}
#media screen and (max-width: 1000px) {
.card {
width: 40%;
}
.heading {
text-align: auto;
}
.card-header {
margin: auto;
}
.image {
width: fit-content;
height: fit-content;
}
}
#media screen and (max-width: 620px) {
.container {
width: 100%;
}
.heading {
padding: 20px;
font-size: 20px;
text-align: auto;
}
.card {
width: 80%;
}
.image {
width: fit-content;
height: fit-content;
}
}
<div class="container">
<div class="heading">
<h1>Latest Posts</h1>
</div>
<div class="row">
<div class="card">
<div class="image">
<img src="https://via.placeholder.com/1920x1080.jpg">
</div>
<div class="card-body">
<p>
Text Here
</p>
Read more
</div>
</div>
I typically put width: 100%; on images in my projects and height: auto this way the image will be more responsive and scale up and down. You can reduce the width for the smaller media query if you want an even smaller image (width: 85%; for example) or I would probably personally end up reducing the width of the container to get the desired result.
1st: Remove your CSS for the class .image
2nd: Add this CSS line to the base-css (not within the media queries):
img {
object-fit: contain;
width: 100%;
}
What will that do?
object-fit: contain will keep the image aspect ratio while width: 100% will cause the image to fit exactly the given space. The height is set automatically according to the width while it maintain the image aspect ratio as mentioned above.
.container {
width: 88%;
margin: 50px auto;
margin-top: 0px;
}
.heading {
text-align: center;
font-size: 30px;
margin-bottom: 50px;
}
.row {
display: flex;
flex-direction: row;
justify-content: space-around;
flex-flow: wrap;
}
.card {
width: 30%;
background: #fff;
border: 1px solid #ccc;
margin-bottom: 50px;
}
.image {
width: fit-content;
height: fit-content;
}
.card-body {
padding: 30px 10px;
text-align: left;
font-size: 18px;
}
.card-body .btn {
display: block;
color: #fff;
text-align: center;
background: black;
margin-top: 30px;
text-decoration: none;
padding: 10px 5px;
}
img {
object-fit: contain;
width: 100%;
}
#media screen and (max-width: 1000px) {
.card {
width: 40%;
}
.heading {
text-align: auto;
}
.card-header {
margin: auto;
}
}
#media screen and (max-width: 620px) {
.container {
width: 100%;
}
.heading {
padding: 20px;
font-size: 20px;
text-align: auto;
}
.card {
width: 80%;
}
}
<div class="container">
<div class="heading">
<h1>Latest Posts</h1>
</div>
<div class="row">
<div class="card">
<div class="image">
<img src="https://via.placeholder.com/1920x1080.jpg">
</div>
<div class="card-body">
<p>
Text Here
</p>
Read more
</div>
</div>
I know this must be a very simple question but I am having trouble in auto adjusting the height of text based div. Basically I am displaying two horizontal divs in a row. One is text based and the other is image based. Image based div is always auto adjusting its height but text based div is not auto resizing its height accordingly. May be it is because of the padding I have added but don't know how to adjust it according to different screen resolutions. Please find the below two screenshots for better understanding.
Desktop View:
Mobile or Tablet View:
Below is the code for reference:
<style>
.container {
display:block;
width:100%;
}
#custom-section2 .left, #custom-section2 .right {
float: left;
width: 50%;
}
#custom-section2 .left {
background-color: #F7E3EC;
height: 464.67px;
}
#custom-section2 .right {
background-color: #FFF;
}
.section2-with-text1{
padding-top: 15%;
font-size: 2vw;
font-family: 'Arial';
letter-spacing: 0.1em;
}
.section2-with-text2{
padding-top: 5%;
font-size: 1.4vw;
font-family: 'Arial';
}
.section2-with-text3{
padding-top: 15%;
}
.section2-with-text3 .button {
background-color: #000;
border: none;
color: white;
padding: 8px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin: 4px 2px;
cursor: pointer;
display:inline-block;
}
.img-style{
height: auto;
}
#media only screen and (min-width:1901px) {
#custom-section2 .right img{
height: 660px;
}
#custom-section2 .left{
height: 660px;
}
}
#media only screen and (max-width:1900) {
#custom-section2 .right img{
height: auto;
}
#custom-section2 .left{
height: auto;
}
}
#custom-section2 .right img{
width: 100%;
}
</style>
<div class="container" id="custom-section2">
<div class="right">
<img src="https://cdn.shopify.com/s/files/1/2200/5487/files/Rectangle_8.jpg?v=1582366707" class="img-style" alt="">
</div>
<div class="left">
<div class="section2-with-text1"><center>TEETH WHITENING KITS</center></div>
<div class="section2-with-text2"><center>Get that insta-famous smile, from the convenience <br> from your home. Formulated with whitening <br> ingredients previously only available at your dentist.</center></div>
<div class="section2-with-text3"><center><button class="button">SHOP NOW</button></center></div>
</div>
</div>
Please suggest a possible solution. I would be grateful.
Thank you
Instead of using float to horizontally align your elements, it would be much easier to use display: flex;
Using flex will keep the left and right elements the same height.
Also note: You'll need to remove the height: 464.67px; declaration in #custom-section2 .left and remove float: left; from #custom-section2 .left, #custom-section2 .right.
(see all my comments in the CSS code)
Like so: (run code snippet)
.container {
display:block;
width:100%;
}
#custom-section2 {
display: flex; /*Add this!*/
}
#custom-section2 .left, #custom-section2 .right {
width: 50%;
/*float: left;*/ /*remove this!*/
}
#custom-section2 .left {
background-color: #F7E3EC;
/*height: 464.67px;*/ /*Remove this!*/
}
#custom-section2 .right {
background-color: #FFF;
}
.section2-with-text1{
padding-top: 15%;
font-size: 2vw;
font-family: 'Arial';
letter-spacing: 0.1em;
}
.section2-with-text2{
padding-top: 5%;
font-size: 1.4vw;
font-family: 'Arial';
}
.section2-with-text3{
padding-top: 15%;
}
.section2-with-text3 .button {
background-color: #000;
border: none;
color: white;
padding: 8px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin: 4px 2px;
cursor: pointer;
display:block;
}
/*.img-style{
height: auto;
}/*
/* You can remove all this: */
/*#media only screen and (min-width:1901px) {
#custom-section2 .right img{
height: 660px;
}
#custom-section2 .left{
height: 660px;
}
}
#media only screen and (max-width:1900) {
#custom-section2 .right img{
height: auto;
}
#custom-section2 .left{
height: auto;
}
}*/
#custom-section2 .right img{
width: 100%;
height: auto; /*Add this!*/
display: block; /*Add this!*/
}
<div class="container" id="custom-section2">
<div class="right">
<img src="https://cdn.shopify.com/s/files/1/2200/5487/files/Rectangle_8.jpg?v=1582366707" class="img-style" alt="">
</div>
<div class="left">
<div class="section2-with-text1"><center>TEETH WHITENING KITS</center></div>
<div class="section2-with-text2"><center>Get that insta-famous smile, from the convenience <br> from your home. Formulated with whitening <br> ingredients previously only available at your dentist.</center></div>
<div class="section2-with-text3"><center><button class="button">SHOP NOW</button></center></div>
</div>
</div>
Im new to flexbox and css.I need some help to make this code work.
The problem is the following, i cant make the inputs, textarea and button to be responsive.
I need them to be that width size on normal computer page but to be smaller and responsive on mobile devices.
Any advice with help me.
Thanks a lot
.email{
padding: 0.5% 0% 0.5% 0%;
display: flex;
align-items: center;
flex-flow: column;
}
.email >div{
margin: 10px 0px 10px 0px;
}
input {
padding: 15px;
width: 402px;
max-width: 402px;
box-sizing: border-box;
border: 1px solid #272525;
font-size: small;
}
::placeholder {
font-size: 14px ;
opacity: 1;
}
textarea{
padding: 15px;
width: 402px;
resize: vertical;
font-size: small;
border: 1px solid #272525;
}
.button-send{
width: 434px;
height: 40px;
background-color: black;
color: white;
font-size: 15px;
font-size: small;
}
<div class="email">
<div>
<input type="text" placeholder="Name">
</div>
<div>
<input type="text" placeholder="Email*">
</div>
<div>
<textarea rows="10" placeholder="Message*"></textarea>
</div>
<div>
<button class="button-send">Send </button>
</div>
</div>
you can add #media queries in Css as I have done it for you below:-
Click on Run code snippet and then Full page and make your window smaller and check it
.email {
padding: 0.5% 0% 0.5% 0%;
display: flex;
align-items: center;
flex-flow: column;
}
.email>div {
margin: 10px 0px 10px 0px;
}
input {
padding: 15px;
width: 402px;
max-width: 402px;
box-sizing: border-box;
border: 1px solid #272525;
font-size: small;
}
::placeholder {
font-size: 14px;
opacity: 1;
}
textarea {
padding: 15px;
width: 402px;
resize: vertical;
font-size: small;
border: 1px solid #272525;
}
.button-send {
width: 434px;
height: 40px;
background-color: black;
color: white;
font-size: 15px;
font-size: small;
}
#media only screen and (max-width: 600px) {
input {
width: 200px;
max-width: 200px;
}
textarea {
width: 200px;
max-width: 200px;
}
button {
width: 200px;
max-width: 200px;
}
}
<body>
<div class="email">
<div>
<input type="text" placeholder="Name">
</div>
<div>
<input type="text" placeholder="Email*">
</div>
<div>
<textarea rows="10" placeholder="Message*"></textarea>
</div>
<div>
<button class="button-send">Send </button>
</div>
</div>
</body>
In the event, you need to alter CSS values exclusively for small screen sizes but retain specific values for another screen size you would then need to use media queries.
So first what is a media query?
A media query consists of a media type and zero or more expressions that check for the conditions of particular media features.
https://www.w3.org/TR/css3-mediaqueries/
I'd advise reading through that document to get a better understanding of what media queries really are.
But in answer to your question to have responsive text areas you would want to add in something like this (You could also just use max-width by changing all your widths to 100% and setting your max-width to your current width.);
.email {
padding: 0.5% 0% 0.5% 0%;
display: flex;
align-items: center;
flex-flow: column;
}
.email>div {
margin: 10px 0px 10px 0px;
}
input {
padding: 15px;
width: 402px;
max-width: 402px;
box-sizing: border-box;
border: 1px solid #272525;
font-size: small;
}
::placeholder {
font-size: 14px;
opacity: 1;
}
textarea {
padding: 15px;
width: 402px;
resize: vertical;
font-size: small;
border: 1px solid #272525;
}
.button-send {
width: 434px;
height: 40px;
background-color: black;
color: white;
font-size: 15px;
font-size: small;
}
#media all and (max-width:500px) {
textarea,.button-send,input {
width: 100%;
}
}
<div class="email">
<div>
<input type="text" placeholder="Name">
</div>
<div>
<input type="text" placeholder="Email*">
</div>
<div>
<textarea rows="10" placeholder="Message*"></textarea>
</div>
<div>
<button class="button-send">Send </button>
</div>
</div>
I have a responsive grid and button container that appears on many different pages with different lengths of text on each page.
I don't want the text wrap so I have used white-space: nowrap on the button.
The problem is that the text is getting truncated for longer text such as save and continue.
Is there any way the text can expand to the amount needed irrespective of the width of the parent container?
I could use width: auto on the button but this falls apart at lower resolutions.
.wrapper {
margin: 0 auto;
padding: 0 15px;
}
.grid {
list-style: none;
margin: 0;
padding: 0;
margin-left: -30px;
}
.grid__item {
display: inline-block;
padding-left: 30px;
vertical-align: top;
width: 100%;
box-sizing: border-box;
}
.application-layout__container__right {
float: right;
}
.one-half {
width: 50%;
}
button {
width: 100%;
white-space: nowrap;
border: 1px solid #0065bd;
background-color: #0065bd;
color: #fff;
font-size: 16px;
height: auto;
text-transform: uppercase;
padding: 14px 22px;
line-height: 28px;
font-weight: bold;
cursor: pointer;
display: table;
vertical-align: middle;
text-align: center;
text-decoration: none;
border-radius: 0;
width: 100%;
}
#media (min-width: 380px) {
.application-layout__container {
padding-right: 0;
}
.wrapper {
max-width: 750px;
}
.medium--one-half {
width: 50%;
}
button {
font-size: 19px;
}
}
#media (min-width: 992px) {
.wrapper {
max-width: 970px;
}
.large--one-third {
width: 33.33333%;
}
}
#media (min-width: 1200px) {
.wrapper {
max-width: 1170px;
}
}
<div class="wrapper application-layout__button__wrapper">
<div class="grid">
<div class="grid__item one-half">
<div class="grid">
<div class="grid__item one-whole medium--one-half large--one-third ">
<button>Back
</button>
</div>
</div>
</div>
<div class="grid__item one-half application-layout__container__right">
<div class="grid">
<div class="grid__item one-whole medium--one-half large--one-third">
<button class="remote-submit-button__default button__default button__primary" type="button">Confirm and pay</button>
</div>
</div>
</div>
</div>
</div>
There is a value for what you need but it's not yet supported by all the broswer. It's fit-content that you can use with width/min-width:
.wrapper {
margin: 0 auto;
padding: 0 15px;
}
.grid {
list-style: none;
margin: 0;
padding: 0;
margin-left: -30px;
}
.grid__item {
display: inline-block;
padding-left: 30px;
vertical-align: top;
width: 100%;
box-sizing: border-box;
}
.application-layout__container__right {
float: right;
}
.one-half {
width: 50%;
}
button {
width: 100%;
white-space: nowrap;
border: 1px solid #0065bd;
background-color: #0065bd;
color: #fff;
font-size: 16px;
height: auto;
text-transform: uppercase;
padding: 14px 22px;
line-height: 28px;
font-weight: bold;
cursor: pointer;
display: table;
vertical-align: middle;
text-align: center;
text-decoration: none;
border-radius: 0;
min-width: fit-content;
}
#media (min-width: 380px) {
.application-layout__container {
padding-right: 0;
}
.wrapper {
max-width: 750px;
}
.medium--one-half {
width: 50%;
}
button {
font-size: 19px;
}
}
#media (min-width: 992px) {
.wrapper {
max-width: 970px;
}
.large--one-third {
width: 33.33333%;
}
}
#media (min-width: 1200px) {
.wrapper {
max-width: 1170px;
}
}
<div class="wrapper application-layout__button__wrapper">
<div class="grid">
<div class="grid__item one-half">
<div class="grid">
<div class="grid__item one-whole medium--one-half large--one-third ">
<button>Back
</button>
</div>
</div>
</div>
<div class="grid__item one-half application-layout__container__right">
<div class="grid">
<div class="grid__item one-whole medium--one-half large--one-third">
<button class="remote-submit-button__default button__default button__primary" type="button">Confirm and pay</button>
</div>
</div>
</div>
</div>
</div>
I'm trying to make a simple game, and I've run into few problems I can't seem to solve:
I can't center vertically floated elements (.stat and .clickable).
Total height of all elements should fit exactly into screen height, however it goes beyond it.
Images differ a bit in their width depending on value I give them (at my screen they look the same at 32% or 29%, but on 30% upper one has slightly wider (and a bit blurry) right border).
Height property of img elements has no effect.
Here's my code (Images are 450px wide squares):
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
background-color: #e6e6e6;
}
.statsBar,
.buttons {
color: #333333;
font-family: Impact, Charcoal, sans-serif;
text-transform: uppercase;
background-color: #bfbfbf;
height: 13%;
}
#score {
float: left;
margin-left: 5%;
}
#hp {
float: right;
margin-right: 5%;
}
.stats:after {
content: "";
display: block;
clear: both;
}
.clickable {
float: left;
width: 29.33%;
margin: 1%;
padding: 1%;
background: #f2f2f2;
}
.game {
width: 50%;
height: 100%;
text-align: center;
margin: auto;
background-color: #999999;
}
img {
width: 32%;
display: block;
margin: auto;
}
#enemyHand {
transform: rotate(180deg);
margin-top: 5%;
}
#playerHand {
margin-bottom: 5%;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src='game.js'></script>
</head>
<body>
<div class="game">
<div class="statsBar">
<p id="score" class="stat">score: 0</p>
<p id="hp" class="stat">hp: 3</p>
</div>
<div class="hands">
<img id="enemyHand" src="paper.png">
<img id="playerHand" src="scissors.png">
</div>
<div class="buttons">
<a id="paper" class="clickable" onclick="document.getElementById('playerHand').src='paper.png'">Paper</a>
<a id="rock" class="clickable" onclick="document.getElementById('playerHand').src='rock.png'">Rock</a>
<a id="scissors" class="clickable" onclick="document.getElementById('playerHand').src='scissors.png'">Scissors</a>
</div>
</div>
</body>
</html>
I don't know what you mean with your first question. However I can help you with the second. I made some small changes to your code, but I don't have the image. Look at the code bellow. The game container now is set to max-height: 100%; and height: 100vh; that should help. (100vh means the hole page. I also made body overflow: hidden;, because I think scrolling isn't necessary. I made the buttons container to the bottom of the page.
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
background-color: #e6e6e6;
overflow:hidden;
}
.statsBar,
.buttons {
color: #333333;
font-family: Impact, Charcoal, sans-serif;
text-transform: uppercase;
background-color: #bfbfbf;
height: 13%;
}
.buttons {
bottom: 0;
clear:both;
}
#score {
float: left;
margin-left: 5%;
}
#hp {
float: right;
margin-right: 5%;
}
.stats:after {
content: "";
display: block;
clear: both;
}
.clickable {
float: left;
width: 29.33%;
margin: 1%;
padding: 1%;
background: #f2f2f2;
}
.game {
width: 50%;
max-height: 100%;
height: 100vh;
text-align: center;
margin: auto;
background-color: #999999;
}
img {
height: 50%;
display: block;
margin: auto;
}
#enemyHand {
transform: rotate(180deg);
margin-top: 5%;
}
#playerHand {
margin-bottom: 5%;
}
For the third question, we don't have the images...
For the height property try display: block; and no width then. Check your classed normally it should work.
I hope I helped you !!!
You can take advantage of flexbox in this case (note the scroll is generated by the snippet's viewport height, ideally it wouldn't even overflow, but if it did, overflow: auto is set just to handle it, you can comment it though based on your benefit):
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
background-color: #e6e6e6;
}
.statsBar,
.buttons {
color: #333333;
font-family: Impact, Charcoal, sans-serif;
text-transform: uppercase;
background-color: #bfbfbf;
height: 13%;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
align-items: center;
}
.hands {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
/* comment if content will never overflow */
overflow-x: auto;
}
.buttons {
display: flex;
flex-flow: row wrap;
justify-content: center;
align-items: center;
}
.clickable {
float: left;
width: 29.33%;
margin: 1%;
padding: 1%;
background: #f2f2f2;
}
.game {
width: 50%;
height: 100%;
/*text-align: center;*/
margin: auto;
background-color: #999999;
display: flex;
flex-flow: column wrap;
justify-content: center;
}
img {
width: 32%;
display: block;
margin: auto;
}
/*#score {
float: left;
margin-left: 5%;
}*/
/*#hp {
float: right;
margin-right: 5%;
}*/
/*.stats:after {
content: "";
display: block;
clear: both;
}*/
/*#enemyHand {
transform: rotate(180deg);
margin-top: 5%;
}*/
/*#playerHand {
margin-bottom: 5%;
}*/
<div class="game">
<div class="statsBar">
<p id="score" class="stat">score: 0</p>
<p id="hp" class="stat">hp: 3</p>
</div>
<div class="hands">
<img id="enemyHand" src="paper.png">
<img id="playerHand" src="scissors.png">
</div>
<div class="buttons">
<a id="paper" class="clickable" onclick="document.getElementById('playerHand').src='paper.png'">Paper</a>
<a id="rock" class="clickable" onclick="document.getElementById('playerHand').src='rock.png'">Rock</a>
<a id="scissors" class="clickable" onclick="document.getElementById('playerHand').src='scissors.png'">Scissors</a>
</div>
</div>
Please check this code. I solve your question 1 and 2. I don't understand about your image issue.
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
background-color: #e6e6e6;
}
.statsBar,
.buttons {
display: table;
color: #333333;
font-family: Impact, Charcoal, sans-serif;
text-transform: uppercase;
background-color: #bfbfbf;
height: 13%;
width: 100%;
}
#score,
#hp{
display: table-cell;
vertical-align: middle;
padding: 10px;
}
#score {
/*float: left;
margin-left: 5%;*/
text-align: left;
}
#hp {
/*float: right;
margin-right: 5%;*/
text-align: right;
}
.stats:after {
content: "";
display: block;
clear: both;
}
.clickable {
/*float: left;*/ /*Float sould not use here */
display: table-cell;
width: 29.33%;
/*margin: 1%;
padding: 1%;*/
border: 5px solid #bfbfbf;
vertical-align: middle;
background: #f2f2f2;
}
.game {
width: 50%;
height: 100%;
text-align: center;
margin: auto;
background-color: #999999;
}
img {
width: 32%;
display: block;
margin: auto;
}
#enemyHand {
transform: rotate(180deg);
margin-top: 5%;
}
#playerHand {
margin-bottom: 5%;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src='game.js'></script>
</head>
<body>
<div class="game">
<div class="statsBar">
<p id="score" class="stat">score: 0</p>
<p id="hp" class="stat">hp: 3</p>
</div>
<div class="hands">
<img id="enemyHand" src="http://placehold.it/450x450">
<img id="playerHand" src="http://placehold.it/450x450">
</div>
<div class="buttons">
<a id="paper" class="clickable" onclick="document.getElementById('playerHand').src='paper.png'">Paper</a>
<a id="rock" class="clickable" onclick="document.getElementById('playerHand').src='rock.png'">Rock</a>
<a id="scissors" class="clickable" onclick="document.getElementById('playerHand').src='scissors.png'">Scissors</a>
</div>
</div>
</body>
</html>