Left/Right percentages differences between browsers - html

I'd like to have a button at the bottom of a table, in the middle of the bottom of the table, centered. I did add left:30% and right:30% so the button locates at the middle, however, I noticed in Chrome this get rendered differently than Safari or Firefox, in Chrome, the percentages are not the same, thus the button ends up a little more to the left than right, and not centered/middled. Try it below.
How can I get this to work the same in Chrome too? Why are the percentages rendered differently, what's the best technique to centre this element that needs to be in absolute positioning?
.panel {
background-color: #fff;
border-radius: 10px;
padding: 15px 25px;
position: relative;
width: 100%;
z-index: 10;
}
.table {
box-shadow: 0px 10px 13px -6px rgba(0, 0, 0, 0.08), 0px 20px 31px 3px rgba(0, 0, 0, 0.09), 0px 8px 20px 7px rgba(0, 0, 0, 0.02);
display: flex;
flex-direction: column;
height:350px;
background:lightblue;
}
.table * {
text-align: center;
}
.contact-button {
bottom: -25px;
background: #f9f9f9;
border-radius: 10px;
left: 30%;
right: 30%;
margin: 0 auto;
position:absolute;
}
.btn {
display: inline-block;
padding: 8px 32px;
cursor: pointer;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
background-color: white;
border: 1px solid black;
color: black;
font-size: 14px;
letter-spacing: 2px;
}
<div class="panel table">
<button class="btn contact-button">CONTACT MORE INFO</button>
</div>

You can just move the button from the div and create something like this
<div class="panel table"></div>
<div class="wrapper">
<button class="btn contact-button">CONTACT MORE INFO</button>
</div>
This way you don't have to use position:absolute; you can just use
display:flex;
justify-content:center;
If you want more support for older browser versions, please check this article
Check the example below
.panel {
background-color: #fff;
border-radius: 10px;
position: relative;
width: 100%;
z-index: 10;
}
.table {
box-shadow: 0px 10px 13px -6px rgba(0, 0, 0, 0.08), 0px 20px 31px 3px rgba(0, 0, 0, 0.09), 0px 8px 20px 7px rgba(0, 0, 0, 0.02);
display: flex;
flex-direction: column;
height: 350px;
background: lightblue;
}
.table * {
text-align: center;
}
.contact-button {
bottom: -25px;
background: #f9f9f9;
border-radius: 10px;
left: 30%;
right: 30%;
margin: 0 auto;
}
.btn {
display: inline-block;
padding: 8px 32px;
cursor: pointer;
text-align: center;
vertical-align: middle;
white-space: nowrap;
outline: none;
line-height: inherit;
border: 1px solid black;
color: black;
font-size: 14px;
letter-spacing: 2px;
}
.wrapper {
display: flex;
justify-content: center;
}
body {
margin: 0;
}
<div class="panel table">
</div>
<div class="wrapper">
<button class="btn contact-button">CONTACT MORE INFO</button>
</div>

You can use this also it may help you without changing much things:
.contact-button {
background: #f9f9f9;
border-radius: 10px;
margin: 0 auto;
margin-top:370px;
}
have a look on this bin: https://jsbin.com/gipibecedu/edit?html,css,output

Related

How to make lines opposite each other?

