Padding-bottom/top hack for responsive blocks with different widths - html

Good day.
I have the following task: I want to build a grid of cards (for example - news), which will keep their proportions with a change of browser's width. For this reason I decided to use aspect-ratio hack for setting card's height (setting padding-top).
This solution works fine for cards with the same width. But my design uses ordinary cards and double.
I chose the "desktop-first" strategy. So my goal is to save cards' proportions with start height - 300px.
So, in my design, I have ordinary card with start size: width: 380px and height: 300px. And double card with start size: width: 780px and height: 300px.
For each case I counted the values for padding-top. For ordinary card: 300/380 = 0,7894736842105263, so padding-top: 78.94836842105263%. For double card: 300/780 = 0,3846153846153846, so padding-top: 38.46153846153846%.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: sans-serif;
background-color: #f0f0f0;
color: #323232;
}
.container {
max-width: 1600px;
margin-right: auto;
margin-left: auto;
padding-left: 10px;
padding-right: 10px;
}
.row {
margin: 0 -10px;
}
.row::before, .row::after {
display: table;
content: '';
}
.row::after {
clear: both;
}
.col {
float: left;
width: 100%;
padding: 0 10px;
}
#media (min-width: 768px) {
.col--regular {
width: 50%;
}
}
#media (min-width: 920px) {
.col--regular {
width: 33.3333%;
}
.col--doubled {
width: 66.6666%;
}
}
#media (min-width: 1220px) {
.col--regular {
width: 25%;
}
.col--doubled {
width: 50%;
}
}
.card {
position: relative;
margin-bottom: 20px;
background-position: center;
background-size: cover;
}
.card__title {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 10px;
font-size: 18px;
font-weight: 700;
}
.card--regular {
padding-top: 78.94836842105263%;
}
.card--doubled {
padding-top: 38.46153846153846%;
}
<div class="container">
<div class="row">
<div class="col col--doubled">
<div class="card card--doubled" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Big card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
</div>
</div>
But if you look at the working example, you will see that double card has a greater height than regular when we change browser's width. So this breaks the grid.
Please tell me what my mistake is. Or how to solve this situation.
Link to example: https://codepen.io/dimitrysh/pen/jZBOzJ
UPD: developers from https://ru.insider.pro/ managed to achieve such result. Please check this "example".
Thank you in advance!

Interesting question ...
If you want the heights to be exactly equal, you need to calculate them the same way. So, lets make col--doubled the same width than col--regular.
Now, the padding trick wroks the same for both.
The car--doubled will need to have width: 200%. And we need to adjust the spacing, setting an adequate margin to col-doubled.
On a side note: May be you could consider switching to a grid display.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: sans-serif;
background-color: #f0f0f0;
color: #323232;
}
.container {
max-width: 1600px;
margin-right: auto;
margin-left: auto;
padding-left: 10px;
padding-right: 10px;
}
.row {
margin: 0 -10px;
}
.row::before, .row::after {
display: table;
content: '';
}
.row::after {
clear: both;
}
.col {
float: left;
width: 100%;
padding: 0 10px;
}
#media (min-width: 768px) {
.col--regular {
width: 50%;
}
}
#media (min-width: 920px) {
.col--regular {
width: 33.3333%;
}
.col--doubled {
width: 33.3333%;
margin-right: 33.33%;
}
}
#media (min-width: 1220px) {
.col--regular {
width: 25%;
}
.col--doubled {
width: 25%;
margin-right: 25%;
}
}
.card {
position: relative;
margin-bottom: 20px;
background-position: center;
background-size: cover;
}
.card__title {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 10px;
font-size: 18px;
font-weight: 700;
}
.card--regular, .card--doubled {
padding-top: 78.94836842105263%;
}
.card--doubled {
width: calc(200% + 20px);
}
<div class="container">
<div class="row">
<div class="col col--doubled">
<div class="card card--doubled" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Big card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular" style="background-image: url('https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80');">
<div class="card__title">
Regular card title
</div>
</div>
</div>
</div>
</div>

