I am designing a basic site where you can play rock paper scissors against the computer. The functionality is working perfectly, now I just need to tweak the format of the page.
I like the idea of having the game, and then underneath after a game, a message and button to restart appear, and should be centered under the page. Currently, these are being displayed to the right of my wrapper holding the actual game.
Here's my htm: the div and button are located at the bottom:
<div id="wrapper">
<div id="left" class="column">
<h2>User</h2>
<div id="userchoice">
</div>
</div>
<div id="middle" class="column">
<h2>VS.</h2>
</div>
<div id="right" class="column">
<h2>Rock Paper Scissors</h2>
<div id="computerchoice">
</div>
</div>
</div>
</br></br>
<div>
<p id="result"></p>
</div>
</br>
<button onclick="playAgain()" id="playagain" class="ui-button ui-widget ui-state-default ui-corner-all">Play Again?</button>
</br>
</br>
and my css:
body
{
text-align: center;
font-family: Verdana, Arial, sans-serif;
font-size: 1em;
}
#wrapper {
/*border: 2px solid black;*/
width: 1015px;
margin-left: auto;
margin-right: auto;
}
#header {
text-align: center;
}
/* 300px content + 20px = 320px physical width per column */
.column {
float: left;
width: 325px;
margin: 5px;
text-align: center;
min-height: 250px;
}
/* The middle column adds 4px of border to its physical width */
#middle {
/*border-left: 2px solid black;
border-right: 2px solid black;*/
margin-left: 0;
margin-right: 0;
padding-left: 10px;
padding-right: 10px;
}
/* CSS Clear Hack: apply this to the containing element. */
.group:before,
.group:after {
content:"";
display:table;
}
.group:after {
clear:both;
}
.group {
zoom:1; /* For IE 6/7 (trigger hasLayout) */
}
I've used this css on another page, and it functions as I want for the button and message at the bottom, so I'm quite baffled about how this isn't working. If you can spot an error or have something else I might try please let me know
Add a clear div to clear the height since you have floated elements.
<div id="wrapper">
<div id="left" class="column">
<h2>User</h2>
<div id="userchoice">
</div>
</div>
<div id="middle" class="column">
<h2>VS.</h2>
</div>
<div id="right" class="column">
<h2>Rock Paper Scissors</h2>
<div id="computerchoice">
</div>
</div>
<!-- clear here -->
<div class="clear" style="clear:both;"></div>
</div>
Related
I am trying to center a Bootstrap Well that says "Resource Booker" within a div so that it aligns properly with the two boxes below it. Ive tried adding padding but it adds padding inside of the well. I provided a picture and my code below.
Page Screenshot
<div class="col-sm-8 text-left">
<br>
<br>
<div class="well well-lg" style="background-color:rgb(0,50,0); color:white;"><h1> Resource Booker </h1> </div>
<br>
<br>
<div class="row">
<div class="column">
<div class="card" id="hi" style="width:400px; height:300px;">
<p><i class="fa fa-user"></i></p>
<h1>Book</h1>
<p>Book A Room</p>
<p> <span class="glyphicon glyphicon-book" style="font-size:150px;"></span></p>
</div>
</div>
<center>
<div class="column">
<br>
</div>
<div class="column">
<div class="card" id="bye" style="width:400px; height:300px;>
<p><i class="fa fa-coffee"></i></p>
<h1>Calender</h1>
<p>Check Availability</p>
<p> <span class="glyphicon glyphicon-calendar" style="font-size:150px;"></span></p>
</div>
</div>
</div>
</div>
</center>
</div>
The CSS for the cards underneath the well is:
/* Float four columns side by side */
.column {
float:left;
width: 27%;
padding: 0px 50px 0px 90px;
}
.row {margin: 0 -5px;}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive columns */
#media screen and (max-width: 600px) {
.column {
width: 100%;
display: block;
margin-bottom: 10px;
}
}
/* Style the counter cards */
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
background-color: #444;
color: white;
}
.fa {font-size:200px;
Try adding the container class wrapped around the div. You can also add margin-left to the same. Further, please add a codepen of your project so that we mobile users can play around for the solution.
If you add margin-left to div then you have to adjust that margin in media query it's better to give max-width to well dive and give them margin: 0 auto and width: 100%.
Your css will like this
.well{max-width: 400px; width: 100%; margin: 0 auto;}
What ends up happening is that the two columns cannot cohabitate next to each other without shrinking the width by about 2%. Doing that causes the edges to not align with the header and it just looks off. Is there something I am missing about 'width' or 'padding'?
This is what I am trying to emulate: https://www.w3schools.com/howto/howto_css_blog_layout.asp
This is what ends up happening (before changing the width by -2%):
What happens when I have to change the width:
body {
padding: 20px;
background: #f1f1f1;
}
.header {
padding: 30px;
font-size: 40px;
text-align: center;
background: white;
}
.leftcolumn {
float: left;
width: 75%;
}
.rightcolumn {
float: left;
width: 25%;
padding-left: 20px;
}
.card {
background-color: white;
padding: 20px;
margin-top: 20px;
}
.row:after {
content: "";
display: table;
clear: both;
}
.footer {
padding: 20px;
text-align: center;
background: #ddd;
margin-top: 20px;
}
#media(max-width: 800px) {
.leftcolumn,
.rightcolumn {
width: 100%;
padding: 0;
}
}
<div class="header">
<h2>Harry's Den</h2>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h2>I love the World</h2>
<h5>Helloo!</h5>
<p>Text!</p>
</div>
<div class="card">
<h2>Wow this works so far!</h2>
<h5>I am just happy to have a semi-functional blog!</h5>
<p>Yay! I do not have much to say other than I am happy to have made it this far. Hopefully this will help!</p>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h2>About Me!</h2>
<p>University: Texas Tech University</p>
<p>Major: Computer Engineering (BS)</p>
<p>Minor: Mathematics</p>
<p>Interests: Energy Infrastructure and Space Exploration Efforts</p>
</div>
<div class="card">
<h3>Popular Post</h3>
</div>
<div class="card">
<h3>Follow Me!</h3>
Twitter
<br/>
Facebook
</div>
</div>
</div>
<div class="footer">
<h2>Developed by Barry Allen</h2>
<h2>Quantum Enterprise Projects</h2>
</div>
Here is the information from the MDN Web Doc.
By default in the CSS box model, the width and height you assign to an
element is applied only to the element's content box. If the element
has any border or padding, this is then added to the width and height
to arrive at the size of the box that's rendered on the screen. This
means that when you set width and height you have to adjust the value
you give to allow for any border or padding that may be added.
The box-sizing property can be used to adjust this behavior:
content-box gives you the default CSS box-sizing behavior. If you set an element's width to 100 pixels, then the element's content
box will be 100 pixels wide, and the width of any border or padding
will be added to the final rendered width.
border-box tells the browser to account for any border and padding in the values you specify for width and height. If you
set an element's width to 100 pixels, that 100 pixels will
include any border or padding you added, and the content box
will shrink to absorb that extra width. This typically makes it
much easier to size elements.
You have to use box-sizing:border-box to include border, padding and margin everything included in the width of your element.
Read more information in MDN Web Docs
* {
box-sizing:border-box;
}
* {
box-sizing:border-box;
}
body{
padding: 20px;
background: #f1f1f1;
}
.header{
padding: 30px;
font-size: 40px;
text-align: center;
background: white;
}
.leftcolumn{
float: left;
width: 75%;
}
.rightcolumn{
float: left;
width: 25%;
padding-left: 20px;
}
.card{
background-color: white;
padding: 20px;
margin-top: 20px;
}
.row:after{
content: "";
display: table;
clear: both;
}
.footer{
padding: 20px;
text-align: center;
background: #ddd;
margin-top: 20px;
}
#media(max-width: 800px){
.leftcolumn, .rightcolumn{
width: 100%;
padding: 0;
}
}
<div class="header">
<h2>Harry's Den</h2>
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h2>I love the World</h2>
<h5>Helloo!</h5>
<p>Text!</p>
</div>
<div class="card">
<h2>Wow this works so far!</h2>
<h5>I am just happy to have a semi-functional blog!</h5>
<p>Yay! I do not have much to say other than I am happy to have made it this far. Hopefully this will help!</p>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h2>About Me!</h2>
<p>University: Texas Tech University</p>
<p>Major: Computer Engineering (BS)</p>
<p>Minor: Mathematics</p>
<p>Interests: Energy Infrastructure and Space Exploration Efforts</p>
</div>
<div class="card">
<h3>Popular Post</h3>
</div>
<div class="card">
<h3>Follow Me!</h3>
Twitter
<br/>
Facebook
</div>
</div>
</div>
<div class="footer">
<h2>Developed by Barry Allen</h2>
<h2>Quantum Enterprise Projects</h2>
</div>
Here is the Fiddle Link. You can expand and shrunk the size of the screen and check it out how it is reacting.
Padding and border are counted in the width. So you have to subtract them.
In your case you can do
.rightcolumn {
width: calc(25% - 20px);
}
i have a legend for a graph that sometimes is scrollable and sometimes isn't.
Unfortunately when the scrollbar shows up, it pushes all of the elements over to the left a bit. So they don't line up with a total (outside the scrollable area)
Example: http://jsfiddle.net/3sKVR/
A simple answer would be to just set a fixed width, but unfortunately, it has to be responsive.
Also, i can't use custom scrollbars to maintain consistency with the rest of the site and also bring down page-load times.
Any help would be greatly appreciated (with internet points!)
Cut down version of code:
HTML:
<div id="legend_cont">
<div id="legend_list">
<div id="legend">
<div class="legend_row">
<div class="legend_cell">
<div class="legend_colour" style="background-color:#ffb100"></div>
</div>
<div class="legend_cell">Merch G</div>
<div class="legend_cell legend_value">$1423.24</div>
</div>
<div class="legend_row">
<div class="legend_cell">
<div class="legend_colour" style="background-color:#ed5929"></div>
</div>
<div class="legend_cell">Merch L</div>
<div class="legend_cell legend_value">$1351.07</div>
</div>
<div class="legend_row">
<div class="legend_cell">
<div class="legend_colour" style="background-color:#3f9c35"></div>
</div>
<div class="legend_cell">Merch N</div>
<div class="legend_cell legend_value">$1194.90</div>
</div>
<div class="legend_row">
<div class="legend_cell">
<div class="legend_colour" style="background-color:#009bbb"></div>
</div>
<div class="legend_cell">Merch T</div>
<div class="legend_cell legend_value">$1188.14</div>
</div>
</div>
</div>
<div id="legend_total">Total:<span id="legend_total_value">$0.00</span>
</div>
</div>
CSS:
#legend_cont {
height: 100%;
border-left: 2px solid #ADADAD;
width: 40%;
float: right;
}
#legend_list {
height: 169px;
overflow: auto;
margin: 20px 4% 20px 7%;
}
#legend {
display: table;
width: 90%;
}
.legend_row {
display: table-row;
}
.legend_cell {
display: table-cell;
padding: 5px;
vertical-align: middle;
}
.legend_colour {
width: 10px;
height: 20px;
background-color: #c1c1c1;
border-radius: 3px;
}
.legend_value {
text-align: right;
}
#legend_total {
height: 50px;
line-height: 50px;
width: 88%;
border-top: 1px solid;
margin-left: 8%;
}
#legend_total_value {
float: right;
padding-right: 5px;
}
1) Make sure there is always a scroll bar
CSS
#legend_cont {
overflow-y: scroll;
}
2) Use js to grab the variable width of the scrollbar (example here)
3) Set the padding-right in #legend_total_value equal to that variable in jquery.
JS
$('#legend_total_value').css('padding-right', wScroll);
Try applying padding-right to compensate for the size of scrollbar when it's not there and position the total accordingly.
#legend_list {
height: 169px;
overflow: auto;
margin: 20px 4% 20px 7%;
padding-right:15px;
}
Demo
I'm trying to make this kind of responsive design with CSS.
It basically should be 600px width when there's enough space to show whole length.
When not, it folds, then right partial come appears on the bottom of left partial.
I'm struggling how to archive this.
This is DEMO that I could go this far
http://jsfiddle.net/a7Fkj/5/
HTML
<div class="table_row">
<div class="left_partial">
<div class="StoreName">Walmart Store</div>
<div class="Location">Located in California</div>
</div>
<div class="right_partial">
<div class="store_icon"><img src="https://twimg0-a.akamaihd.net/profile_images/616833885/walmart_logo_youtube.jpg"><div>
<div class="person1">John Smith<div>
<div class="person2">Mike Tailor<div>
<div class="person3">Jessica Swan<div>
</div>
</div>
CSS
div.table_row{
min-width: 300px;
margin-bottom: 30px;
}
div.left_partial{
width: 300px;
}
div.right_partial{
width: 300px;
}
div.StoreName{
background-color: #000000;
color: #FFFFFF;
}
div.Location{
}
div.store_icon{
width: 60px;
height: 60px;
}
div.person1{
}
div.person2{
}
div.person3{
}
You don't need media queries for this design- you can use inline-block to collapse the layout when the browser is resized.
HTML:
<div class="table_row">
<div class="left_partial">
<div class="StoreName">Walmart Store</div>
<div class="Location">Located in California</div>
</div>
<div class="right_partial">
<div class="store_icon"><img src="https://twimg0-a.akamaihd.net/profile_images/616833885/walmart_logo_youtube.jpg" /></div>
<div class="people">
<div class="person">John Smith</div>
<div class="person">Mike Tailor</div>
<div class="person">Jessica Swan</div>
</div>
</div>
</div>
CSS:
div.table_row{
min-width: 300px;
margin-bottom: 30px;
}
div.left_partial{
width: 300px;
display:inline-block;
vertical-align:top;
}
div.right_partial{
width: 300px;
display:inline-block;
vertical-align:top;
margin-bottom:30px;
}
div.StoreName{
background-color: #000000;
color: #FFFFFF;
}
div.Location{
}
div.store_icon{
width: 60px;
height: 60px;
display:inline-block;
vertical-align:top;
}
div.store_icon img{
width:100%;
height:100%;
}
div.people{
display:inline-block;
vertical-align:top;
height:60px;
width:234px;
}
jsfiddle: http://jsfiddle.net/kmMEM/
This will collapse the design when the browser is resized- I added a 30px bottom margin to your right_partial to ensure the list stacks correctly.
I want all my information to be in the center as you can see in the link below:
http://jsfiddle.net/EdHEu/
It looks fine BUT when i stretch/maximize the browser page the layout changes by text going right and then the boxes moving.
How is this stopped?
Thanks!
James
NOTE: Your Link is not working.
If your setup is like this:
<body>
<div id="main">
<div id="content">
<!--Content-->
</div>
<div id="sidebar">
<!--Sidebar-->
</div>
</div>
</body>
To Center the content ( to give the page a fixed width ), you need to use this CSS:
#main {
width:960px /* Give it a width */
margin: 0 auto; /* It will Center the #main */
}
This way, you can give the page a fixed width and make the layout fixed.
Why don't you take a look at this code (jsfiddle) & see if that cleans it up a bit more, too.
HTML:
<div class="content">
<form class="location" action="weezyresults.php" method="post">
<div>
<label for="job">job?</label>
<div class="input" name="job" >
<!-- change me back to your inputs,
and in the css change '.input' to 'input' -->
</div>
<label>job title or keywords</label>
</div>
<div>
<label for="where">where?</label>
<div class="input" name="where" >
<!-- change me back to your inputs,
and in the css change '.input' to 'input' -->
</div>
<label>town, city or county</label>
</div>
</form>
</div><!-- end .content -->
CSS:
.content {
margin:0 auto;
width:200px;
}
form>div { margin-bottom: 10px; }
form .input {
background: #ffffff;
border: 1px solid;
color: #BDBDBD;
height:35px;
margin:2px;
width: 320px;
}
div>label:first-child {
color: #585858;
font: bold 16px helvetica;
height:20px;
margin: 4px;
width: 320px;
}
div>label:last-child {
color: #585858;
font:italic 13px HelveticaNeue-Light;
margin: 4px;
}
.center {
text-align:center;
margin:0 auto;
width: 651px;
}