Need to make lines opposite to each other, now the lines are under each other. Tried a lot of methods but nothing work, please help! Really stuck with that. See the code below and a picture that shows the desired result, idk what to do. Tried to add margin; top; bottom; padding, these methods didn't do anything.
Here's the CSS and HTML:
.crypto-card{
width: 250px;
height: 230px;
background: white;
-webkit-box-shadow: 0px 3px 8px 0px rgba(194,192,194,1);
-moz-box-shadow: 0px 3px 8px 0px rgba(194,192,194,1);
box-shadow: 0px 3px 2px 0px rgba(240,240,240,1);
border-radius: 6px;
transition: .3s;
margin-left: 15px;
margin-right: 25px;
margin-bottom: 20px;
border: 1px solid rgb(245, 245, 245);
}
.crypto-card:hover{
transform: translateY(-1px);
-webkit-box-shadow: 0px 3px 6px 2px rgba(240,240,240,1);
-moz-box-shadow: 0px 3px 6px 2px rgba(240,240,240,1);
box-shadow: 0px 3px 6px 2px rgba(240,240,240,1);
}
.crypto-card .body{
width: 100%;
border-top: 1px solid rgb(240, 240, 240);
padding: 10px;
}
.crypto-card .logo-sprite{
width: 29px;
height: 29px;
margin: 10px;
}
.crypto-symbol{
border-left: 1px solid rgb(220, 220, 220);
padding-left: 10px;
font-size: 1.3rem;
/* font-family: 'Loto', sans-serif; */
letter-spacing: 5px;
text-transform: uppercase;
/* color: #3c3c3c; */
font-weight: 500;
color: rgb(70, 70, 70);
padding-bottom: 4px;
position: relative;
top: 4px;
}
.crypto-card .price-label{
width: 100%;
text-align: left;
color: rgb(190, 190, 190);
font-weight: 500;
font-size: .8rem;
}
.crypto-card .price{
font-size: 1.5rem;
font-weight: 100;
right: -60px;
top: 4px;
text-align: right;
}
<div class="d-flex justify-content-left" style="margin-top: 10px; padding-left: 5%; padding-right: 5%;">
<div class="row" style="">
<div class="crypto-card">
<span>
<img src="https://s2.coinmarketcap.com/static/img/coins/64x64/1.png" class="logo-sprite" width="16" height="16" alt="Bitcoin">
<span class="crypto-symbol">BTC</span>
</span>
<div class="body">
<span class="price">$3865.58</span>
<div class="price-label"><span class="title">Price</span></div>
<span class="volume">$67,585,868,137</span>
</div>
</div>
But I need it similar to this
Using a display: grid would make this super easy.
Here's and example:
* {
box-sizing: border-box;
}
.container {
width: 500px;
margin: auto;
padding: 20px;
}
.card {
display: grid;
grid-template-columns: 50px auto;
grid-template-rows: 50px 200px;
border: 1px solid #eee;
border-radius: 5px;
}
.card .image {
display: block;
align-self: stretch;
justify-self: stretch;
padding: 5px;
border: 1px solid #eee;
border-top: 0;
border-left: 0;
}
.card .header {
padding: 10px;
border-bottom: 1px solid #eee;
}
.card .side {
border-right: 1px solid #eee;
white-space: nowrap;
display: flex;
align-items: center;
}
.card .side .text {
rotate: -90deg;
translate:-12px 0;
}
.card .content {
padding: 10px;
}
<div class="card">
<img
src="https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
class="image"
alt="Bitcoin"
/>
<div class="header">BTC is a scam</div>
<div class="side">
<div class="text">BIG SCAM</div>
</div>
<div class="content">content in here</div>
</div>

How can I build this badge with CSS?