I found, as it seems to me, a flexible solution of the problem.
The trick is to use the flexbox module for strings.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: sans-serif;
background-color: #f0f0f0;
color: #323232;
}
.container {
max-width: 1180px;
margin-right: auto;
margin-left: auto;
padding-left: 10px;
padding-right: 10px;
}
.row {
margin: 0 -10px;
}
.row::before, .row::after {
display: table;
content: '';
}
.row::after {
clear: both;
}
.col {
float: left;
width: 100%;
padding: 0 10px;
overflow: hidden;
}
#media (min-width: 768px) {
.col--regular {
width: 50%;
}
}
#media (min-width: 920px) {
.col--regular {
width: 33.3333%;
}
.col--double {
width: 66.6666%;
}
}
#media (min-width: 1220px) {
.col--regular {
width: 25%;
}
.col--double {
width: 50%;
}
}
.card {
position: relative;
margin-bottom: 20px;
background-position: center;
background-size: cover;
background-image: url("https://images.unsplash.com/5/unsplash-kitsune-4.jpg?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=bc01c83c3da0425e9baa6c7a9204af81&auto=format&fit=crop&w=1350&q=80");
overflow: hidden;
}
.card__title {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: 10px;
font-size: 18px;
font-weight: 700;
}
.card--regular {
padding-top: 78.94836842105263%;
}
.card--double {
padding-top: 38.46153846153846%;
}
.flex-container {
width: 100%;
}
.flex-container .flex-row {
width: 100%;
display: flex;
justify-content: flex-start;
align-items: stretch;
flex-wrap: wrap;
}
<div class="container flex-container">
<div class="row flex-row">
<div class="col col--double">
<div class="card card--double">
<div class="card__title">
Big card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular">
<div class="card__title">
Regular card title
</div>
</div>
</div>
<div class="col col--regular">
<div class="card card--regular">
<div class="card__title">
Regular card title
</div>
</div>
</div>
</div>
</div>
Pay attention to css-classes flex-container, flex-row.
Thus we will stretch the cards according to the height of the highest card.

Related

Can't apply margin-top to some items while being able to apply margin-bottom to every item

