I have a container with several elements inside. I want to center these elements vertically, as a group. Can this be done with flexbox and if so, how?
Here is a demo:
.container {
margin: 0 auto;
width: 700px;
height: 600px;
background: #ebebeb;
flex-direction: column;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-ms-flex-align: center;
-webkit-align-items: center;
-webkit-box-align: center;
align-items: center;
}
.btn {
display: inline-block;
padding: 5px 10px;
padding: 0.3125rem 0.625rem;
background: #129c87;
color: #fff;
border: 1px solid #999;
border-radius: 2px;
font-weight: 600;
text-align: center;
outline: none;
border: none;
cursor: pointer;
font-family: Arial;
}
<div class="container">
<h1>Center me and my paragraphs plz</h1>
<p>First paragraph is always first</p>
<p>Then comes the second</p>
<a class="btn" href="#">Read more</a>
</div>
You just need justify-content:center;
fiddle: https://jsfiddle.net/w64ks4x7/
.container {
margin: 0 auto;
width: 700px;
height: 600px;
background: #ebebeb;
flex-direction: column;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-ms-flex-align: center;
-webkit-align-items: center;
-webkit-box-align: center;
align-items: center;
justify-content:center;
}
Related
The left most item is not aligned with the rest of the items. How to i center them correctly?
.activities{
display: flex;
align-items: center;
flex-direction: column;
padding-top: 25px;
background-color: #F3FAEF;
text-align: center;
}
.activities-image{
border-radius: 50%;
width: 150px;
height: 150px;
}
.activities-header{
font-size: 18px;
font-weight: bold;
}
.activities-cols{
display: flex;
align-items: center;
text-align: center;
}
.activity-col{
border: 1px solid red;
width: 330px;
height: 330px;
}
Demo: https://codepen.io/AdanRod133/pen/jOxPBEX
Full-page: https://codepen.io/AdanRod133/full/jOxPBEX
.activity-col {
border: 1px solid red;
width: 330px;
height: 330px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
I have problem with my website.
I did responsive website with mobile menu and it's looking very good on Developere Mode with responsive and android phone but on iphone it look terrible..
Here on dev tools/android:
Here on iphone:
Code:
HTML:
<header class="header">
<div class="header-wrapper">
<div class="header-logo" id="headerLogo">
<img src="assets/images/logo_right.svg" alt="Logo company" height="70px">
</div>
<div class="header-logo header-logo--mobile">
<img class="logo-mobile" src="assets/images/logo.png" alt="Logo company" height="70px">
</div>
<div class="header-contact-container">
<div class="header-contact__item">
<div class="header-contact__icon">
<i class="gg-phone"></i>
</div>
</div>
</div>
</div>
<nav class="site-nav" id="nav__main">
<ul class="site-nav__list">
<li class="site-nav__item site-nav__item--is-hidden">
<a class="site-nav__anchor" href="#" id="mobile_nav">MENU</a>
</li>
<li class="site-nav__item">
<a class="site-nav__anchor" href="javascript: scrollSmoothTo('mainWrapper')"
id="homeNavButton">Home</a>
</li>
<li class="site-nav__item">
<a class="site-nav__anchor" href="javascript: scrollSmoothTo('aboutUs')"
id="aboutNavButton">About</a>
</li>
<li class="site-nav__item">
<a class="site-nav__anchor" href="javascript: scrollSmoothTo('services')" id="servicesNavButton">Services</a>
</li>
<li class="site-nav__item">
<a class="site-nav__anchor" href="javascript: scrollSmoothTo('contact')" id="contactNavButton">Contact</a>
</li>
</ul>
</nav>
</header>
CSS DEFAULT
.header {
display: block;
}
.header-wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
width: 65%;
padding: 30px 0;
margin: 0 auto;
}
.header-logo {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.header-logo--mobile {
display: none;
}
.header-contact-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.header-contact__item {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.header-contact__title {
font-size: 1.2rem;
text-transform: uppercase;
margin: 0 0 10px;
}
.header-contact__data {
text-align: center;
}
.header-contact__icon {
display: block;
margin-left: 15px;
height: 100%;
}
.site-nav {
height: 50px;
background: rgb(250, 255, 253);
border-top: 1px solid rgba(224, 224, 224, 0.68);
border-bottom: 1px solid rgba(224, 224, 224, 0.68);
z-index: 999;
}
.site-nav__list {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin: 0 auto;
padding: 0;
height: 100%;
list-style: none;
}
.site-nav__item--is-hidden {
display: none;
}
.site-nav__item {
width: 180px;
height: 80%;
}
.site-nav__anchor {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
height: 100%;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
color: rgb(6, 67, 62);
font-family: 'Sora', sans-serif;
font-weight: 500;
font-size: 1.1em;
text-transform: uppercase;
text-decoration: none;
-webkit-appearance: none!important;
}
.site-nav__anchor:hover {
font-size: 1.2rem;
color: #ffcc00;
}
.header-nav--sticky {
position: fixed;
top: 0;
width: 100%;
}
CSS MOBILE
.header-wrapper {
display: block;
width: 100%;
text-align: center;
}
.header-logo {
display: none;
}
.header-logo--mobile {
display: block;
padding-top: 30px;
}
.logo-mobile {
}
.header-contact-container {
display: block;
}
.header-contact__item {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
width: auto;
padding-top: 30px;
}
.header-contact__title {
font-size: 1.4rem;
}
.header-contact__data {
display: block;
/*-webkit-box-ordinal-group:3;*/
/*-ms-flex-order:2;*/
/*order:2;*/
font-size: 1.2rem;
}
.site-nav {
height: auto!important;
}
.site-nav__list {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
height: auto!important;
/*height: auto;*/
}
.site-nav__item--is-hidden {
display: block!important;
background: #FFCC00;
max-height: 100%!important;
}
.site-nav__item {
display: none;
width: 100%;
max-height: 100%!important;
}
.site-nav__anchor {
padding: 15px 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.16);
}
.site-nav__anchor:nth-child(1):hover {
font-size: 1.2rem;
color:inherit!important;
}
JS
const mobileButtonMenu = document.getElementById("mobile_nav")
mobileButtonMenu.addEventListener("click", setMobileMenu);
function setMobileMenu() {
const menu = document.querySelectorAll(".site-nav__item")
if (menu[1].style.display === "block") {
menu[1].style.display = "none";
menu[2].style.display = "none";
menu[3].style.display = "none";
menu[4].style.display = "none";
} else {
menu[1].style.display = "block";
menu[2].style.display = "block";
menu[3].style.display = "block";
menu[4].style.display = "block";
}
}
I dont know what I have to do. I think that problem may be with height:auto, because other elements with flex was be good render.
I'm working on a personal project and I have a problem with overlapping when I resize the window.
Basically until now my page is divided in 3 sections, header (which is sticky), middle/hero and last section with the products.
The problem is when I make my page less higher, the images with the coffees are overlapping the text.
My code is here:
display: grid;
grid-template-columns: repeat(auto-fit, minmax(20em, 1fr));
height: calc(100vh - 64px);
width: calc(100vw - 64px);
justify-content: center;
}
.text-section {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
font-size: 1.05em;
margin: 0 5vw 0 5vw;
padding: 0 2vw 0 2vw;
}
.text-section h2 {
font-size: 2em;
font-weight: 600;
padding-bottom: 1em;
}
/* <p> color */
.ph {
color: #3c4043;
}
.image-section {
display: flex;
align-items: center;
justify-content: center;
background-image: url(https://www.illy.com/dw/image/v2/BBDD_PRD/on/demandware.static/-/Sites-masterCatalog_illycaffe/default/dw9a7f00e7/products/Coffee/Coffee-Ground/9893ME_coffee_ground-espresso_can-classico-roast-250gr-zagnoli-decorated_illy-shop/DecoratoOZ_GroundClassico_800x800px.png);
background-repeat: no-repeat;
background-size: contain;
background-position: center;
min-height: 15em;
margin: 2vw;
}
.main-body {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
justify-content:space-between;
}
.illy,
.lavazza,
.starbucks {
display: flex;
flex-direction: column;
align-items: center;
width: 15em;
height: 25em;
}
https://codepen.io/claudiuu/full/ZEWmRzR
here is the overlap
I am trying to remove the text-decoration of a flex child when the parent is the anchor. I've tried all of the following code, and it is not working at all. I've created a jsFiddle, and on that the underline shows all the time and not on hover. In my WordPress installation, it only shows on hover. I'm really not sure what to do! Any help is appreciated!
Thank you ahead of time!!!!
.fleximagebox_link:hover, a.fleximagebox_link:hover, a .fleximagebox_link:hover,
.fleximagebox_link a:hover, .fleximagebox_link:hover a,
a .fleximagebox_link p:hover, .image_background:hover, .image_background:hover a,
a .image_background:hover, .image_background.fleximagebox_link a:hover,
a .image_background.fleximagebox_link:hover {
text-decoration: none!important;
}
Here is the jsFiddle that explains what I'm talking about: https://jsfiddle.net/Clare12345/th60mde3/2/
This will get rid of the underline in your fiddle .flexbox_images a { text-decoration: none; }
As to why it's on your website, all we can do is guess if you don't include the code or a link to your site. But you might try changing that line to .flexbox_images a, .flexbox_images a:hover { text-decoration: none !important; }
.flexbox_images a {
text-decoration: none;
}
.main_box {
background: white;
height: 400px;
width: 100%;
margin: 0 auto;
padding: 0px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
overflow: hidden;
}
.main_box .flexbox_images {
color: white;
width: 100%;
padding: 0px;
overflow: auto;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.flexbox_images a {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
width: 100%;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.image_background {
height: 250px;
margin: 0 auto;
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
max-width: 101%;
}
.image_background_left {
background-repeat: no-repeat;
background-size: contain;
background-image: url(http://pipsum.com/350x240.jpg);
justify-content: flex-end;
margin-right: -1px;
}
.image_background_right {
background-repeat: no-repeat;
background-size: contain;
background-image: url(http://pipsum.com/350x240.jpg);
justify-content: flex-start;
margin-left: -1px;
}
.fleximagebox_link {
font-size: 28pt;
background: rgba(255, 255, 255, 0.85);
color: #000!important;
text-transform: uppercase;
font-weight: 900;
letter-spacing: 1.5px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
width: 130px;
}
.image_background_left .fleximagebox_link {
justify-content: flex-end;
padding-left: 35px;
}
.image_background_right .fleximagebox_link {
justify-content: flex-start;
padding-right: 35px;
}
.image_background_right .fleximagebox_link p {
font-size: 28pt!important;
color: #000!important;
text-transform: uppercase;
font-weight: 900;
letter-spacing: 1.5px;
margin-bottom: 0px;
}
.main_black_bar {
width: 3px;
background: #000;
height: 50px;
margin-top: 15px;
margin-bottom: 15px;
margin-left: -1px;
}
.image_background_left .main_black_bar {
margin-left: 35px;
}
.image_background_right .main_black_bar {
margin-right: 35px;
}
<div class="main_box">
<div class="flexbox_images">
<a href="">
<div class="image_background image_background_left">
<div class="fleximagebox_link">Buy
<div class="main_black_bar"> </div>
</div>
</div>
</a>
<a href="">
<div class="image_background image_background_right">
<div class="fleximagebox_link">
<div class="main_black_bar"> </div>Sell</div>
</div>
</a>
</div>
</div>
I am working on an CMS, and I want to have a full 100% height.
How do I get my page a 100% height without the 100vh on the wrapper (which I am guessing this is the right way doing this).
body{
margin: 0;
font-family: arial;
}
.main-wrapper{
display: -webkit-box;
display: -moz-box;
display: box;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flexbox;
display: flex;
flex-direction: row;
height: 100vh;
overflow: hidden;
/*flex-wrap: wrap;*/
}
.main-wrapper div{
}
.sidebar1{
/*flex-direction: column;*/
/*flex-wrap: wrap;*/
/*flex: 1;*/
/*height: 100%;*/
/*width: 10px;*/
/*background-color: #29313c;*/
background-color: #29313c;
color: white;
display: flex;
flex-direction: column;
/*height: 100vh;*/
}
.sidebar1 .category{
flex: 1;
height: 100%;
padding: 10px;
display: flex;
align-items: center;
justify-content: center;
color: #90A4BB;
text-decoration: none;
font-weight: bold;
}
.sidebar1 .category:hover{
color: white;
background-color: #2E3C54;
}
.sidebar1 .category:not(:last-child){
border-bottom: 1px solid #90A4BB;
}
.sidebar1 .category div{
}
.sidebar2{
background-color: #dee3e7;
flex-wrap: wrap;
flex-direction: column;
flex-basis: 330px;
/*width: 330px;*/
/* flex: 1;
flex-wrap: wrap;
flex-direction: column;
*/
}
.main-content{
flex: 5;
flex-wrap: wrap;
flex-direction: column;
background-color: #fff;
}
<div class="main-wrapper">
<div class="sidebar1">
<a href="#" class="category">
<div>AAA</div>
</a>
<a href="#" class="category">
<div>BBB</div>
</a>
<a href="#" class="category">
<div>Banana</div>
</a>
</div>
<div class="sidebar2">
</div>
<div class="main-content">
</div>
</div>
https://jsfiddle.net/nyu1uma1/
(remove hight: 100vh)
Just give:
html,body {
height: 100%;
}
And height: 100%; to .main-wrapper
.main-wrapper{
display: -webkit-box;
display: -moz-box;
display: box;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flexbox;
display: flex;
flex-direction: row;
height: 100%;
overflow: hidden;
/*flex-wrap: wrap;*/
}
Working Fiddle