Here's a quick mockup of a layout that I'd like to build:
How would you do this? I've been playing around with flexbox-based solutions for a bit, but I haven't been able to make it work yet.
Some additional caveats:
To make the design responsive, I want to use some Bootstrap-like grid system to split the items over multiple rows on smaller screens. I'm currently using Pure CSS, but I'm open to alternatives including custom media queries.
Ideally I'd load the icons inside the bubbles from SVG assets. I know I can make four bubble-shaped icons, pop 'em in as <img> tags and then horizontally center them with the text, but that's probably not the most elegant solution.
The four "icon with description" columns should be vertically centered towards one another. Although this is not visible here, it'll affect the layout when the text doesn't line up as neatly as in my mockup.
Check this StackBlitz: FlexBox example
In the example I'm using flexbox. If you change the size of the browser window you will see how the icons break down into the next line (responsive).
HTML file:
<div class="container">
<div class="item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x icon-background"></i>
<i class="fa fa-lock fa-stack-1x"></i>
</span>
<p>Description</p>
</div>
<div class="item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x icon-background"></i>
<i class="fa fa-lock fa-stack-1x"></i>
</span>
<p>Description</p>
</div>
<div class="item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x icon-background"></i>
<i class="fa fa-lock fa-stack-1x"></i>
</span>
<p>Description</p>
</div>
<div class="item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x icon-background"></i>
<i class="fa fa-lock fa-stack-1x"></i>
</span>
<p>Description</p>
</div>
</div>
CSS file:
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
.item {
display: flex;
flex-direction: column;
align-items: center;
}
.icon-background {
color: #c0ffc0;
}
I really enjoy using flexbox, and I think it is not necessary to use bootstrap or other frameworks. Just using flexbox you have a responsive layout with few lines.
I used the <img> tag, but you can use the CSS tag background.
Just look at this simple example that I have done. Starting with it you can adapt to your mockup can do whathever it's necessary.
.father {
padding: 0;
margin: 0;
list-style: none;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
justify-content: space-around;
}
.element {
color: #000;
text-align: center;
}
.element .element-circle {
border-radius: 50%;
overflow: hidden;
background-color: #fdcb6e;
padding: 2rem;
}
.element .element-image {
background: url('https://image.flaticon.com/icons/svg/149/149315.svg');
width: 80px;
height: 80px;
padding: 15px;
}
.element p {
font-weight: bold;
}
<div class="father">
<div class="element">
<div class="element-circle"><div class="element-image"></div></div>
<p>Lorem Ipsum</p>
<span>Subtitle</span>
</div>
<div class="element">
<div class="element-circle"><div class="element-image"></div></div>
<p>Lorem Ipsum</p>
<span>Subtitle</span>
</div>
<div class="element">
<div class="element-circle"><div class="element-image"></div></div>
<p>Lorem Ipsum</p>
<span>Subtitle</span>
</div>
<div class="element">
<div class="element-circle"><div class="element-image"></div></div>
<p>Lorem Ipsum</p>
<span>Subtitle</span>
</div>
</div>
More info of flexbox you can find in this guide.
Related
this is for sure a common question but text-align and display properties are not solving it, so i must have some mistake.
What should i do to display the 3 items in the same horizontal line?
.contact__information {
vertical-align: middle;
margin-bottom: var(--mb-1);
padding-right: var(--mb-.75);
align-items: right;
text-align: center;
display: inline-flex;
margin-left: auto;
margin-right: auto;
}
<section class="contact section" id="contact">
<h2 class="section__title">Contacte</h2>
<span class="section__subtitle">Contacte para mais informações</span>
<div class="contact__information">
<i class="uil uil-phone contact__icon"></i>
<div>
<h3 class="contact__title">Telemóvel</h3>
<span class="contact__subtitle">999-777-666</span>
</div>
</div>
<div class="contact__information">
<i class="uil uil-envelope contact__icon"></i>
<div>
<h3 class="contact__title">Email</h3>
<span class="contact__subtitle">email.com</span>
</div>
</div>
<div class="contact__information">
<i class="uil uil-map-marker contact__icon"></i>
<div>
<h3 class="contact__title">Morada</h3>
<span class="contact__subtitle">Portugal</span>
</div>
</div>
</section>
Step 1: Define width
Step 2: Locate parent to flex - #contact
Step 3: align-items: center; makes all elements inline (aligned)
Step 4: justify-content: space-evenly; spaces all elements evenly. Using up extra space.
#contact {
width: 100%;
display: flex;
align-items: center;
justify-content: space-evenly;
}
<section class="contact section" id="contact">
<h2 class="section__title">Contacte</h2>
<span class="section__subtitle">Contacte para mais informações</span>
<div class="contact__information">
<i class="uil uil-phone contact__icon"></i>
<div>
<h3 class="contact__title">Telemóvel</h3>
<span class="contact__subtitle">999-777-666</span>
</div>
</div>
<div class="contact__information">
<i class="uil uil-envelope contact__icon"></i>
<div>
<h3 class="contact__title">Email</h3>
<span class="contact__subtitle">email.com</span>
</div>
</div>
<div class="contact__information">
<i class="uil uil-map-marker contact__icon"></i>
<div>
<h3 class="contact__title">Morada</h3>
<span class="contact__subtitle">Portugal</span>
</div>
</div>
</section>
Feels like an opportunity for flex. I added borders and padding just to make it obvious what was where and did some alignment you can customize as needed
.contact.section {
display: flex;
flex-direction: row;/* or column if you want the first two on top */
justify-content: flex-start;
align-items: center;
}
.contact__information,
.contact__information div { /*probably need a class for the div */
display: flex;
flex-direction: row;
justify-content: center;
border: solid 1px lime;
padding:0.25rem;
}
.contact__information div {
display: flex;
flex-direction: column;/* or row if titles are in line with data */
border: solid 1px pink;
}
.contact__title {
border: solid blue 1px;
padding: 0.5rem;
align-self: center;
}
.contact__subtitle {
border: solid #8d8dff 1px;
padding: 0.5rem;
align-self: center;
}
<section class="contact section" id="contact">
<h2 class="section__title">Contacte</h2>
<span class="section__subtitle">Contacte para mais informações</span>
<div class="contact__information">
<i class="uil uil-phone contact__icon"></i>
<div>
<h3 class="contact__title">Telemóvel</h3>
<span class="contact__subtitle">999-777-666</span>
</div>
</div>
<div class="contact__information">
<i class="uil uil-envelope contact__icon"></i>
<div>
<h3 class="contact__title">Email</h3>
<span class="contact__subtitle">email.com</span>
</div>
</div>
<div class="contact__information">
<i class="uil uil-map-marker contact__icon"></i>
<div>
<h3 class="contact__title">Morada</h3>
<span class="contact__subtitle">Portugal</span>
</div>
</div>
</section>
How move third element down, that first block with logo, and second other full width contain another panel,and down will be another panel?
this block (pastenow.ru/57IX6) need to move and it must be like this : pastenow.ru/57IXE
<nav class="navbar">
<!--start of top_panel-->
<div class="logo"><img src="img/logo.png" alt=""> </div>
<div class="panel">
<div class="nav_title">С нами ловят все!</div>
<div class="phone">8 800 553535</div>
<div class="address_wrapper">
<div class="address">Павлодар, ул. Мира 7</div>
<div class="address">Павлодар, ул. Мира 8</div>
</div>
<div class="call_btn def_btn">Заказать звонок</div>
</div>
<!--end of top_panel-->
<!--start of bottom_panel-->
<div class="bottom_panel">
<div class="main">Главная</div>
<div class="about_us">компании</div>
<div class="tournament">Турниры</div>
<div class="goods">Товары</div>
<div class="news">Новости</div>
<div class="photo">Фото</div>
<div class="video">Видео</div>
<div class="contact">Контакты</div>
<div class="social_icons_wrapper">
<div ><i class="fa fa-youtube icon_size" aria-hidden="true"></i></div>
<div ><i class="fa fa-instagram icon_size" aria-hidden="true"></i></div>
<div ><i class="fa fa-vk icon_size" aria-hidden="true"></i></div>
<div ><i class="fa fa-whatsapp icon_size" aria-hidden="true"></i></div>
<div><i class="fa fa-telegram icon_size" aria-hidden="true"></i></div>
</div>
</div>
<!--end of bottom_panel-->
if add flex-wrap: wrap; so all goes down, but i need only one.
css
.container{
width: 1170px;
height: auto;
min-height: 100vh;
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: auto;
font-family: "Museo Cyrl 900";
}
.header_line{
width: 100%;
height: 122px;
background-color: #fff;
}
.navbar{
width: 100%;
display: inline-flex;
justify-content: space-between;
}
.logo{
width: 200px;
height: auto;
}
.panel{
width: 100%;
display: inline-flex;
justify-content: space-between;
}
.bootom_panel{
width: 100%;
display:inline-flex;
justify-content: flex-end;
}
I have made a codepen demo with slight adjustments in the layout which you have provided. Please click on this link: https://codepen.io/ArunK_UI/pen/qwbXLm?editors=1100
Major change here is I have wrapped upper panel and lower panel in one wrapper and then gave them respective properties.
<div class="panel-wrap">
<div class="panel"></div>
<div class="bottom_panel"></div>
</div>
I have a few divs that act as lists/buttons on my page.
Each div contains an icon and a text.
I need to keep these 'buttons' in the center of the page but at the same time, I have to align the icons and texts under eachother.
So all the icons are under eachother AND all the texts are under eachother.
This is what I have so far:
code
https://jsfiddle.net/sy21m4dq/
.list{
width:100%;
text-align:center;
}
.list-item{
display:inline-block;
width:250px;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="list">
<div class="list-item">
<i class="fa fa-user" aria-hidden="true"></i> Account
</div>
<div class="list-item">
<i class="fa fa-sign-in" aria-hidden="true"></i> Account LOGIN
</div>
<div class="list-item">
<i class="fa fa-star" aria-hidden="true"></i> freedback
</div>
<div class="list-item">
<i class="fa fa-question" aria-hidden="true"></i> Help
</div>
</div>
This is what I am looking to achieve:
could someone please advice on this?
Thanks in advance.
I'd improve your markup structure and leverage a CSS layout option, such as display table, among others.
My suggestion is to have additional layers of markup for the various CSS layout concerns you have / need.
<div class="list">
<div class="list-container">
<div id="list-item">
<div class="list-item-cell"><i class="fa fa-user" aria-hidden="true"></i></div>
<div class="list-item-cell">Account</div>
</div>
<div id="list-item">
<div class="list-item-cell"><i class="fa fa-star" aria-hidden="true"></i></div>
<div class="list-item-cell">freedback</div>
</div>
<div id="list-item">
<div class="list-item-cell"><i class="fa fa-question" aria-hidden="true"></i></div>
<div class="list-item-cell">Help</div>
</div>
<div id="list-item">
<div class="list-item-cell"><i class="fa fa-sign-in" aria-hidden="true"></i></div>
<div class="list-item-cell">Account LOGIN</div>
</div>
</div>
</div>
In this way, you can leverage the type of layout styles you want in a cleaner fashion. Your markup is your skeleton. If you have too few bones, your design will be more limited.
.list{
width:100%;
text-align:center;
}
.list-container {
display: table;
max-width: 400px;
margin: 0 auto;
}
.list-item{
display: table-row;
width:250px;
}
.list-item-cell {
display: table-cell;
}
.list-item-cell:first-child {
padding-right: 10px;
width: 30px;
}
There's a few things going on that I will explain, but the below snippet works.
You had the divs with id="list-item", which was a typo. They needed to be class="list-item".
You had the .list-item as inline-block, but really they should be block, and the container (the .list div) should be set to the 250px width.
A little icing on the cake to make the icons / text really line up was to apply some width to the icons (.list-item .fa).
body{
text-align: center;
}
.list {
display: inline-block;
width: 150px;
}
.list-item {
display: block;
width: auto;
text-align: left;
}
.list-item .fa {
width: 30px;
text-align: center;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="list">
<div class="list-item">
<i class="fa fa-user" aria-hidden="true"></i> Account
</div>
<div class="list-item">
<i class="fa fa-sign-in" aria-hidden="true"></i> Account LOGIN
</div>
<div class="list-item">
<i class="fa fa-star" aria-hidden="true"></i> freedback
</div>
<div class="list-item">
<i class="fa fa-question" aria-hidden="true"></i> Help
</div>
</div>
Add a fixed width to the icons
i {
width: 20px;
text-align: center;
}
Make the list an inline-flex-container with columns-display
Center the whole box with either text-align-center or flex
https://jsfiddle.net/qw2f3ojt/
I'm attempting to create a footer for my first page in Bootstrap and it looks fine except the contents should be centered vertically. After inspecting the elements in Chrome, it looks like the actual container element is about 50% the height of the parent footer element.
Now I was able to partially fix this by setting the "line-height" to match the "height" property of the footer, but when doing so, it caused part of the contents to appear well below the footer. What am I doing wrong and how can I fix this?
Without Line-Height:
With Line-Height:
<!-- Site footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-sm-6">
<p>
Home | About Us | Contact
<br />
© Website 2016. All rights reserved.
</p>
</div>
<div class="col-sm-6">
<p class="muted pull-right">
<i id="social-fb" class="fa fa-facebook-square fa-2x social"></i>
<i id="social-tw" class="fa fa-twitter-square fa-2x social"></i>
<i id="social-gp" class="fa fa-google-plus-square fa-2x social"></i>
<i id="social-em" class="fa fa-envelope-square fa-2x social"></i>
</p>
</div>
</div>
</div>
</footer>
CSS
footer
{
height: 100px;
background:#fff;
margin-top:20px;
line-height: 100px;
}
You can use display:flex + align-items:center to achieve that.
footer
{
height: 100px;
background:#fff;
margin-top:20px;
display:flex;
align-items:center;
}
jsfiddle
Try adding padding-top and padding-bottom instead of line-height:
footer
{
height: 100px;
background:#fff;
padding: 2% 0;
}
You can use table properties for vertical alignment.
HTML:
<!-- Site footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-sm-6">
<p>
Home | About Us | Contact
<br />
© Website 2016. All rights reserved.
</p>
</div>
<div class="col-sm-6">
<p class="muted pull-right">
<i id="social-fb" class="fa fa-facebook-square fa-2x social"></i>
<i id="social-tw" class="fa fa-twitter-square fa-2x social"></i>
<i id="social-gp" class="fa fa-google-plus-square fa-2x social"></i>
<i id="social-em" class="fa fa-envelope-square fa-2x social"></i>
</p>
</div>
</div>
</div>
</footer>
CSS:
footer {
background:#fff;
margin-top:20px;
}
footer p {
margin: 0;
}
footer .container .row {
display: table;
width: 100%;
height: 100px;
}
footer .container .row > div {
display: table-cell;
vertical-align: middle;
float: none;
}
Working example: https://jsfiddle.net/62shy0ob/1
I have three .well items on my homepage, and I don't want to fill them with content just to ensure they size correctly on every screen. Ideally I'd like a CSS solution that can specify their height and width match each other regardless of which screen they are being displayed on (and also that they stack correctly when the window shrinks.
/* CSS used here will be applied after bootstrap.css */
#benefit-box-1 {
padding-top: 1em;
display: inline-block;
text-align: center;
float: left;
}
#benefit-box {
padding-top: 1em;
display: inline-block;
text-align: center;
float: left;
}
#benefit-box-3 {
padding-top: 1em;
display: inline-block;
text-align: center;
float: left;
}
#benefit-row-2 {
margin-top: 1px;
}
.icon-div {
display:inline-block;
text-align: centre;
vertical-align: bottom;
width: 100%;
height: 100%;
}
.icon-div:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em; /* Adjusts for spacing */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row" id="benefit-row">
<div class="col-md-4" id="benefit-box-1">
<div class="well">
<div class="icon-div">
<i class="fa fa-users fa-4x"></i>
<h1>Collaborate in your sales meetings.</h1>
</div>
</div>
</div>
<div class="col-md-4" id="benefit-box">
<div class="well">
<div class="icon-div">
<i class="fa fa-map-signs fa-4x"></i>
<h1>Direct your team to the best deals</h1>
</div>
</div>
</div>
<div class="col-md-4" id="benefit-box-3">
<div class="well">
<div class="icon-div">
<i class="fa fa-filter fa-4x"></i>
<h1>Trust your pipeline forecast</h1>
</div>
</div>
</div>
</div>
<div class="row" id="benefit-row-2">
<div class="col-md-4" id="benefit-box-1">
<div class="well">
<div class="icon-div">
<i class="fa fa-bullseye fa-4x"></i>
<h1>Helps you target the right contacts</h1>
</div>
</div>
</div>
<div class="col-md-4" id="benefit-box">
<div class="well">
<div class="icon-div">
<i class="fa fa-graduation-cap fa-4x"></i>
<h1>In-built sales training</h1>
</div>
</div>
</div>
<div class="col-md-4" id="benefit-box-3">
<div class="well">
<div class="icon-div">
<i class="fa fa-line-chart fa-4x"></i>
<h1>Smash your sales targets</h1>
</div>
</div>
</div>
</div>
</div>
I made a bootply here: My attempts
I managed to solve this issue by dropping the wells/bootstrap standard responsive behaviour and adopting some of my own using the Flex methods. If anyone is interested here's the bootply: Flex CSS classes to make responsive pages
I used the info present here in order to make this work - standard behaviour on my boxes is to have 33% of the screen width on large devices, 50% on medium devices and 100% on small devices. Works a charm.
From what I can tell it's not going to be very useful on older browsers (I don't particularly care for my project) but on modern browsers it works just as planned.