I have a grid of items and I'm looking to add two Titles (i.e. class="work-category"), first at the beginning of the grid, and second, in the middle of the grid.
I'd like to add margin-top and margin-bottom to both Titles. However, while I can apply margin-bottom to both Titles, I CANNOT add margin-top to the second Title. I CAN add margin-top to the first Title.
See the image for clear demonstrations of the issue:
enter image description here
I'd like to add margin-top to the second Title, as well. How to fix this problem?
.portfolio {
list-style: none;
margin-left: auto;
margin-right: auto;
}
.container {
width: 1170px;
}
.row {
margin-left: -15px;
margin-right: -15px;
}
.work-category {
padding: 0 30px;
margin-top: 50px;
margin-bottom: 50px;
}
.portfolio .one-col {
padding: 0px 30px;
}
.col-md-4 {
width: 50px;
float: left;
}
.footer {
clear: both;
position: relative;
bottom: 0px;
width: 100%;
padding-top: 104px;
margin-top: -27px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<div class="portfolio">
<div class="container">
<div class="row">
<div class="work-category">Title 1</div>
<div class="col-md-4 one-col">...</div>
<div class="col-md-4 one-col">...</div>
<div class="col-md-4 one-col">...</div>
<div class="col-md-4 one-col">...</div>
<div class="work-category">Title 2</div>
<div class="col-md-4 one-col">...</div>
<div class="col-md-4 one-col">...</div>
<div class="col-md-4 one-col">...</div>
<div class="col-md-4 one-col">...</div>
<div class="footer">...</div>
</div>
</div>
</div>
From your snippet, there is no margin-top on any of the titles. The reason why your margin-top is not being applied is simply because Bootstrap uses a more specific selector:
.row > * {
margin-top: var(--bs-gutter-y);
}
Where the value is a Bootstrap CSS-variable. This selector means that any direct child of .row will have this margin-top-value applied from the CSS-variable. So all you need to do is use a more specific selector, such as:
.row .work-category {
padding: 0 30px;
margin-top: 50px;
margin-bottom: 50px;
}
More on CSS-specificity from MDN here
Full snippet:
.portfolio {
list-style: none;
margin-left: auto;
margin-right: auto;
}
.container {
width: 1170px;
}
.row {
margin-left: -15px;
margin-right: -15px;
}
.row .work-category {
padding: 0 30px;
margin-top: 50px;
margin-bottom: 50px;
}
.portfolio .one-col {
padding: 0px 30px;
}
.col-md-4 {
width: 50px;
float: left;
}
.footer {
clear: both;
position: relative;
bottom: 0px;
width: 100%;
padding-top: 104px;
margin-top: -27px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<div class="portfolio">
<div class="container">
<div class="row">
<div class="work-category">Title 1</div>
<div class="col-md-4 one-col">column</div>
<div class="col-md-4 one-col">column</div>
<div class="col-md-4 one-col">column</div>
<div class="col-md-4 one-col">column</div>
<div class="work-category">Title 2</div>
<div class="col-md-4 one-col">column</div>
<div class="col-md-4 one-col">column</div>
<div class="col-md-4 one-col">column</div>
<div class="col-md-4 one-col">column</div>
<div class="footer">footer</div>
</div>
</div>
</div>

Aligning images horizontally with respect to another image

I am trying to align some pictures perfectly according to their height while maintaining their ability to scale. I have made a column layout using floats in CSS. There are three columns and have equal width so they scale equally but I can't seem to make the images have optimal height so they all fit in their containers with equal height. The images in my middle column are flowing out.
.section__banner-row {
max-width: 100%;
margin: 0 auto;
}
.section__banner-row:not(:last-child) {
margin-bottom: 1rem;
}
.section__banner-row::after {
content: "";
display: table;
clear: both;
}
.section__banner-row [class^="col-"] {
float: left;
}
.section__banner-row [class^="col-"]:not(:last-child) {
margin-right: 1rem;
}
.section__banner-row .col-1-of-2 {
width: calc((99.9% - 1rem) / 2);
}
.section__banner-row .col-1-of-3 {
width: calc((99.9% - 2 * 1rem) / 3);
}
.section__inside-banner {
margin-top: 1rem;
}
.container-shadow-box {
position: relative;
overflow: hidden;
}
.container-shadow-box img {
width: 100%;
display: block;
transition: all 0.5s;
}
.container-shadow-box:hover img {
transform: scale(1.11);
}
<div class="section__banner-row">
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/FhQFN40/blog-masonry-01.jpg" alt="Masonry 1">
</div>
</div>
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/0JHHwbm/blog-masonry-02.jpg" alt="Masonry 2">
</div>
<div class="section__inside-banner">
<div class="col-1-of-2">
<div class="container-shadow-box">
<img src="https://i.ibb.co/NycZ9KN/blog-masonry-03.jpg" alt="Masonry 3">
</div>
</div>
<div class="col-1-of-2">
<div class="container-shadow-box">
<img src="https://i.ibb.co/qRNZm1q/blog-masonry-04.jpg" alt="Masonry 4">
</div>
</div>
</div>
</div>
<div class="col-1-of-3">
<div class="container-shadow-box">
<img src="https://i.ibb.co/PmcznpR/blog-masonry-05.jpg" alt="Masonry 5">
</div>
</div>
</div>
Flexbox example:
body * {
box-sizing: border-box;
}
.grid-box {
padding-bottom: 28%; /* adjust this for container aspect ratio */
height: 0;
position: relative;
background: pink;
}
.section__banner-row {
display: flex;
}
.section__banner-row.outer {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 5px;
}
.section__banner-row .col {
flex: 1 1 auto;
display: flex;
flex-direction: column;
justify-content: stretch;
align-items: stretch;
}
.section__banner-row .col > div {
flex-basis: 50%;
flex-grow: 1;
}
.container-shadow-box {
margin: 10px;
height: 100%;
background: #ddd;
}
.container-shadow-box>div {
background-size: cover;
height: 100%;
}
<div class="grid-box">
<div class="section__banner-row outer">
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/FhQFN40/blog-masonry-01.jpg);"></div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/0JHHwbm/blog-masonry-02.jpg);"></div>
</div>
<div class="section__banner-row">
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/NycZ9KN/blog-masonry-03.jpg);"></div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/qRNZm1q/blog-masonry-04.jpg);"></div>
</div>
</div>
</div>
</div>
<div class="col">
<div class="container-shadow-box">
<div style="background-image: url(https://i.ibb.co/PmcznpR/blog-masonry-05.jpg);"></div>
</div>
</div>
</div>
</div>
Fiddle demo
Does my browser support flexbox?

Using %-based width divs inside a container with px-based margin

