Shifted overflowing div Mozilla Firefox Margin - html

I want to code a shifted div as here:
https://codepen.io/anon/pen/VQQdaL
Relevant css:
.wrap {
display: flex;
margin: 0 auto;
max-width: 1000px;
width: 100%;
}
.box {
position: relative;
flex-shrink: 0;
background: #fff;
margin-bottom: 5%;
width: 50%;
}
.image {
flex-shrink: 0;
margin-top: 5%;
margin-left: -5%;
width: 55%;
background: linear-gradient(135deg, #fed2db, #212353);
}
this works for me just fine in Chrome/Safari but not in Firefox. Is there something I am missing?
This is what it should look like:
This is what it looks like in Firefox:
.section {
background: black;
padding: 4em 0;
}
.wrap {
display: flex;
margin: 0 auto;
max-width: 1000px;
width: 100%;
}
.box {
position: relative;
flex-shrink: 0;
background: #fff;
margin-bottom: 5%;
width: 50%;
}
.image {
flex-shrink: 0;
top: 5%;
margin-left: -5%;
width: 55%;
background: linear-gradient(135deg, #fed2db, #212353);
}
<div class="section">
<div class="wrap">
<div class="box">
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
<div class="image"></div>
</div>
</div>

The problem seems primarily due to the lack of absolute height. I couldn't produce a clean single reason for the behavior, but in the meantime, I recreated the intended result in JSFiddle. Hope this helps.
JSFiddle code:
.section {
background: black;
padding: 4em 0;
}
.wrap {
display: flex;
margin: 0 auto;
max-width: 1000px;
width: 100%;
}
.box {
position: absolute;
height: 100px;
flex-shrink: 0;
background: blue;
margin-bottom: 5%;
width: 50%;
}
.image {
position: relative;
height: 100px;
flex-shrink: 0;
background: green;
margin-top: 20px;
margin-left: 45%;
width: 55%;
background: linear-gradient(135deg, #fed2db, #212353);
}
<div class="section">
<div class="wrap">
<div class="box">
<br>
<br>
<br>
<br>
<br>
</div>
<div class="image"></div>
</div>
</div>

Related

Circle appear gap at edge

I'm playing CSS battle and trying to achieve the result perfectly, but I don't know why there is some gap at the edge of the circle as you can see on the screenshot here: Screenshot
I know there is better solution like using gradient, but I'm trying to learn to solve the problem here and improve my understanding of CSS. Below is my code:
body {
background-color: #E3516E;
}
.Container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.Circle {
width: 199px;
height: 200px;
background-color: blue;
border-radius: 50%;
overflow: hidden;
position: relative;
}
.Square {
width: 99.5px;
height: 100px;
position: absolute;
}
.Green {
background-color: #51B5A9;
}
.Yellow {
background-color: #FADE8B;
right: 0;
}
.White {
background-color: #F7F3D7;
bottom: 0;
left: 0;
}
.Transparent {
background-color: #E3516E;
bottom: 0;
right: 0;
}
<div class="Container">
<div class="Circle">
<div class="Green Square"></div>
<div class="Yellow Square"></div>
<div class="White Square"></div>
<div class="Transparent Square"></div>
</div>
</div>
There is no gap at edges. Looks like Anti-Aliasing. I have added a border to it, so that you can see there's no gap.
<div class="Container">
<div class="Circle">
<div class="Green Square"></div>
<div class="Yellow Square"></div>
<div class="White Square"></div>
<div class="Transparent Square"></div>
</div>
</div>
<style>
body {
background-color: #E3516E;
}
.Container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.Circle {
width: 199px;
height: 200px;
border-radius: 50%;
overflow: hidden;
position: relative;
}
.Square {
width: 99.5px;
height: 100px;
position: absolute;
}
.Green {
background-color: #51B5A9;
}
.Yellow {
background-color: #FADE8B;
right: 0;
}
.White {
background-color: #F7F3D7;
bottom: 0;
left: 0;
}
.Transparent {
background-color: #E3516E;
border: 1px blue solid;
bottom: 0;
right: 0;
}
</style>
A conic gradient can do it:
.box {
width: 200px;
height: 200px;
border-radius: 50%;
background: conic-gradient(#FADE8B 25%, #0000 0 50%, #F7F3D7 0 75%, #51B5A9 0)
}
body {
background: #E3516E;
}
<div class="box"></div>

Flex Container in IE 11 not aligning properly

I have a problem with the following snippet: I need to make it work in Internet Explorer 11. In Chrome, Firefox and Edge it looks like it should.
There are 3 elements (red, yellow, green), beneeth each other. Another blue element with 50% of the height is on top of the others.
This is how it should look like:
However Internet Explorer 11 puts the blue element on the right side beneeth the others and not on top of them. Can you guys help me with that problem?
This is how it looks in IE11 - it should not look like this
.wrapper {
display: block;
height: 50px;
}
.flex-wrapper {
height: 100%;
width: 100%;
position: relative;
display: flex;
margin: 2px 0;
}
.outer,
.inner {
width: 100%;
max-width: 100%;
display: flex;
}
.outer {
height: 100%;
}
.inner {
height: 30%;
align-self: center;
position: absolute;
}
.inner-element,
.outer-element {
height: 100%;
max-width: 100%;
align-self: flex-start;
}
<div class="wrapper">
<div class="flex-wrapper">
<div class="outer">
<div class="outer-element" style="width: 10%; background-color: red"></div>
<div class="outer-element" style="width: 50%; background-color: yellow"></div>
<div class="outer-element" style="width: 40%; background-color: green"></div>
</div>
<div class="inner">
<div class="inner-element" style="width: 50%; background-color: blue"></div>
</div>
</div>
</div>
The problem
The issue is that you are positioning .inner absolutely but not giving it a specific position. This means that where the browser first renders it is where it will output on screen. It seems IE handles this differently to other browsers which is why you are getting the discrepancy.
The solution
The following modifications would be required:
Add left: 0; to .inner to align it to the left of .flex-wrapper
Add top: 50%; to .inner to move it down 50% of .flex-wrapper and transform: translateY(-50%); to move it back up by 50% of its height
.wrapper {
display: block;
height: 50px;
}
.flex-wrapper {
height: 100%;
width: 100%;
position: relative;
display: flex;
margin: 2px 0;
}
.outer,
.inner {
width: 100%;
max-width: 100%;
display: flex;
}
.outer {
height: 100%;
}
.inner {
height: 30%;
align-self: center;
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
}
.inner-element,
.outer-element {
height: 100%;
max-width: 100%;
align-self: flex-start;
}
<div class="wrapper">
<div class="flex-wrapper">
<div class="outer">
<div class="outer-element" style="width: 10%; background-color: red"></div>
<div class="outer-element" style="width: 50%; background-color: yellow"></div>
<div class="outer-element" style="width: 40%; background-color: green"></div>
</div>
<div class="inner">
<div class="inner-element" style="width: 50%; background-color: blue"></div>
</div>
</div>
</div>
I would made some changes.
First:
- Position .inner
- Make it full height thanks to its position
- Make it display: flex
.inner {
position: absolute;
top: 0; bottom: 0; left: 0;
display: flex;
}
Second:
- Give a height to .inner-element
- Center it
.inner-element {
height: 30%;
align-self: center;
}
.wrapper {
display: block;
height: 50px;
}
.flex-wrapper {
height: 100%;
width: 100%;
position: relative;
display: flex;
margin: 2px 0;
}
.outer,
.inner {
width: 100%;
max-width: 100%;
display: flex;
}
.outer {
height: 100%;
}
.inner {
/*height: 30%; No need for that anymore */
/*align-self: center; No need for that anymore */
position: absolute;
top: 0;
bottom: 0;
left: 0; /* Now it's in the right position */
display: flex; /* To be able to align the inner-element */
}
.inner-element,
.outer-element {
height: 100%;
max-width: 100%;
align-self: flex-start;
}
.inner-element {
height: 30%; /* Make it the right height */
align-self: center; /* Center it */
}
<div class="wrapper">
<div class="flex-wrapper">
<div class="outer">
<div class="outer-element" style="width: 10%; background-color: red"></div>
<div class="outer-element" style="width: 50%; background-color: yellow"></div>
<div class="outer-element" style="width: 40%; background-color: green"></div>
</div>
<div class="inner">
<div class="inner-element" style="width: 50%; background-color: blue"></div>
</div>
</div>
</div>

Flex-box Row Span [duplicate]

This question already has answers here:
Calculator keypad layout with flexbox
(2 answers)
Closed 5 years ago.
I've seen some solutions for this using flex-direction: column but that was for the entire flex container. I already have a container with a row direction and wanted to know if I could make a two row div without changing the whole layout. Here's my current situation.
I'd like to combine the blank div with the div with the equal sign. Here's my code as well. Thanks a lot!
<div class="container">
<div class="headline">
JSCalc
</div>
<div class="display">
</div>
<div class="button-container">
<div class="ac all-rows row1 clear">AC</div>
<div class="ce all-rows row1 clear">CE</div>
<div class="divide all-rows row1">÷</div>
<div class="multiply all-rows row1">×</div>
<div class="seven all-rows">7</div>
<div class="eight all-rows">8</div>
<div class="nine all-rows">9</div>
<div class="subtract all-rows">-</div>
<div class="four all-rows">4</div>
<div class="five all-rows">5</div>
<div class="six all-rows">6</div>
<div class="addition all-rows">+</div>
<div class="three all-rows">3</div>
<div class="two all-rows">2</div>
<div class="one all-rows">1</div>
<div class="all-rows">
</div>
<div class="zero all-rows">0</div>
<div class="decimal all-rows">.</div>
<div class="all-rows">=</div>
</div>
</div>
CSS:
html {
background-color: #333;
}
.container {
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 20rem;
height: 30rem;
background-color: #f0f0f0;
border-radius: 3%;
}
.headline {
width: 100%;
height: 5%;
text-align: center;
font-size: 1.5rem;
margin-top: 1%;
}
.display {
height: 20%;
width: 80%;
margin: 0 auto;
background-color: #DFE2DB;
margin-top: 5%;
border: 2px solid #c6cbbf;
border-radius: 5%;
}
.button-container {
height: 75%;
width: 100%;
display: flex;
justify-content: space-around;
align-content: flex-start;
flex-wrap: wrap;
}
.all-rows {
width: 22%;
background-color: #c6c6c6;
height: 3.5rem;
display: inline-block;
margin: 1% 0 1% 0;
border-radius: 5%;
font-size: 2em;
text-align: center;
line-height: 3.5rem;
vertical-align: bottom;
}
.row1 {
margin-top: 5%;
}
.clear {
background-color: #e19ba2;
}
.zero {
width: 47%;
}
.decimal {
flex-grow: 0;
width: 22%;
}
The simplest solution is to use a pseudo and bridge the two, visually.
Add these 2 rules (and the equal class to the markup)
.equal {
position: relative;
}
.equal::before {
content: '';
position: absolute;
left: 0;
right: 0;
bottom: 90%; /* start 10% below the top to cover the rounded border */
height: 100%;
background: inherit;
}
Note, when you add the events, you need to add the "equal" event to both the equal button and the one above it.
Stack snippet
html {
background-color: #333;
}
.container {
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 20rem;
height: 30rem;
background-color: #f0f0f0;
border-radius: 3%;
}
.headline {
width: 100%;
height: 5%;
text-align: center;
font-size: 1.5rem;
margin-top: 1%;
}
.display {
height: 20%;
width: 80%;
margin: 0 auto;
background-color: #DFE2DB;
margin-top: 5%;
border: 2px solid #c6cbbf;
border-radius: 5%;
}
.button-container {
height: 75%;
width: 100%;
display: flex;
justify-content: space-around;
align-content: flex-start;
flex-wrap: wrap;
}
.all-rows {
width: 22%;
background-color: #c6c6c6;
height: 3.5rem;
display: inline-block;
margin: 1% 0 1% 0;
border-radius: 5%;
font-size: 2em;
text-align: center;
line-height: 3.5rem;
vertical-align: bottom;
}
.row1 {
margin-top: 5%;
}
.clear {
background-color: #e19ba2;
}
.zero {
width: 47%;
}
.decimal {
flex-grow: 0;
width: 22%;
}
.equal {
position: relative;
}
.equal::before {
content: '';
position: absolute;
left: 0;
right: 0;
bottom: 90%; /* start 10% below the top to cover the rounded border */
height: 100%;
background: inherit;
}
<div class="container">
<div class="headline">
JSCalc
</div>
<div class="display">
</div>
<div class="button-container">
<div class="ac all-rows row1 clear">AC</div>
<div class="ce all-rows row1 clear">CE</div>
<div class="divide all-rows row1">÷</div>
<div class="multiply all-rows row1">×</div>
<div class="seven all-rows">7</div>
<div class="eight all-rows">8</div>
<div class="nine all-rows">9</div>
<div class="subtract all-rows">-</div>
<div class="four all-rows">4</div>
<div class="five all-rows">5</div>
<div class="six all-rows">6</div>
<div class="addition all-rows">+</div>
<div class="three all-rows">3</div>
<div class="two all-rows">2</div>
<div class="one all-rows">1</div>
<div class="all-rows"></div>
<div class="zero all-rows">0</div>
<div class="decimal all-rows">.</div>
<div class="all-rows equal">=</div>
</div>
</div>
Another way is to wrap the 3/2/1/0/./ and the /=/ into 2 groups, make those wrappers flex row containers and then adjust their width's/margin's to match the rest of the buttons.

CSS overflow and white-space not working

Current Situation
Using the following code I show a couple of divs floated to the left.
* {
margin: 0;
padding: 0;
border: none;
box-sizing: border-box;
}
.container {
width: 100%;
height: 100%;
}
.header {
height: 80px;
position: fixed;
width: 100%;
background: green;
}
.inner-container {
position: absolute;
top: 80px;
left: 0px;
right: 0px;
bottom: 0px;
overflow: auto;
white-space: nowrap;
}
.column {
height: 500px;
width: 150px;
background: red;
float: left;
margin: 5px;
}
<div class="container">
<div class="header">
</div>
<div class="inner-container">
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
</div>
</div>
Current result:
Problem
What I want is that the red boxes don't wrap within its container. I want both, a vertical and horizontal scroll bar if the space is not enough. For the vertical scrollbar it works. What am I missing?
JSFiddle: https://jsfiddle.net/brainchest/j6zh400v/
A fix I found was to change the .column from being a float: left to display: inline-block. This treats each column as a "word" (like a word in text) and thus the white-space: no-wrap; applies. Otherwise, the float: left changes the way the element gets positioned.
Edited Fiddle: https://jsfiddle.net/9bo4f5pv/
Use display: flex on the parent, then flex: 0 0 150px on the columns.
* {
margin: 0;
padding: 0;
border: none;
box-sizing: border-box;
}
.container {
width: 100%;
height: 100%;
}
.header {
height: 80px;
position: fixed;
width: 100%;
background: green;
}
.inner-container {
position: absolute;
top: 80px;
left: 0px;
right: 0px;
bottom: 0px;
overflow: auto;
display: flex;
}
.column {
height: 500px;
flex: 0 0 150px;
background: red;
margin: 5px;
}
<div class="container">
<div class="header">
</div>
<div class="inner-container">
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
</div>
</div>

How can I make FireFox understand the correct height of my divs?

here is my fiddle http://jsfiddle.net/9m1Lba6u/
This works on Google Chrome and Safari and shows all the numbers from 1 to last. But in FireFox it only shows until 99. Am I missing some thing in my style sheet?
here is a shorter version off my code:
html, body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
overflow: hidden;
}
.head {
width: 100%;
height: 60px;
background-color: #CDF1F4;
}
.main-content {
width: 70%;
height: 100%;
padding-bottom: 70px;
float: right;
background-color: #BEE4F4;
overflow: auto;
box-sizing: border-box;
}
.side-bar {
width: 30%;
height: 100%;
padding-bottom: 70px;
float: left;
background-color: #E1BEF4;
overflow: auto;
box-sizing: border-box;
}
<div class="head"></div>
<div class="main-content"></div>
<div class="side-bar"></div>
Here is a simple CSS2 approch (it require couple of more wrappers though)
HTML:
<div class="head"></div>
<div class="page">
<div class="page-inner">
<div class="main-content">first
<br>1
<br>2
<br>3
<br>4
.....
<br>99
<br>100
<br>
<br>last
</div>
<div class="side-bar">first
<br>1
<br>2
<br>3
<br>4
.....
<br>99
<br>100
<br>
<br>last
</div>
</div>
</div>
CSS:
html, body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
}
body:before{
content:'';
float:left;
height: 100%;
}
.head {
width: 100%;
height: 60px;
background-color: #CDF1F4;
}
.page{position:relative;}
.page:after{content:''; display:block; clear:both;}
.page-inner{position:absolute; left:0; right:0; top:0; bottom:0;}
.main-content {
width: 70%;
height: 100%;
float: right;
background-color: #BEE4F4;
overflow: auto;
}
.side-bar {
width: 30%;
height: 100%;
float: left;
background-color: #E1BEF4;
overflow: auto;
}
.footer {
width: 100%;
height: 160px;
background-color: #F4BED6;
}
change
overflow: scroll;
in .main-content and .side-bar , It works for me