I am using ReactJS. This is the Page component part
<div className="animated main">
<div className="title text">Lorem ipsum dolor sit amet consectetur </div>
<div className="image"></div>
</div>
And this is the page.css component
*{
box-sizing: border-box;
}
.main{
display: flex;
flex-wrap: wrap;
height: fit-content;
}
.title{
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
text-align: left;
font-size: 4em;
font-weight: bold;
padding: 5%;
}
.image{
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
background-image: url(../images/image1.png);
background-repeat: no-repeat;
border: 1px solid black;
position: absolute ;
}
* {
box-sizing: border-box;
}
.main {
display: flex;
flex-wrap: wrap;
height: fit-content;
}
.title {
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
text-align: left;
font-size: 4em;
font-weight: bold;
padding: 5%;
}
.image {
flex-basis: 50%;
flex-grow: 0;
flex-shrink: 0;
background-image: url(../images/image1.png);
background-repeat: no-repeat;
border: 1px solid black;
position: absolute;
}
<div class="animated main">
<div class="title text">Lorem ipsum dolor sit amet consectetur </div>
<div class="image"></div>
</div>
I am trying to position the image of the right side of the screen but it disappears whenever i add the position : relative / absolute feature.
Related
I made this layout but I can't find a way to align the circles and the text on the same line. As you can see in the first picture there's a problem both with circles and text. I'd like to achive the result you see in the 2nd picture.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.grid {
display: flex;
flex-wrap: wrap;
max-width: 980px;
width: 100%;
margin: auto;
padding-top: 5%;
padding-bottom: 5%;
}
.cell {
flex-basis: 33.3%;
display: flex;
justify-content: center;
align-items: center;
}
.cell:before {
padding-bottom: 100%;
display: block;
content: '';
}
.circle {
width: 250px;
height: 250px;
border: 0.5px solid;
border-radius: 50%;
background-position: center;
background-size: contain;
background-repeat: no-repeat;
box-shadow: 0px 0px 15px 0px;
overflow: hidden;
margin: 0 auto 1em;
}
.circle img {
width: 100%;
position: relative;
height: 100%;
}
h3 {
text-align: center;
}
.inner {
text-align: start;
padding-bottom: 15%;
}
<div class="grid">
<div class="cell">
<div class="inner">
<div class="circle" style="background-image:url('https://freight.cargo.site/t/original/i/655f74e74d3b88cc9d367ba8cccd79680c3837a84a547f9e03b6f39981f424e0/3.png');"></div>
<div class="caption">
<h3>Chiara Bersani <br> Marta Montanini</h3>
</div>
</div>
</div>
First, you will have to remove your manual line breaks <br>. Once you do this, the text can wrap automatically without having odd breaks at specific breaking points. If you want to force a line break, use horizontal padding on .caption h3.
Once you do this, just use align-items: self-start; on .grid.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.grid {
display: flex;
flex-wrap: wrap;
align-items: self-start;
max-width: 980px;
width: 100%;
margin: auto;
padding-top: 5%;
padding-bottom: 5%;
}
.cell {
flex-basis: 33.3%;
display: flex;
justify-content: center;
align-items: center;
}
.cell:before {
padding-bottom: 100%;
display: block;
content: '';
}
.circle {
width: 250px;
height: 250px;
border: 0.5px solid;
border-radius: 50%;
background-position: center;
background-size: contain;
background-repeat: no-repeat;
box-shadow: 0px 0px 15px 0px;
overflow: hidden;
margin: 0 auto 1em;
}
.circle img {
width: 100%;
position: relative;
height: 100%;
}
.caption h3 {
text-align: center;
padding: 0 2em;
}
.inner {
text-align: start;
padding-bottom: 15%;
}
<div class="grid">
<div class="cell">
<div class="inner">
<div class="circle" style="background-image:url('https://freight.cargo.site/t/original/i/655f74e74d3b88cc9d367ba8cccd79680c3837a84a547f9e03b6f39981f424e0/3.png');"></div>
<div class="caption">
<h3>Chiara Bersani Marta Montanini</h3>
</div>
</div>
</div>
<div class="cell">
<div class="inner">
<div class="circle" style="background-image:url('https://freight.cargo.site/t/original/i/655f74e74d3b88cc9d367ba8cccd79680c3837a84a547f9e03b6f39981f424e0/3.png');"></div>
<div class="caption">
<h3>Chiara Bersani Longer TEXT...........................</h3>
</div>
</div>
</div>
<div class="cell">
<div class="inner">
<div class="circle" style="background-image:url('https://freight.cargo.site/t/original/i/655f74e74d3b88cc9d367ba8cccd79680c3837a84a547f9e03b6f39981f424e0/3.png');"></div>
<div class="caption">
<h3>Chiara Bersani Marta Montanini more text lorem foo</h3>
</div>
</div>
</div>
</div>
Trying to place a button into flex container and make its height to be percentage of sibling's (.task) height. It works as expected except that button horizontally overflows parent (.task-buttons) and ancestor (.task). I have no idea why it happens.
I'd like .task-buttons to have the same width as its content and fit into .task, shrinkin .task-todo if needed. Exactly .task-todo as its parent (.task-info) may contain additional items that shouldn't be shrunk.
*,
::before,
::after {
box-sizing: border-box;
padding: 0;
margin: 0;
font-size: 22px;
}
.container {
position: relative;
left: 30%;
top: 50px;
width: 40%;
padding: 8px 16px;
border-radius: 30px;
box-shadow: 0px 1px 4px #00000029;
}
.task {
display: flex;
justify-content: space-between;
width: 100%;
}
.task-info {
display: flex;
align-items: center;
white-space: nowrap;
overflow: hidden;
}
.task-todo {
overflow: hidden;
text-overflow: ellipsis;
}
.task-buttons {
display: flex;
align-items: center;
position: relative;
}
.task-inc-button {
font-size: 18px;
color: white;
height: 80%;
aspect-ratio: 1;
border: none;
border-radius: 50%;
background-color: #9BE0DB;
cursor: pointer;
}
<div class="container">
<div class="task">
<div class="task-info">
<div class="task-todo">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis magna a sem posuere vestibulum.</div>
</div>
<div class="task-buttons">
<button type="button" class="task-inc-button">+</button>
</div>
</div>
</div>
Replace aspect-ratio: 1; with width: 20px; in .task-inc-button CSS, I hope it'll help you out. Thank You
*,
::before,
::after {
box-sizing: border-box;
padding: 0;
margin: 0;
font-size: 22px;
}
.container {
position: relative;
left: 30%;
top: 50px;
width: 40%;
padding: 8px 16px;
border-radius: 30px;
box-shadow: 0px 1px 4px #00000029;
}
.task {
display: flex;
justify-content: space-between;
width: 100%;
}
.task-info {
display: flex;
align-items: center;
white-space: nowrap;
overflow: hidden;
}
.task-todo {
overflow: hidden;
text-overflow: ellipsis;
}
.task-buttons {
display: flex;
align-items: center;
position: relative;
}
.task-inc-button {
font-size: 18px;
color: white;
height: 80%;
border: none;
border-radius: 50%;
background-color: #9BE0DB;
cursor: pointer;
width: 20px;
}
<div class="container">
<div class="task">
<div class="task-info">
<div class="task-todo">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis magna a sem posuere vestibulum.</div>
</div>
<div class="task-buttons">
<button type="button" class="task-inc-button">+</button>
</div>
</div>
</div>
I have one flexbox with two rows and min-height. The right row has another flex with 2 columns with justify-content space between.
It works perfectly fine in Chrome but it does not fill the min-height in IE. There are many questions about it but none of them worked for me. Please note I have different styles of this where image is on top, bottom or right. I need to expand both content and image to fill the entire card in IE.
Here is the code.
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.card-image {
width: 100%;
background-size: cover;
width:80px;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg");
}
<div class='card-wrap'>
<a href='#'>
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</a>
</div>
Image from IE
Its a bug in IE 10-11. In IE 10-11, min-height declarations on flex containers work to size the containers themselves, but their flex item children do not seem to know the size of their parents. They act as if no height has been set at all.
More info: https://github.com/philipwalton/flexbugs#flexbug-3
Workaround
Simply wrap the flex container (here it div with classname card) with another flex-container having flex direction column
.ie-fix-wrapper{
display: flex;
flex-direction:column;
}
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.card-image {
width: 100%;
background-size: cover;
width:80px;
height: 100%;
background-repeat: no-repeat;
background-position: 50% 50%;
background-image: url("https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg");
}
<div class='card-wrap'>
<a href='#'>
<div class="ie-fix-wrapper">
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</div>
</a>
</div>
The solution provided by #Soothran works well. There is also alternative solution that is quicker to implement - inherit min-height in the children. In this case of the code above:
.image-wrap {
min-height: inherit;
}
.card-content {
min-height: inherit;
}
.card-wrap {
display: block;
position: relative;
}
a {
display: block;
}
.card-image-left {
flex-direction: row;
}
.card {
box-sizing: border-box;
display: flex;
border: 1px solid black;
min-height: 200px;
}
.card-content {
min-height: inherit;
padding: 12px;
display: flex;
flex-direction: column;
justify-content: space-between;
flex-grow: 1;
}
.card-text {
font-size: 0.875rem;
color: #1D1D1D;
}
.card-footer {
margin-top: 12px;
}
.card-image-wrap {
overflow: hidden;
position: relative;
}
h3 {
font-size: 1.25rem;
font-weight: 500;
margin: 0 0 4px 0;
}
.image-wrap {
min-height: inherit;
}
.card-image {
width: 100%;
width:80px;
height: 100%;
background: black;
}
<div class='card-wrap'>
<a href='#'>
<div class='card card-image-left'>
<div class='image-wrap'>
<div class='card-image'>
</div>
</div>
<div class='card-content'>
<div class='card-header'>
<h3>test title</h3>
<div class='card-text'>test subtitlte</div>
</div>
<div class='card-footer'>
<div>
<div class='card-footer-monetary'>1000</div>
</div>
</div>
</div>
</div>
</a>
</div>
You need to wrap any flex-direction:column inside a flex-direction:row
(or just display:flex for simple)
I am trying to design a landing page where different sections have different background-colors. The first section container (brown background) is a Flexbox to position the child elements. Below the first section comes another container (blue background) that also spans the whole width of the page.
Problem: There is some whitespace between the two containers, that I can't remove.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
}
.section-container {
background: #8EB8E5;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
JSFiddle: https://jsfiddle.net/z4oecan1/
Your <h3> elements have a default margin; remove it. use padding on the <h3> instead if you need to push it down.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
margin: 0;
}
.section-container {
background: #8EB8E5;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
Another option is to leave the margins as-is and add overflow:auto to the section-container div to fix the collapsed margins.
body {
margin: 0;
}
.about-container {
width: 100%;
height: 490px;
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
background: #605B56;
}
#title {
font-size: 28px;
font-weight: 200;
color: #8EB8E5;
}
.pic {
width: 200px;
height: 200px;
border-radius: 50%;
background: #8EB8E5;
}
p {
text-align: right;
color: $white;
}
h3 {
text-align: center;
}
.section-container {
background: #8EB8E5;
overflow:auto;
}
<div class="about-container">
<div class="about-text">
<h3 id="title">Title</h3>
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="pic"></div>
</div>
<div class="section-container">
<h3>
Section Title
</h3>
Some text for the next section
</div>
It's due to the default margin-top of the h3 in the second section, which exceeds its container (collapsing margins....)
To avoid that, set margin-top: 0 for that h3, and to recreate the space above it, add a padding-top to it.
https://jsfiddle.net/031p3m04/1/
I have a page that has three main section:
project-arrow-box
white-green
light-gray
project-arrow-box and light-gray are on the left side of the page and white-green is on the right. I am wanting light-gray and white-green's bottom to meet at the same point and touch my footer. My white-green's section will change size based if validation errors are made or whatever the case may be. On different screen sizes these two divs (light-gray and white-green) very in placement. Sometimes light-gray surpasses white-green and vise versa. Again, I want the end/bottom of those two divs to touch my footer regardless of the screen size.
I have tried adding bottom: 0; to both of light-gray and white-green, but this did not help. I have white-green's height set to auto, so it adapts to the expanding nature of this div. This happened before the footer, so the footer has nothing to do with any of these issues.
What can I do so this becomes possible?
.project_arrow_box {
position: relative;
/*background: rgb(69,186,149);*/
background: #00a16d;
border: 4px solid #00a16d;
width: 33%;
height: 800px;
z-index: 99;
}
#project-content-wrap {
margin: 30% 13%;
}
.white-green {
background-color: rgb(241, 250, 247);
width: 66.56%;
height: auto;
z-index: 55;
margin-left: 33.4%;
margin-right: 0;
position: absolute;
top: 0;
right: 0;
text-align: center;
}
#white-green-section {
position: relative;
left: 30%;
text-align: center;
opacity: 0;
}
.light-gray {
background-color: #E0E0E0;
width: 33.5%;
padding-top: 150px;
bottom: 0;
margin-bottom: 0;
}
.light-gray-container {
left: 15%;
position: relative;
width: 80%;
height: auto;
padding-bottom: 40px;
}
<div class="project_arrow_box">
<div id="project-content-wrap">
</div>
</div>
<div class="white-green">
<div id="white-green-section">
</div>
</div>
<div class="light-gray">
<div class="light-gray-container">
</div>
</div>
You can do this with Flexbox
body, html {
margin: 0;
padding: 0;
}
.container {
display: flex;
}
.left {
display: flex;
flex-direction: column;
flex: 0 0 33%;
}
.one {
background: #A1EB88;
flex: 100vh;
}
.two {
flex: 100vh;
background: #F2BB7C;
}
.three {
background: lightblue;
flex: 1;
}
footer {
height: 50px;
background: red;
width: 100%;
}
<div class="container">
<div class="left">
<div class="one">One</div>
<div class="two">Two</div>
</div>
<div class="three">Three</div>
</div>
<footer>Footer</footer>
Using Flexbox is likely the simplest way to pull that off:
HTML:
<div class="container">
<div class="left-container">
<div class="project-arrow-box">
<p>
</p>
</div>
<div class="light-grey">
<p>
</p>
</div>
</div>
<div class="white-green">
<p>
</p>
</div>
</div>
<div class="footer">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos, vero?
</p>
</div>
CSS:
.container, .left-container, .white-green {
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6, BB7 */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Safari 6.1+. iOS 7.1+, BB10 */
display: flex; /* NEW, Spec - Firefox, Chrome, Opera */
margin: 0;
}
.left-container {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
flex-direction: column;
}
.project-arrow-box {
background-color: white;
flex-grow: 1;
padding: 1em;
}
.light-grey {
background-color: #aaa;
flex-grow: 1;
padding: 1em;
}
.white-green {
background-color: #ccFFcc;
flex-grow: 1;
padding: 1em;
}
.footer {
background-color: #000;
color: #fff;
}
See: https://jsfiddle.net/bL2ymhps/1/