Bit of a beginner's question here - I'm sure it's been asked many times over but not knowing how to phrase the question means I've found it hard to find answers.
I'm trying to create 3 "cards" in a div which are responsive. I would like the margin between the cards to stay at 20px.
This is what I've come up with so far - the contents of the card container should add up to 965, so I'm not sure what's causing it to break and spill out, unless I'm doing something else wrong.
.container {
max-width: 1280px;
}
.card-container {
max-width: 965px;
padding: 0 20px;
display: block;
float: left;
}
.card {
width: 33%;
min-width: 295px;
}
.one {
width: 100%;
height: 200px;
background-color: #333;
display: block;
float: left;
}
.card + .card {
margin: 0px 0px 0px 20px;
}
<div class="container">
<div class="card-container">
<div class="card">
<div class="one"></div>
</div>
<div class="card">
<div class="one"></div>
</div>
<div class="card">
<div class="one"></div>
</div>
</div>
<!-- <div class="map-card"></div> -->
</div>
Thanks for any help, or redirecting to a similar topic.
You can use flex like this https://jsfiddle.net/3gg8ngm2/2/:
.container {
max-width: 1280px;
}
.card-container {
max-width: 965px;
padding: 0 20px;
display: flex;
}
.card {
width: 33%;
/* min-width: 295px; */
}
.one {
width: 100%;
height: 200px;
background-color: #333;
display: block;
float: left;
}
.card + .card {
margin: 0px 0px 0px 20px;
}
<div class="container">
<div class="card-container">
<div class="card">
<div class="one"></div>
</div>
<div class="card">
<div class="one"></div>
</div>
<div class="card">
<div class="one"></div>
</div>
</div>
<!-- <div class="map-card"></div> -->
</div>
Or you can also use display-inline-block to your .card class.
There is a solution based on display: flex
.container {
width: 600px;
}
.card-container {
display: flex;
background: yellow;
}
.card {
width: calc(33% - 20px);
margin-right: 20px;
}
.card:first-child {margin-left:20px}
.one {
height: 200px;
background-color: #333;
}
<div class="container">
<div class="card-container">
<div class="card">
<div class="one">1</div>
</div>
<div class="card">
<div class="one">2</div>
</div>
<div class="card">
<div class="one">3</div>
</div>
</div>
</div>
Add this
.card {
width: 30%;
float:left;
min-width: 295px;
}
and will resolve your issue.

Bootstrap rows overlapping when viewing on smaller screens

