I have a jsfiddle below of 3 divs, 2 of which service-box-one & service-box-two the child service-details needs to be half the size of the parent div service-box and positioned at the bottom of the parent div service-box.
This works fine in IE, Firefox and Chrome, however, with safari, the divs empty-details and service-details don't inherit the 50% height and sit at the top of the parent div service-box instead of the bottom.
If you load the jsfiddle in IE, Firefox and Chrome you can see how it's supposed to look.
jsfiddle
.service-3col {
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-ms-flex-wrap: wrap;
-moz-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
list-style-type: none;
padding: 0;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
.service-3col>li {
overflow: hidden;
}
.service-box {
width: 33.33333%;
max-width: 33.33333%;
-webkit-box-flex: 1 1 33.33333%;
-moz-box-flex: 1 1 33.33333%;
-webkit-flex: 1 1 33.33333%;
-ms-flex: 1 1 33.33333%;
flex: 1 1 33.33333%;
padding: 0 10px;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.service-box .service-img {
min-height: 250px;
position: relative;
transition: all 0.5s ease-in-out;
background-image: url('https://wallpaperbrowse.com/media/images/random-pictures-1.jpg');
}
.service-box .service-img {
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
width: 100%;
}
.service-box .service-img .empty-details {
height: 50%;
background: transparent;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
width: 100%;
flex-direction: column;
}
.service-box-one .service-img .service-details,
.service-box-two .service-img .service-details {
height: 50%;
}
.service-box .service-img .service-details {
background: rgba(0, 102, 0, 0.8);
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
width: 100%;
flex-direction: column;
}
.service-box .service-img .service-details h1 {
text-align: center;
color: #FFF;
font-family: 'Times New Roman', Arial, Helvetica, sans-serif;
text-transform: uppercase;
margin-top: 15px;
margin-bottom: 0;
font-size: 1.6em;
}
h1 {
font-size: 2em;
margin: .67em 0;
}
.service-box-one .service-img .service-details p,
.service-box-two .service-img .service-details p {
font-size: 1.2em;
}
.service-box .service-img .service-details p,
.service-box .service-img .service-details b {
text-align: center;
color: #FFF;
margin: 0 1em 1em 1em;
}
.service-box-three .service-img .service-details {
height: 100%;
}
<div class="Zebra-section">
<div class="container">
<ul class="service-3col">
<li class="service-box service-box-one">
<div class="service-img">
<div class="empty-details">
</div>
<div class="service-details">
<h1>NO VAT!</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut commodo, odio sit amet interdum porttitor</p>
</div>
</div>
</li>
<li class="service-box service-box-two">
<div class="service-img">
<div class="empty-details">
</div>
<div class="service-details">
<h1>Surveys</h1>
<p>Buying a house?
<br> You need a survey.
</p>
<a class="Btn Btn--big">READ MORE</a>
</div>
</div>
</li>
<li class="service-box service-box-three">
<div class="service-img">
<div class="service-details">
<h1>Testimonials</h1>
<div class="testimonial-fade">
<div class="testimonial-text">
<p><em>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut commodo, odio sit amet interdum porttitor, nibh elit tempus mi, ac consequat tortor sem vitae sapien. Mauris tempus leo neque, in sollicitudin lorem venenatis ac. Vestibulum imperdiet mollis dignissim. Suspendisse vitae posuere tellus.</em></p>
<b>Chris</b>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
Add these two lines of code to your CSS:
.service-box .service-img .empty-details
{
position:relative; <-------- this
float:left; <-------- this
width:100%;
height: 50%;
background: transparent;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
flex-direction: column;
}
Those two lines should force the empty-details div and service-details div to each take a position relative to their container div and since they both have width:100% they should both occupy the whole width meaning the latter will have to go to the bottom since the top is taken.
There are other approaches, for example, if the top example didn't work you could set the service-details div to be position:absolute and bottom:0 since its parent container element now has position: relative (leave the new CSS we just addded above). And add the class .service-details under the old statement (don't erase the old CSS) like this:
.service-box-one .service-img .service-details, .service-box-two .service-img .service-details
{
height: 50%;
}
.service-details
{
position:absolute; // Container div must have position:relative
bottom:0; // No need to write px in 0px when value is 0
}
Related
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 am trying to create a webpage with a vertically and horizontally centred div, with defined height and width, split down the middle. Almost like an open book.
I have no problems with achieving this in Chrome/Firefox/Safari but cannot get this to reflect in IE11 as half of the 'book' has a greater height than the other half, which leads me to believe the 'height: 863px' property in .loginContainer is causing the issue as it looks marginally better once I move this.
Not totally sure but I think I need to specify an explicit height for the container to stop the content inside becoming squashed - simply removing this property allows the container to be too small so content looks cramped once I put text in there.
I have tried to remove the property and use padding on the content inside to create a bit of space but I don't feel this is the right approach and makes it appear totally different to the mock ups I'm following.
I have created a JSFiddle found here;
https://jsfiddle.net/e02cqdr6/2/
and think the issue lies at;
.loginContainer {
display: flex;
justify-content: flex-start;
flex-grow: 0;
flex-shrink: 1;
margin: 0 auto;
width: 1338px;
height: 863px;
border-radius: 15px;}
html,
body {
background-color: rgb(27, 27, 27);
height: 100%;
min-height: 100%;
/* for firefox */
}
.pageContainer {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
}
.loginContainer {
display: flex;
justify-content: flex-start;
flex-grow: 0;
flex-shrink: 1;
margin: 0 auto;
width: 1338px;
height: 863px;
border-radius: 15px;
}
.leftContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
text-align: center;
background-color: green;
width: 621px;
border-radius: 15px 0 0 15px;
}
.rightContainer {
display: flex;
flex-direction: column;
background-color: #ffffff;
align-items: center;
width: 717px;
border-radius: 0 15px 15px 0;
}
.titleContainer {
display: flex;
flex-direction: column;
width: 100%;
}
input {
height: 30px;
width: 220px;
padding: 0 10px 0 10px;
box-shadow: none !important;
border: 1px solid rgb(243, 241, 241);
border-radius: 15px;
background-color: rgb(243, 241, 241);
color: grey;
}
a {
font-size: 0.7rem;
color: orange;
text-decoration: none;
}
.nextBtn {
margin-top: 10px;
background-color: rgb(134, 200, 223);
color: #ffffff;
}
.assetContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
}
.descContainer {
display: flex;
flex-direction: column;
text-align: center;
width: 100%;
}
.descHeading {
margin: 0 auto;
color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 36px;
font-style: normal;
font-weight: 100;
padding-bottom: 5px;
}
.productDesc {
margin: 0 auto;
color: #fff;
font-family: Arial, Helvetica, sans-serif;
font-size: 17px;
font-style: normal;
font-weight: 100;
width: 440px;
}
.assetLogoBlack {
width: 100%;
height: 100%;
}
.logoContainer {
width: 100%;
}
.servicesLogo {
width: 30%;
}
<div class="pageContainer">
<div class="loginContainer">
<div class="leftContainer">
<div class="assetContainer">
<div class="logoContainer">
<img src="/assets/ilogo.svg" class="servicesLogo">
<img src="/assets/cslogo.svg" class="servicesLogo">
</div>
<div class="descContainer">
<p class="descHeading">Lorem ipsum dolor sit amet</p>
<p class="productDesc">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi volutpat sodales arcu id tincidunt. Ut a laoreet risus. Suspendisse potenti. Curabitur in ultricies risus. Vivamus convallis non libero commodo malesuada. Cras eu neque vulputate
lectus sagittis ullamcorper sit amet vitae ante. Integer pellentesque neque eget molestie vehicula. </p>
</div>
</div>
</div>
<div class="rightContainer">
</div>
</div>
</div>
So I expect it to look like this: https://ibb.co/T2Cc59V
but instead it looks like this: https://ibb.co/M8zZ9rs
To reiterate, the problem only exists in IE11.
Nothing stands out as obvious and I have no errors thrown so am totally stumped as to how to resolve this.
Thank you for all the input, I have ended up stripping this back to bare bones to see what is causing the issue as it does work fine on the jsfiddle. It turns out it is the white space around the asset I need to use for the background makes it appear as though it doesn't fill the parent div.
I'm trying to get even space between the font awesome icon and the paragraph of text to it's right, which is separated by a divider (in this the case, the right-border of the icon).
How can I make the space between the icon and it's border even, the same as the space between icons border and paragraph of text? I'm using flex's space-between at the moment, as well as some padding, but the space isn't evenly distributed, and it gets worse as the screen resizes.
body {
height: 100vh;
width: 100%;
}
#container {
height: 90%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
#display {
height: 76%;
width: 100%;
background-color: #ECECEC;
overflow: hidden;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.content {
display: flex;
justify-content: space-evenly;
align-items: center;
flex-direction: row;
height: 100%;
width: 95%;
}
.content i {
width: 25%;
display: flex;
justify-content: center;
align-items: center;
border-right: 1px solid black;
}
.text {
width: 50%;
justify-content: center;
align-items: center;
padding: 0 6%;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<div id="container">
<div id="display">
<div class="content">
<i class="fas fa-balance-scale fa-7x"></i>
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut scelerisque volutpat libero, at venenatis dolor rutrum vel. Donec fermentum eleifend tortor, at sollicitudin est rutrum nec. Fusce eget vehicula ex. Vestibulum semper gravida nulla, in aliquam ipsum dignissim nec.</p>
</div>
</div>
</div>
</div>
Try this.
.content i {
padding-right: 35px;
}
I am trying to build a basic user interface using flexbox, I have this so far..
body,html {
margin:0;
padding:0;
height:100%;
}
.container {
height:100%;
display:flex;
flex-direction:column;
}
.top {
flex:4;
display:flex;
background:wheat;
align-items: center;
justify-content: center;
}
.bottom {
flex:1;
background:teal;
}
.bottom_content {
display:flex;
flex-direction:column;
}
.section1 {
flex:1;
font-size:20px;
text-align:center;
}
.section2 {
flex:1;
}
.btn {
background:red;
color:white;
padding:20px;
}
<div class="container">
<div class="top">
<span>TOP CONTENT</span>
</div>
<div class="bottom">
<div class="bottom_content">
<div class="section1">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacus quam, blandit non lacus in, venenatis tempor dolor. Aliquam in lectus lacus. </span>
</div>
<div class="section2">
<div class="btn">
THIS IS A BUTTON
</div>
</div>
</div>
</div>
</div>
I am trying to achieve this...
How can I make the bottom section with equal height and make the content within it vertically and horizontally centered?
I am also planning on using fittext.js or similar to make the button and the text above fit into the flex item.
Where am I going wrong?
The problem
The issue with your current code is that .bottom is not filling the available space and that the default alignment and justification is being used.
The fix
The desired output can be achieved by doing the following:
Remove flex:1; from .section1 and .section2. This stops these divs from expanding to fill the available space
Add align-items: center; and justify-content: space-evenly; to.bottom_content. This will center align and evenly space out the .section1 and .section2 divs
Add display: flex; to .bottom. This will make .bottom expand to fit the available space
Change flex: 1; to flex: 1 0 auto; on .bottom. This will stop .bottom from reducing in size when the height of the window is small
body,
html {
margin: 0;
padding: 0;
height: 100%;
}
.container {
height: 100%;
display: flex;
flex-direction: column;
}
.top {
flex: 4;
display: flex;
background: wheat;
align-items: center;
justify-content: center;
}
.bottom {
/*Change*/
flex: 1 0 auto;
background: teal;
/*Add*/
display: flex;
}
.bottom_content {
display: flex;
flex-direction: column;
/*Add*/
align-items: center;
justify-content: space-evenly;
}
.section1 {
/*Remove*/
/*flex:1;*/
font-size: 20px;
text-align: center;
}
.section2 {
/*Remove*/
/*flex:1;*/
}
.btn {
background: red;
color: white;
padding: 20px;
}
<div class="container">
<div class="top">
<span>TOP CONTENT</span>
</div>
<div class="bottom">
<div class="bottom_content">
<div class="section1">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacus quam, blandit non lacus in, venenatis tempor dolor. Aliquam in lectus lacus. </span>
</div>
<div class="section2">
<div class="btn">
THIS IS A BUTTON
</div>
</div>
</div>
</div>
</div>
I have commented some of your code. Please Check
body,
html {
margin: 0;
padding: 0;
height: 100%;
}
.container {
height: 100%;
display: flex;
flex-direction: column;
}
.top {
flex: 4;
display: flex;
background: wheat;
align-items: center;
justify-content: center;
}
.bottom {
flex: 1;
background: teal;
}
.bottom_content {
display: flex;
flex-direction: column;
}
.section1 {
<!-- flex: 1;
-->font-size: 20px;
text-align: center;
}
.section2 {
flex: 1;
}
.btn {
background: red;
color: white;
padding: 20px;
margin-top: 25px;
}
<div class="container">
<div class="top">
<span>TOP CONTENT</span>
</div>
<div class="bottom">
<div class="bottom_content">
<div class="section1">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacus quam, blandit non lacus in, venenatis tempor dolor. Aliquam in lectus lacus. </div>
<button class="btn">
THIS IS A BUTTON
</button>
</div>
<!-- <div class="section2"> -->
<!-- <div class="btn"> -->
<!-- THIS IS A BUTTON -->
<!-- </div> -->
<!-- </div> -->
</div>
</div>
</div>
justify-content:center and display:flex is the key.
you can adjust margin as you wish,besides it should do the trick.
.bottom_content {
display: flex;
flex-direction: column;
margin-top: 20px;
}
.section2 {
flex: 1;
display: flex;
justify-content: center;
}
.btn {
background: red;
color: white;
padding: 20px;
width: fit-content;
position: absolute;
margin-top: 10px;
}
I have a layout built using flexbox, but there is one aspect I just can't seem to get to work.
I have panels which have anchor tags in them that I want to be vertically and horizontally centered, but I want the anchor tags to be 100% of the width and height of the panel so that when you click anywhere in the panel it will link you, as opposed to just clicking the link text.
Here is the HTML for a panel:
<div class="panel--link panel--one">
<a href="#" class="link">
Panel 1
</a>
</div>
And the SCSS:
.panel {
box-sizing: content-box;
flex: 1;
border: 3px solid #fff;
padding: 0px;
text-align: center;
}
.panel--link {
#extend .panel;
display: flex;
flex: 1;
justify-content: center;
align-items: center;
a.link {
text-decoration: none;
color: #fff;
text-transform: uppercase;
font-weight: 600;
font-size: 1rem;
letter-spacing: 3px;
flex: 1;
}
}
See my Codepen for the entire layout so you understand it better!
http://codepen.io/zauber/pen/BpRJQG
Thanks for the help
Don't be afraid, make anchor flexbox too:
a {
display: flex;
justify-content: center;
align-items: center;
}
and you should add align-items: stretch to parent of anchor.
Remove align-items: center from .content .panel--link and make .content .panel--link a.link a flexbox too and align it vertically using:
display: flex;
justify-content: center;
align-items: center;
See demo below:
body {
height: 800px;
}
.main {
height: 100%;
}
.content {
height: 100%;
border: 20px solid #fff;
display: flex;
box-sizing: border-box;
}
.content .column {
flex-direction: column;
width: 33.33333%;
background: #374550;
display: flex;
}
.content .panel,
.content .panel--link {
box-sizing: content-box;
flex: 1;
border: 3px solid #fff;
padding: 0px;
text-align: center;
}
.content .panel .logo,
.content .panel--link .logo {
margin: 7.5% 0px 0% 0%;
width: 80%;
}
.content .panel .blurb,
.content .panel--link .blurb {
width: 80%;
margin: 7.5% auto 0% auto;
}
.content .panel .blurb h1,
.content .panel--link .blurb h1 {
text-decoration: none;
color: rgba(255, 255, 255, 0.6);
font-weight: lighter;
line-height: 220%;
font-size: 0.85rem;
margin: 0px;
}
.content .panel .tel,
.content .panel--link .tel {
margin: 7.5% auto 5% auto;
}
.content .panel .tel h2,
.content .panel--link .tel h2 {
text-decoration: none;
color: #fff;
font-weight: 500;
font-size: 1.2rem;
margin: 0px;
}
.content .panel--link {
display: flex;
flex: 1;
justify-content: center;
/*align-items: center;*/
text-align: center;
}
.content .panel--link a.link {
text-decoration: none;
color: #fff;
text-transform: uppercase;
font-weight: 600;
font-size: 1rem;
letter-spacing: 3px;
flex: 1;
display: flex;
justify-content: center;
align-items: center;
}
#media (max-width: 768px) {
.content .column--two {
order: -1;
}
.content .column--two .panel--two {
order: -1;
}
}
.content .column--two .panel--one {
flex-grow: 1;
}
.content .column--two .panel--two {
flex-grow: 2;
background: #374550;
}
.content .column--two .panel--three {
flex-grow: 1;
}
<main class="content">
<div class="column column--one">
<div class="panel--link panel--one">
<a href="#" class="link">
Panel 1
</a>
</div>
<div class="panel--link panel--two">
<a href="#" class="link">
Panel 2
</a>
</div>
</div>
<div class="column column--two">
<div class="panel--link panel--one">
<a href="" class="link">
Panel 3
</a>
</div>
<div class="panel panel--two">
<div class="blurb">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin lectus orci, imperdiet ac auctor non, tristique eget augue. Curabitur quis gravida lorem, sed maximus purus. Nunc sit amet mollis turpis.</h1>
</div>
<div class="tel">
<h2>123 456 789</h2>
</div>
</div>
<div class="panel--link panel--three">
<a href="#" class="link">
Panel 4
</a>
</div>
</div>
<div class="column column--three">
<div class="panel--link panel--one">
<a href="#" class="link">
Panel 5
</a>
</div>
<div class="panel--link panel--two">
<a href="#" class="link">
Panel 6
</a>
</div>
</div>
</main>