I would like to add a badge to my navbar. It should look like the one in the image below.
My current Approach
I use two divs for this. One above and one below. The lower one should do the rounding.
My approach works not so good and I find it more hacky as good.
Question
I wonder if there is a better, cleaner way? Can somebody help me?
Thanks in advance, Max
* {
margin: 0;
padding: 0;
font-family: Verdana,Geneva,sans-serif;
}
body {
background-color: #f1f1f1;
}
nav {
height: 80px;
background-color: white;
padding:10px 80px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.badge-top {
background: #ccc;
margin-top:-10px;
height:25px;
padding-top:20px;
padding-left:5px;
padding-right:5px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
font-size:0.8rem;
font-weight:bold;
width:30px;
text-align: center;
}
.badge-bottom {
background: #ccc;
color:#ccc;
border-radius:50px;
margin-top:-10px;
}
.badge-bottom:after {
content: '.';
}
<nav>
<div>logo</div>
<div>
<button class="btn nav-btn">SUBMIT</button>
</div>
<div>
<div class="badge-top">123</div>
<div class="badge-bottom"></div>
</div>
</nav>
Really no reason for multiple elements. Note that I've put box-sizing: border-box on your stylesheet. This makes sizing calculations much easier by including padding, etc. Most layout libraries do this.
* {
margin: 0;
padding: 0;
font-family: Verdana, Geneva, sans-serif;
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
}
nav {
height: 80px;
background-color: white;
padding: 10px 80px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.badge {
background: #ccc;
width: 40px;
height: 60px;
padding-top: 26px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
font-size: 0.8rem;
font-weight: bold;
text-align: center;
border-radius: 0 0 20px 20px;
}
<nav>
<div>logo</div>
<div>
<button class="btn nav-btn">SUBMIT</button>
</div>
<div class="badge">
123
</div>
</nav>
div {
position: relative;
width: 2.5rem;
height: 4.5rem;
border-bottom-left-radius: 1.25rem;
border-bottom-right-radius: 1.25rem;
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.4);
background-color: #bfbfbf;
}
span {
position: absolute;
bottom: 1rem;
left: 50%;
transform: translate(-50%);
color: #222;
font-weight: bold;
}
<div>
<span>420</span>
</div>

How to adjust the boxshadow such that it is the full length of the parent div?

i want the boxshadow to fit the entire width of the parent div that is wrapper.
i have a div with class emptydiv and i have added box shadow only to top. doing so it will create a box shadow that is cut at the edges like in picture below.
.wrapper {
position: absolute;
bottom: 32px;
width: 316px;
height: 225px;
background: white;
box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.29);
border-radius: 16px;
display: flex;
flex-direction: column;
opacity: 1;
}
.container_one {
height: 101px;
width: 316px;
padding: 16px 6px 16px 22px;
border-radius: 16px 16px 0 0;
box-shadow: 0px 6px 6px -6px rgba(0, 0, 0, 0.29);
margin: 0px -6px 0px -6px;
}
.description {
height: 42px;
width: 289px;
margin-top: 8px;
color: black;
display: flex;
font-size: 12px;
font-weight: 400;
margin-bottom: 16px;
`;
.container_two {
padding: 16px 0px 16px 10px;
max-height: 108px;
display: flex;
flex-wrap: wrap;
overflow-x: hidden;
& > div {
margin-right: 4px;
margin-bottom: 16px;
}
}
.empty_div{
height: 32px;
width: 316px;
border-radius: 0 0 16px 16px;
box-shadow: 0px -6px 6px -6px rgba(0, 0, 0, 0.29);
margin: 0px -6px 0px -6px;
}
<div class="wrapper">
<div class="container_one">
this has boxshadow that is as expected
<span class="text">sometext</span>
<div class="description">some big description</div>
</div>
<div class="container_two">
this has boxshadow cut at right side
</div>
<div class="empty_div"/>
</div>
Now the problem is how can i set margin on empty_div such that it fits the entire width of wrapper div. right now its cut on the right edge as shown in picture above.
could someone help me with this. thanks.
All you need to do is remove the static width property for the containers with the shadowbox property and it should all work out.
Please review the modified example below. I modified the CSS so it is compatible with the browser as I think you copied and pasted the raw style SASS, LESS or one of those processors.
.wrapper {
position: absolute;
bottom: 32px;
width: 316px;
height: 225px;
background: white;
box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.29);
border-radius: 16px;
display: flex;
flex-direction: column;
opacity: 1;
}
.container_one {
height: 101px;
padding: 16px 6px 16px 22px;
border-radius: 16px 16px 0 0;
box-shadow: 0px 6px 6px -6px rgba(0, 0, 0, 0.29);
margin: 0px -6px 0px -6px;
}
.description {
height: 42px;
width: 289px;
margin-top: 8px;
color: black;
display: flex;
font-size: 12px;
font-weight: 400;
margin-bottom: 16px;
}
.container_two {
padding: 16px 0px 16px 10px;
max-height: 108px;
display: flex;
flex-wrap: wrap;
overflow-x: hidden;
}
.container_two > div {
margin-right: 4px;
margin-bottom: 16px;
}
.empty_div{
height: 32px;
border-radius: 0 0 16px 16px;
box-shadow: 0px -6px 6px -6px rgba(0, 0, 0, 0.29);
margin: 0px -6px 0px -6px;
}
<div class="wrapper">
<div class="container_one">//this has boxshadow that is as expected
<span class="text">sometext</span>
<div class="description">some big description</div>
</div>
<div class="container_two"> //this has boxshadow cut at right side
</div>
<div class="empty_div"/>
</div>

Why wont my css styling of background color ,width, and height work on my last div >gameover?

Why wont my css styling of background color ,width, and height work on my last div >gameover ?
this first part is my html code:
<head>
<title>Maths Game</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-
scalable=yes">
<link rel="stylesheet" href="styling.css">
</head>
<body>
<div id="container">
<div id="score">Score: <span id="scoreValue">0</span></div>
<div id="correct">Correct</div>
<div id="wrong">Try Again</div>
<div id="question">7x7</div>
<div id="instructionBox">Click on the correct answer</div>
<div id="choices">
<div id="box1" class="box">1</div>
<div id="box2" class="box">2</div>
<div id="box3" class="box">3</div>
<div id="box4" class="box">4</div>
</div>
<div id="startReset">start Game</div>
Im guessing right here below is where it started getting messed up:
<div id="timeremaining">Time remaining:<span id="timeRemainingValue">
60</span> sec</div>
<div id="gameOver">
<p>Game Over!</p>
<p>Your score is __</p>
</div>
</div>
this second part is my css code and only the last style "game over" isn't working;
html {
height: 100%;
background: radial-gradient(circle, white, grey);
}
#container {
height: 440px;
width: 550px;
background-color: #9DD2EA;
margin: 100px auto;
/* this line directly above centers the container top and bottom 100px and left and
right to auto so that margin keeps getting
bigger and bigger on both sides till the element is center */
padding: 10px;
border-radius: 20px;
/* above line curves corners of element */
box-shadow: 4px 4px 6px 6px purple;
-webkit-box-shadow: 4px 4px 6px 6px purple;
-moz-box-shadow: 4px 4px 6px 6px purple;
/* [horizontal offset] [vertical offset] [blur radius] [optional spread radius] [color]
*/
position: relative;
}
#score {
background-color: yellow;
padding: 10px;
position: absolute;
left: 475px;
box-shadow: 0px 4px purple;
-moz-box-shadow: 0px 4px purple;
-webkit-box-shadow: 0px 4px purple;
}
#correct {
position: absolute;
left: 240px;
background-color: green;
color: white;
padding: 10px;
display: none;
}
#wrong {
/* line 45 makes it to where this element does not interact with other elements and
other elements behave as if it doesent exist*/
position: absolute;
left: 240px;
background-color: red;
color: white;
padding: 10px;
display: none;
}
#question {
margin: 55px auto 10px auto;
height: 150px;
width: 420px;
background-color: rgb(184, 53, 240);
box-shadow: 0px 4px purple;
font-size: 100px;
text-align: center;
font-family: Arial, Helvetica, sans-serif, sans-serif;
line-height: 150px;
color: black;
border-radius: 5px;
position: relative;
}
#question:active {
box-shadow: 0px 0px purple;
-moz-box-shadow: 0px 0px purple;
-webkit-box-shadow: 0px 0px purple;
top: 4px
}
#instructionBox {
height: 60px;
width: 420px;
background-color: blue;
margin: 1px auto 1px auto;
text-align: center;
line-height: 55px;
box-shadow: 0px 4px purple;
-moz-box-shadow: 0px 4px purple;
-webkit-box-shadow: 0px 4px purple;
border-radius: 5px;
position: relative;
/* transition: all 0.2s; line 71 & 72 with line 77 make the transition happen on click
*/
}
#instructionBox:active {
box-shadow: 0px 0px purple;
-moz-box-shadow: 0px 0px purple;
-webkit-box-shadow: 0px 0px purple;
top: 4px;
}
#choices {
/* background-color: sandybrown; */
height: 100px;
width: 420px;
margin: 10px auto;
color: black;
text-align: center;
line-height: -50px;
margin: 10px auto;
border-radius: 5px;
}
.box {
/*these boxes are within a choices div to help them size together*/
margin-right: 26px;
width: 85px;
height: 85px;
background-color: white;
float: left;
border-radius: 5px;
cursor: pointer;
box-shadow: 0px 4px grey;
-moz-box-shadow: 0px 4px grey;
-webkit-box-shadow: 0px 4px grey;
line-height: 80px;
position: relative;
/* with position relative and .box:active { top: 4px; the box moves down 4px}*/
/* transition: all 0.2s;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-o-transition: all 0.2s;
-ms-transition: all 0.2s; */
}
.box:hover,
#startReset:hover {
background-color: grey;
color: white;
box-shadow: 0px 4px purple;
-webkit-box-shadow: 0px 4px purple;
-moz-box-shadow: 0px 4px purple;
}
.box:active,
#startReset:active {
box-shadow: 0px 0px purple;
-webkit-box-shadow: 0px 0px purple;
-moz-box-shadow: 0px 0px purple;
top: 4px;
}
/* #box1{
margin: 10px 10px;
background-color: red;
width: 30px;
height: 30px;
}
#box2{
margin: 10px 10px;
background-color: white;
width: 30px;
height: 30px;
}
#box3{
margin: 10px 10px;
background-color: blue;
width: 30px;
height: 30px;
}*/
#box4 {
margin-right: 0;
}
#startReset {
/*these boxes are within a choices div to help them size together*/
margin-left: 230px;
width: 100px;
height: 45px;
background-color: rgb(255, 255, 255, 0.5);
float: left;
border-radius: 5px;
cursor: pointer;
box-shadow: 0px 4px grey;
-moz-box-shadow: 0px 4px grey;
-webkit-box-shadow: 0px 4px grey;
line-height: 45px;
text-align: center;
position: relative;
}
/* instead of writing these same pargraphs of code just at the element id to the similar
code alrady made like above */
/* #startReset:hover{
background-color: grey;
color: white;
box-shadow: 0px 4px purple;
-webkit-box-shadow: 0px 4px purple;
-moz-box-shadow: 0px 4px purple;
}
#startReset:active{
box-shadow: 0px 0px purple;
-webkit-box-shadow: 0px 0px purple;
-moz-box-shadow: 0px 0px purple;
top: 4px;
} */
#timeremaining {
/*these boxes are within a choices div to help them size together*/
visibility: hidden;
/* display: none; */
margin-left: 10px;
width: 200px;
height: 45px;
background-color: greenyellow;
float: left;
border-radius: 5px;
cursor: pointer;
box-shadow: 0px 4px grey;
-moz-box-shadow: 0px 4px grey;
-webkit-box-shadow: 0px 4px grey;
line-height: 45px;
text-align: center;
position: relative;
}
this below is the broken part with the >gameover style or gameOver div:
#gameOver {
height: 200px;
width: 500px;
background-color: linear-gradient(blue, green);
font-size: 1.0em;
}

Why are the spans not centering within this div?

i have 2 spans within a span to center next to eachother, class inside_span up and inside_span down, they are aligned to the left of the pulse_result_format span, i have tried margin: 0 auto on the pulse result format span, does not work, and display: inline-block;
HTML:
<div class="pulse_votes_container thumb1">
<span class="pulse_vote_buttons">
</span>
<span class="pulse_result_format">
<span class='inside_span up'>{up}</span>
<span class='inside_span down'>{down}</span>
</span>
</div>
CSS:
.inside_span {
display: inline-block;
width:40%;
border-radius: 3px 3px 3px 3px;
margin: 10% auto 0px 0px;
float:left;
}
.down {
background-color:#FF6E25;
}
.up {
background-color: rgb(70, 136, 71);
}
.pulse_result_format {
display: inline-block;
float: left;
width: 100%;
text-align: center;
font-weight: bold;
color: rgb(255, 255, 255);
text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.25);
white-space: nowrap;
vertical-align: baseline;
}
.pulse_votes_container {
width:100%;
height:100%;
display: inline-block;
text-align: center;
}
Remove the float:left from .inside_span
.inside_span {
display: inline-block;
width:40%;
border-radius: 3px 3px 3px 3px;
margin: 10% auto 0px 0px;
}
jsFiddle example