So basically the question is in the header. When I lower my screen size, the columns drop below, but start to overlap with the row below.
I am just wanting to know if there is something really obvious that I'm missing.
I just can't seem to find a solution that will work for me.
See screenshot and code below...
#section-headings {
font-size: 44px;
}
h1 {
text-align: center;
color: #ffffff !important;
}
h2 {
text-align: center;
}
#tag-line {
color: #ffffff !important;
}
#main-header {
margin: 0;
}
.jumbotron {
background-image: url(../images/alaska-landscape.jpg);
background-size: cover;
height: 100vh;
width: 100%;
margin: 0;
}
#services {
background-color: #fC99B0;
height: 100vh;
width: 100%;
margin: 0;
}
#services-col {
padding: 80px;
}
#general-text {
text-align: justify;
}
#about {
background-color: #8589FC;
height: 100vh;
width: 100%;
margin: 0;
}
#previous-work {
background-color: #28292D;
height: 100vh;
width: 100%;
margin: 0;
}
.col-md-6, .col-sm-6 {
border-bottom: 0;
margin-bottom: 0;
margin: 0;
}
#glyphicon-image {
display: block;
margin: 0 auto;
}
<!-- Section 2 Services -->
<div id="services" class="container">
<div id="services-row" class="row">
<h1 id="section-headings">services</h1>
<div id="services-col" class="col-md-6 col-sm-6">
<h2>heading 1</h2>
<p id="general-text">paragraph text 1</p>
<img id="glyphicon-image" src="images/bar-chart.png" alt="ux-glyphicon" style="width:128px;height:128px;">
</div>
<div id="services-col" class="col-md-6 col-sm-6">
<h2>heading 2</h2>
<p id="general-text">paragraph text 2</p>
<img id="glyphicon-image" src="images/domain-registration.png" alt="ux-glyphicon" style="width:128px;height:128px;">
</div>
</div>
</div>
<!-- Section 3 About -->
<div id="about" class="container">
<div id="about-row" class="row">
<h1 id="section-headings">about site</h1>
<div class="col-md-6 col-sm-6">
<img src="..." alt="AboutImage">
</div>
<div class="col-sm-6">
<p>Add the about text here and the about image over there <---</p>
</div>
</div>
</div>
WEBPAGE WITH SMALL RESOLUTION
The problem lies in the fact that you set the height to 100vh. As in
#services {
background-color: #fC99B0;
height: 100vh;
width: 100%;
margin: 0;
}
What you should probably do is set the minimum height to 100vh (I'm guessing that you want to have one section take the full height) but leave the height and max-height alone, this way if the height of the content is higher than the screen's, your element will grow bigger to accommodate.
#services {
background-color: #fC99B0;
min-height: 100vh;
width: 100%;
margin: 0;
}
#section-headings {
font-size: 44px;
}
h1 {
text-align: center;
color: #ffffff !important;
}
h2 {
text-align: center;
}
#tag-line {
color: #ffffff !important;
}
#main-header {
margin: 0;
}
.jumbotron {
background-image: url(../images/alaska-landscape.jpg);
background-size: cover;
height: 100vh;
width: 100%;
margin: 0;
}
#services {
background-color: #fC99B0;
min-height: 100vh;
width: 100%;
margin: 0;
}
#services-col {
padding: 80px;
}
#general-text {
text-align: justify;
}
#about {
background-color: #8589FC;
min-height: 100vh;
width: 100%;
margin: 0;
}
#previous-work {
background-color: #28292D;
height: 100vh;
width: 100%;
margin: 0;
}
.col-md-6, .col-sm-6 {
border-bottom: 0;
margin-bottom: 0;
margin: 0;
}
#glyphicon-image {
display: block;
margin: 0 auto;
}
<!-- Section 2 Services -->
<div id="services" class="container">
<div id="services-row" class="row">
<h1 id="section-headings">services</h1>
<div id="services-col" class="col-md-6 col-sm-6">
<h2>UX Design and SEO</h2>
<p id="general-text">My main area of focus and expertise is in helping businesses to create a strong, appropriate online presence that helps them connect and communicate with there customers in the best way possible.</p>
<img id="glyphicon-image" src="images/bar-chart.png" alt="ux-glyphicon" style="width:128px;height:128px;">
</div>
<div id="services-col" class="col-md-6 col-sm-6">
<h2>Website Development</h2>
<p id="general-text">Unlike most UX and SEO consultants, I will not only work with you to design an optimal solution for you and your audience, but I will also implement your solution for you, rather than send you out to fix things on your own.</p>
<img id="glyphicon-image" src="images/domain-registration.png" alt="ux-glyphicon" style="width:128px;height:128px;">
</div>
</div>
</div>
<!-- Section 3 About -->
<div id="about" class="container">
<div id="about-row" class="row">
<h1 id="section-headings">about nomadic</h1>
<div class="col-md-6 col-sm-6">
<img src="..." alt="AboutImage">
</div>
<div class="col-sm-6">
<p>Add the about text here and the about
image over there <---</p>
</div>
</div>
</div>
i thinks it solution
Add a div after each container with class ,
col-sm-12 pad-0
and add this css
.pad-0{padding:0;}
Will solve the problem easily.
See working example below :
/*--CSS--*/
.clrfix{clear:both;}
#section-headings {
font-size: 44px;
}
#section-headings {
display: block;
float: left;
width: 100%;
}
h1 {
text-align: center;
color: #ffffff !important;
}
h2 {
text-align: center;
}
#tag-line {
color: #ffffff !important;
}
#main-header {
margin: 0;
}
.jumbotron {
background-image: url(../images/alaska-landscape.jpg);
background-size: cover;
height: 100vh;
width: 100%;
margin: 0;
}
#services {
background-color: #fC99B0;
height: 100vh;
width: 100%;
margin: 0;
}
#services-col {
padding: 80px;
}
#general-text {
text-align: justify;
}
#about {
background-color: #8589FC;
height: 100vh;
width: 100%;
margin: 0;
}
#previous-work {
background-color: #28292D;
height: 100vh;
width: 100%;
margin: 0;
}
.col-md-6, .col-sm-6 {
border-bottom: 0;
margin-bottom: 0;
margin: 0;
}
#glyphicon-image {
display: block;
margin: 0 auto;
}
#media (max-width: 767px){#services-col { padding:0 10%;}
<!--HTML-->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<!-- Section 2 Services -->
<div id="services" class="container">
<div class="col-sm-12 pad-0">
<div id="services-row" class="row">
<h1 id="section-headings">services</h1>
<div id="services-col" class="col-md-6 col-sm-6">
<h2>UX Design and SEO</h2>
<p id="general-text">My main area of focus and expertise is in helping businesses to create a strong, appropriate online presence that helps them connect and communicate with there customers in the best way possible.</p>
<img id="glyphicon-image" src="images/bar-chart.png" alt="ux-glyphicon" style="width:128px;height:128px;">
</div>
<div id="services-col" class="col-md-6 col-sm-6">
<h2>Website Development</h2>
<p id="general-text">Unlike most UX and SEO consultants, I will not only work with you to design an optimal solution for you and your audience, but I will also implement your solution for you, rather than send you out to fix things on your own.</p>
<img id="glyphicon-image" src="images/domain-registration.png" alt="ux-glyphicon" style="width:128px;height:128px;">
</div>
</div>
</div>
</div>
<div class="clrfix"></div>
<!-- Section 3 About -->
<div id="about" class="container">
<div class="col-sm-12 pad-0">
<h1 id="section-headings">about nomadic</h1>
<div id="about-row" class="row">
<div class="col-md-6 col-sm-6">
<img src="..." alt="AboutImage">
</div>
<div class="col-sm-6">
<p>Add the about text here and the about image over there <---</p>
</div>
</div>
</div>
</div>

Trouble centering divs within a row in brackets

I'm trying to center 4 columns inside a a row. Trying in code pen or similar works like I want, but in adobe-brackets is not working, I don't know if there is a bug or something...
Does anyone has any idea?
PD.: in my brackets output, everything is on the left.
body {
position: relative;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.container-fluid {
width: inherit;
height: inherit;
margin: 0;
padding: 0;
}
.content {
padding: 100px 0;
}
.content-2 {
color: violet;
background-color: blueviolet;
}
div.img {
margin: 5px;
float: center;
width: 180px;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
.row-centered {
text-align: center;
}
.col-centered {
display: inline-block;
float: none;
margin-right: 0 auto;
width: 90%;
}
<section class="content content-2">
<div class="container">
<div class="row row-centered">
<div class="img col-md-2 col-centered">
<img src="forest.jpg" alt="Forest">
<div class="desc">
<h3>CREATIVIDAD</h3>
<p>hhhhhhhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="forest.jpg" alt="Forest">
<div class="desc">
<h3>DISEÑO</h3>
<p>hhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="forest.jpg" alt="Forest">
<div class="desc">
<h3>MULTIMEDIA</h3>
<p>hhhhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="forest.jpg" alt="Forest">
<div class="desc">
<h3>WEB</h3>
<p>hhhhhhhhhhh</p>
</div>
</div>
</div>
</div>
</section>
Use CSS Flexbox. Apply flexbox properties to .row-centered as well as .col-centered:
.row-centered {
display: flex; /* Flex Container */
flex-wrap: wrap; /* Wrap the content to next line if required */
justify-content: center; /* Horizontally content to center */
align-items: center;
}
.col-centered {
display: flex; /* Flex Container */
flex-direction: column; /* Flex Direction - Column */
justify-content: center; /* Vertically Center Alignment */
float: none;
margin-right: 0 auto;
width: 90%;
}
Have a look at this snippet below (use full screen):
body {
position: relative;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.container-fluid {
width: inherit;
height: inherit;
margin: 0;
padding: 0;
}
.content {
padding: 100px 0;
}
.content-2 {
color: violet;
background-color: blueviolet;
}
div.img {
margin: 5px;
float: center;
width: 180px;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
.row-centered {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.col-centered {
display: flex;
flex-direction: column;
justify-content: center;
float: none;
margin-right: 0 auto;
width: 90%;
}
<section class="content content-2">
<div class="container">
<div class="row row-centered">
<div class="img col-md-2 col-centered">
<img src="http://placehold.it/30x30" alt="Forest">
<div class="desc">
<h3>CREATIVIDAD</h3>
<p>hhhhhhhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="http://placehold.it/30x30" alt="Forest">
<div class="desc">
<h3>DISEÑO</h3>
<p>hhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="http://placehold.it/30x30" alt="Forest">
<div class="desc">
<h3>MULTIMEDIA</h3>
<p>hhhhhhhhhhhhh</p>
</div>
</div>
<div class="img col-md-2 col-centered">
<img src="http://placehold.it/30x30" alt="Forest">
<div class="desc">
<h3>WEB</h3>
<p>hhhhhhhhhhh</p>
</div>
</div>
</div>
</div>
</section>
Hope this helps!