On my landing page, we have a "Media Resource" section with links to videos, support materials and social media. Currently, the content in the section shrinks when the window is resized rather than the wanted outcome of stacking.
To be clear, the Videos, Support, and Social are what should be stacking. The heading of the section is perfectly fine.
I've looked through the HTML and CSS for the section but can't seem to pinpoint what's causing them not to stack like desired. Below is the HTML and CSS for what's being worked on.
HTML
<div class="container-fluid no-gutters media-resource-wrapper">
<div class="row">
<div class="col-12 col-lg-4 text-center">
<h2 class="boxheader-lead">Media & Public Relations Resource Center</h2>
</div>
<div class="col-3 col-lg-2">
<img src="~/Images/Video.png" alt="videos" class="img-fluid media-icon video" />
</div>
<div class="col-6 col-lg-4">
<img src="~/Images/Materials.png" alt="support materials" class="img-fluid" />
</div>
<div class="col-3 col-lg-2">
<img src="~/Images/Social.png" alt="social" class="img-fluid media-icon social" />
</div>
</div>
</div>
CSS
.media-resource-wrapper {
background-color: #00b9f2;
padding: 60px 0;
}
.media-resource-wrapper > .row {
margin: 0 10px;
}
.media-resource-wrapper h2 {
margin-bottom: 30px;
color: #fff;
font-weight: bold;
n-bottom: 30px;
color: #fff;
font-weight: bold;
}
/* Media resourse icon positioning */
.media-resource-wrapper .media-icon {
position: relative;
top: 20px;
}
#media (min-width: 992px) {
.health-professionals-block .boxheader-landing {
left: 30px;
margin-top: 250px;
width: 20%;
}
.boxheader-landing h1, .boxheader-landing h2 {
font-size: 1.75em;
}
.boxheader-landing-copy {
font-size: .9em;
}
.media-resource-wrapper h2 {
margin-top: 40px;
border-right: 1px solid #fff;
padding-right: 30px;
}
.media-resource-wrapper .media-icon {
top: 30px;
}
.media-resource-wrapper {
padding: 60px 0 60px 0;
}
}
UPDATE
I made a change that was recommended but the images below shows how it looks by default and then when I shrink.
Standard Size:
Smaller window:
Use standard bootstrap class col-sm-3 and col-sm-6.
Replace the URL with your image and it will stack.
.media-resource-wrapper {
background-color: #00b9f2;
padding: 60px 0;
}
.media-resource-wrapper>.row {
margin: 0 10px;
}
.media-resource-wrapper h2 {
margin-bottom: 30px;
color: #fff;
font-weight: bold;
n-bottom: 30px;
color: #fff;
font-weight: bold;
}
/* Media resourse icon positioning */
.media-resource-wrapper .media-icon {
position: relative;
top: 20px;
}
#media (min-width: 992px) {
.health-professionals-block .boxheader-landing {
left: 30px;
margin-top: 250px;
width: 20%;
}
.boxheader-landing h1,
.boxheader-landing h2 {
font-size: 1.75em;
}
.boxheader-landing-copy {
font-size: .9em;
}
.media-resource-wrapper h2 {
margin-top: 40px;
border-right: 1px solid #fff;
padding-right: 30px;
}
.media-resource-wrapper .media-icon {
top: 30px;
}
.media-resource-wrapper {
padding: 60px 0 60px 0;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.css" rel="stylesheet" />
<div class="container-fluid no-gutters media-resource-wrapper">
<div class="row">
<div class="col-sm-12 col-lg-4 text-center">
<h2 class="boxheader-lead">Media & Public Relations Resource Center</h2>
</div>
<div class="col-sm-3 col-lg-2">
<img src="https://lh3.googleusercontent.com/gN6iBKP1b2GTXZZoCxhyXiYIAh8QJ_8xzlhEK6csyDadA4GdkEdIEy9Bc8s5jozt1g=w300" alt="videos" class="img-fluid media-icon video" />
</div>
<div class="col-sm-6 col-lg-4">
<img src="https://lh3.googleusercontent.com/gN6iBKP1b2GTXZZoCxhyXiYIAh8QJ_8xzlhEK6csyDadA4GdkEdIEy9Bc8s5jozt1g=w300" alt="support materials" class="img-fluid" />
</div>
<div class="col-sm-3 col-lg-2">
<img src="https://lh3.googleusercontent.com/gN6iBKP1b2GTXZZoCxhyXiYIAh8QJ_8xzlhEK6csyDadA4GdkEdIEy9Bc8s5jozt1g=w300" alt="social" class="img-fluid media-icon social" />
</div>
</div>
</div>
<div class="container-fluid no-gutters media-resource-wrapper">
<div class="row">
<div class="col-12 text-center">
<h2 class="boxheader-lead">Media & Public Relations Resource
Center</h2>
</div>
</div>
<div class="row">
<div class="col-3 ">
<img src="~/Images/Video.png" alt="videos" class="img-fluid media-
icon video" />
</div>
<div class="col-6 ">
<img src="~/Images/Materials.png" alt="support materials"
class="img-fluid" />
</div>
<div class="col-3 ">
<img src="~/Images/Social.png" alt="social" class="img-fluid
media-icon social" />
</div>
</div>
If you want the columns to stack use col-sm- instead...
https://www.codeply.com/go/kQHOYSTEnL
<div class="container-fluid no-gutters media-resource-wrapper">
<div class="row">
<div class="col-12 col-lg-4 text-center">
<h2 class="boxheader-lead">Media & Public Relations Resource Center</h2>
</div>
<div class="col-sm-3 col-lg-2">
<img src="//placehold.it/200" alt="videos" class="img-fluid media-icon video" />
</div>
<div class="col-sm-6 col-lg-4 text-center">
<img src="//placehold.it/200" alt="support materials" class="img-fluid" />
</div>
<div class="col-sm-3 col-lg-2">
<img src="//placehold.it/200" alt="social" class="img-fluid media-icon social" />
</div>
</div>
</div>
As you can see here, the .col- is the smallest breakpoint, so they will continue to shrink horizontally in width. sm is the next size up so they will become full-width, and stack vertically at 576px. If you want the cols to stack at wider widths use col-md-,col-lg- or col-xl-, etc..
<div class="container-fluid no-gutters media-resource-wrapper">
<div class="row">
<div class="col-12 text-center">
<h2 class="boxheader-lead">Media & Public Relations Resource Center</h2>
</div>
<div class="col-3 ">
<img src="~/Images/Video.png" alt="videos" class="img-fluid media-icon video" />
</div>
<div class="col-6 ">
<img src="~/Images/Materials.png" alt="support materials" class="img-fluid" />
</div>
<div class="col-3 ">
<img src="~/Images/Social.png" alt="social" class="img-fluid media-icon social" />
</div>
</div>
Related
how to align the height of each column to make them all equal ? I followed the rules from the page: https://www.w3schools.com/howto/howto_css_equal_height.asp, using the properties display:flex and flex: 1, but unfortunately this does not work in my case. Is it affected by the fact that each of these columns is additionally wrapped in bootstrap classes col-12 col-lg-3 ?
HTML code:
<section class="bg-bright container-fluid text-center px-4 py-5">
<div class="row">
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img src="<?php echo get_theme_file_uri( 'assets/img/dzieło.png' ); ?>" class="cards__img img-fluid" alt="...">
<p class="cards__text">Kompleksowa obsługa klienta</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img src="<?php echo get_theme_file_uri( 'assets/img/dzieło.png' ); ?>" class="cards__img img-fluid" alt="...">
<p class="cards__text">Dbałość o najmniejsze detale</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img src="<?php echo get_theme_file_uri( 'assets/img/dzieło.png' ); ?>" class="cards__img img-fluid" alt="...">
<p class="cards__text">Komfort obsługi urządzeń</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img src="<?php echo get_theme_file_uri( 'assets/img/dzieło.png' ); ?>" class="cards__img img-fluid" alt="...">
<p class="cards__text">Funkcjonalność</p>
</div>
</div>
</div>
</div>
</section>
CSS code:
.row {
--bs-gutter-x: 1.5rem;
--bs-gutter-y: 0;
display: flex;
flex-wrap: wrap;
margin-top: calc(var(--bs-gutter-y) * -1);
margin-right: calc(var(--bs-gutter-x)/ -2);
margin-left: calc(var(--bs-gutter-x)/ -2);
}
.col-lg-3 {
flex: 0 0 auto;
width: 25%;
}
.cards {
display: flex;
width: 100%;
align-items: stretch;
}
.cards__body {
background-color: red;
box-shadow: rgba(0, 0, 0, 0.05) 0px 8px 20px 0px;
flex: 1;
}
.cards__text {
color: #333;
font-size: 17px;
font-weight: 700;
padding: 1rem;
}
You can use min-height:...
.row {
display:flex;
}
.col-lg-3 {
flex: 0 0 auto;
width: 25%;
}
.cards {
display: flex;
width: 100%;
align-items: stretch;
}
.cards__body {
background-color: red;
box-shadow: rgba(0, 0, 0, 0.05) 0px 8px 20px 0px;
flex: 1;
min-height:300px;
}
.cards__text {
color: #333;
font-size: 17px;
font-weight: 700;
padding: 1rem;
max-width:100%;
}
<section class="bg-bright container-fluid text-center px-4 py-5">
<div class="row">
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQzhE83ZD8Aa9uJQhWtZ8EdTB7Wg0NsmHg-7w&usqp=CAU" class="cards__img img-fluid" alt="...">
<p class="cards__text">Kompleksowa obsługa klienta klienta klienta</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQzhE83ZD8Aa9uJQhWtZ8EdTB7Wg0NsmHg-7w&usqp=CAU" class="cards__img img-fluid" alt="...">
<p class="cards__text">Dbałość o najmniejsze detale</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQzhE83ZD8Aa9uJQhWtZ8EdTB7Wg0NsmHg-7w&usqp=CAU" class="cards__img img-fluid" alt="...">
<p class="cards__text">Komfort obsługi urządzeń</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQzhE83ZD8Aa9uJQhWtZ8EdTB7Wg0NsmHg-7w&usqp=CAU" class="cards__img img-fluid" alt="...">
<p class="cards__text">Funkcjonalność</p>
</div>
</div>
</div>
</div>
</section>
You have not added .row class in your CSS. It should be
.row {
display: flex;
}
And all your divs are of the same height. You just have applied the background-colour to cards__body instead of .col-lg-3 which is the full height div.
For making inner divs of same height you can give .card__body class flex as flex: 0 0 auto;
The 'flex' css property will define what part of the wrapper width the columns can span. Here's a cool playground for Flexbox: https://demos.scotch.io/visual-guide-to-css3-flexbox-flexbox-playground/demos/
Normally the below property should be set to stretch by default, but do try to add this css.
.row {
align-items: stretch;
}
Also if the above doesn't do anything:
.row > div {
height: 100%;
}
(((My version is responsive, please run the code snippet as full page below)))
Wow, this is very tricky with bootstrap. In fact, you don't need to use flexbox to do it and I think using flexbox will break the responsive grid system in mobile view. All you need to do is giving the cards and cards__body both height: 100%;, it will take up all the vertical space in the grid row. However, that will bring up another issue: no spacing in mobile view and you might find that margin no longer doing the job of spacing out the element for the cards. Luckily, you can still use padding for spacing.
Checkout the code below and compare the changes what I commented out the things you don't need and what I added. Happy coding ;)
.col-lg-3 {
/* flex: 0 0 auto;
width: 25%; */
}
.cards {
/* display: flex; */
/* width: 100%; */
/* align-items: stretch; */
margin: auto;
width: fit-content;
height: 100%;
padding-bottom: 1em;
}
.cards__body {
background-color: red;
box-shadow: rgba(0, 0, 0, 0.05) 0px 8px 20px 0px;
/* flex: 1; */
height: 100%;
}
.cards__text {
color: #333;
font-size: 17px;
font-weight: 700;
padding: 1rem;
height: 100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="style.css" />
<title>Static Template</title>
</head>
<body>
<section class="bg-bright container-fluid text-center px-4 py-5">
<div class="row">
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img
src="https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png"
class="cards__img img-fluid"
alt="..."
/>
<p class="cards__text">Kompleksowa obsługa klienta</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img
src="https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png"
class="cards__img img-fluid"
alt="..."
/>
<p class="cards__text">Dbałość o najmniejsze detale</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img
src="https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png"
class="cards__img img-fluid"
alt="..."
/>
<p class="cards__text">Komfort obsługi urządzeń</p>
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="cards">
<div class="cards__body">
<img
src="https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png"
class="cards__img img-fluid"
alt="..."
/>
<p class="cards__text">Funkcjonalność</p>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
I have six images with names and I want to place them in the footer.
After placing the names are displaying in two lines instead of a single line. that is "s player" where "s" is displaying above the "player" instead of in a single line in smaller devices so how to make responsive to resolve this issue?.`
.footer {
position: fixed;
bottom: 0px;
background-color: white;
height: 45pt;
width: 100%;
padding: 2pt 8pt;
border-top: 1pt solid #f3f3f4;
}
span {
font-family: Segoe Script;
}
.super {
color: #9400D3;
text-size-adjust: inherit;
}
.duper {
color: #4B0082;
}
.champ {
color: #0000FF;
}
.good {
color: #FF7F00;
}
.hero {
color: #FF0000;
}
.king {
color: #00BD13;
}
<div class="footer">
<div class="row">
<div class="col s2 col-xs-2 col-sm-2 col-md-2 col-lg-2">
<img src="/images/abc.svg" alt="Player1">
<div><span class="super">s</span> Player</div>
</div>
<div class="col s2 col-xs-2 col-sm-2 col-md-2 col-lg-2">
<img src="/images/bcd.svg" alt="Player2">
<div><span class="duper">d</span> Player</div>
</div>
<div class="col s2 col-xs-2 col-sm-2 col-md-2 col-lg-2">
<img src="/images/cde.svg" alt="Player3">
<div><span class="champ">c</span> Player</div>
</div>
<div class="col s2 col-xs-2 col-sm-2 col-md-2 col-lg-2">
<img src="/images/def.svg" alt="Player4">
<div><span class="good">g</span> Player</div>
</div>
<div class="col s2 col-xs-2 col-sm-2 col-md-2 col-lg-2">
<img src="/images/efg.svg" alt="Player5">
<div><span class="hero">h</span> Player</div>
</div>
<div class="col s2 col-xs-2 col-sm-2 col-md-2 col-lg-2">
<img src="/images/fgh.svg" alt="Player6">
<div><span class="king">k</span> Player</div>
</div>
</div>
`
Problem come here from all the class col-xx that you use in you children in row. They have to have all the same width so please just use a single col class :
.footer {
position: fixed;
bottom: 0px;
background-color: white;
height: 45pt;
width: 100%;
padding: 2pt 8pt;
border-top: 1pt solid #f3f3f4;
}
span {
font-family: Segoe Script;
}
.super {
color: #9400D3;
text-size-adjust: inherit;
}
.duper {
color: #4B0082;
}
.champ {
color: #0000FF;
}
.good {
color: #FF7F00;
}
.hero {
color: #FF0000;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="footer">
<div class="row">
<div class="col">
<img src="/images/abc.svg" alt="Player1">
<div><span class="super">s</span> Player</div>
</div>
<div class="col">
<img src="/images/bcd.svg" alt="Player2">
<div><span class="duper">d</span> Player</div>
</div>
<div class="col">
<img src="/images/cde.svg" alt="Player3">
<div><span class="champ">c</span> Player</div>
</div>
<div class="col">
<img src="/images/def.svg" alt="Player4">
<div><span class="good">g</span> Player</div>
</div>
<div class="col">
<img src="/images/efg.svg" alt="Player5">
<div><span class="hero">h</span> Player</div>
</div>
<div class="col">
<img src="/images/fgh.svg" alt="Player6">
<div><span class="king">k</span> Player</div>
</div>
</div>
I am making a page with one .html file and one .css file.
I have incorporated the bootstrap 4 CDN into my html head.
The grid appears properly for the medium screen sizes but it is not resizing when I view on my phone.
I have used bootstrap 4 before with no issues in my react app but the same methods do not seem to be working with plain html and css.
my code can be seen below.
html:
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Portfolio</title>
<meta name="description" content="Showcasing my portfolio">
<!-- Latest compiled and minified CSS (bootstrap) -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<nav>
<div class="navLeft">
NAME
</div>
<div class="navRight">
PORTFOLIO
ABOUT
CONTACT
CURRICULUM VITAE
GITHUB PROFILE
</div>
</nav>
<div class="container">
<div class="contentPane">
<div class="nameSection">
<div class="row">
<div class="col-md-4 col-10 mx-auto">
<img src="" alt="NAME">
<h1>NAME</h1>
</div>
</div>
<div class="row">
<div class="col-md-4 col-10 mx-auto">
<div class="underline" class="col-12 mx-auto"></div>
<h4>Front End Developer</h4>
</div>
</div>
</div>
<div class="portfolioSection">
<div class="row">
<div class="col-4 mx-auto">
<h1>PORTFOLIO</h1>
</div>
</div>
<div class="row">
<div class="col-4 mx-auto">
<div class="underline" class="col-12 mx-auto"></div>
<h4>Front End Developer</h4>
</div>
</div>
<div class="row">
<div class="col-10 mx-auto">
<img class="screen" id="kovScreen" src="" alt="King Of Vape Screenshot">
</div>
<div class="col-md-5 col-10 mx-auto">
<img class="screen" id="rgbyScreen" src="" alt="Simon Game Screenshot">
testcontent
</div>
<div class="col-md-5 col-10 mx-auto">
<img class="screen" id="osxsScreen" src="" alt="Naughts and Crosses Screenshot">
testcontent
</div>
<div class="col-md-5 col-10 mx-auto">
<img class="screen" id="pomodoroScreen" src="" alt="Pomodoro Clock Screenshot">
testcontent
</div>
<div class="col-md-5 col-10 mx-auto">
<img class="screen" id="calculatorScreen" src="" alt="Calculator Screenshot">
testcontent
</div>
</div>
</div>
<div class="aboutSection">
<div class="row">
<div class="col-4 mx-auto">
<h1>PORTFOLIO</h1>
</div>
</div>
<div class="row">
<div class="col-4 mx-auto">
<div class="underline" class="col-12 mx-auto"></div>
<h4>Front End Developer</h4>
</div>
</div>
</div>
</div>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
I do have more than 12 columns in some rows but never had an issue with it before, and as I stated earlier, everything works fine on medium screen sizes.
css:
nav {
position: fixed;
top: 0px;
z-index: 1;
display: block;
height: 50px;
width: 100%;
background-color: #A65900;
padding-top: 10px;
box-shadow: 0px 0px 10px 2px rgba(0, 0, 0, 0.68);
}
nav a {
text-decoration: none;
color: white;
padding: 0 0.5em;
display: inline;
}
nav .navLeft {
font-size: 20px;
display: inline;
margin-left: 5rem;
}
nav .navRight {
display: inline;
margin-right: 5rem;
}
.contentPane {
box-shadow: 0px 0px 10px 2px rgba(0, 0, 0, 0.68);
}
.nameSection {
width: 100%;
text-align: center;
background-color: #FFA200;
}
.nameSection img {
margin-top: 90px;
max-height: 200px;
width: 100%;
}
.underline {
display: block;
clear: both;
height: 8px;
background-color: white;
border-radius: 5px;
margin-bottom: 5px;
}
.nameSection h4 {
margin-bottom: 40px;
}
.portfolioSection {
text-align: center;
background-color: #FFEF00;
}
.portfolioSection h1 {
margin-top: 40px;
}
.screen {
width: 100%;
max-height: 200px;
}
Can anybody see what I am doing wrong?
All help is appreciated. Thanks.
See Responsive meta tag in the Bootstrap documentation.
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
You missed out the meta viewport directive so mobile browsers will assume you have not designed a responsive website and will default to scaling for a desktop design instead.
Add the meta element.
My page has 3 div(s) within a div. In tablet and desktop screens they look good (center-aligned), but on a very small device such as cellphone the inner div(s) are left aligned (I want them to be horizontally center aligned). I applied text-center, and center-block to the outer div but it does not work. Any suggestion? Here are the html, and css codes.
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
portfolio-caption {
max-width: 281px;
background-color: #994ACC;
text-align: center;
padding: 10px;
border-top: 3px solid #ffffff;
margin-bottom: 10px;
}
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12">
<div style="max-width: 281px">
<a href="#" ">
<img src="./x/pilotproject1.jpg " class="img-responsive " style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div style="max-width: 281px ">
<a href="# ">
<img src="./x/pilotproject2.jpg " class="img-responsive "
style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div style="max-width: 281px ">
<a href="# " class="pilot-link ">
<img src="./x/pilotproject3.jpg " class="img-responsive "
style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
</div>
The reason that I have is that the width of the pictures is 281 px, if I do not set the width, the width of the div that comes after the img will be bigger than 281 px which is not something that I want.
as you can see in this picture, the images are all left-aligned
I added a class centered as a container to center elements (please remove the border border: 1px solid red; it is used to show you the container block ):
.centered {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
border: 1px solid red;
}
.img-responsive {
display: block;
max-width: 281px !important;
height: auto;
margin: 0 auto;
}
wrap each element you want to be centered.
Also in your css portfolio-caption should be .portfolio-caption to select a class.
I moved your in-line style to css class img-responsive so you can update your style in one place.
.img-responsive {
display: block;
max-width: 281px !important;
height: auto;
margin: 0 auto;
}
.portfolio-caption {
width: 281px;
background-color: #994ACC;
text-align: center;
padding: 10px;
border-top: 3px solid #ffffff;
margin-bottom: 10px;
float: right;
}
.centered {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
/* border: 1px solid red; */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="centered">
<a href="#">
<img src="http://placehold.it/350x150" class="img-responsive" alt=" ">
</a>
</div>
<div class="centered">
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="centered">
<a href="# ">
<img src="http://placehold.it/350x150" class="img-responsive" alt=" ">
</a>
</div>
<div class="centered">
<div class="portfolio-caption">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="centered">
<a href="# " class="pilot-link ">
<img src="http://placehold.it/350x150" class="img-responsive" alt=" ">
</a>
</div>
<div class="centered">
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
</div>
You should not apply classes to outer divs, apply them exactly to what you want to be centered : class="img-responsive center-block", and
also check the bootstrap version center-block is new in Bootstrap version 3.0.1 i believe.
Use
Text align : center ;
text-align:center
<div style="max-width: 281px; text-align : center">
Plunker link :
https://plnkr.co/edit/UaW436KiylzfqOCU1cg1?p=preview
I am trying to make the bottom right greyish box (the one without image) same height and width as other boxes with images. It is supposed to be responsive but if I manage to make it fit this resolution it doesn't work in other resolutions. I tried with flexbox but couldn't make it work. I am using Bootstrap as you can see. I also tried using vh and vw but no luck...
I would really appreciate if someone with more experience could tell me the proper way to do this? Thanks all for reading and trying to help!
Here is the screenshot of what I am trying to achieve:
Here is my code so far:
<!-- T E A M S E C T I O N -->
<section id="team" class="no-padding">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-center">
<h1><span class="orange">[ </span>Meet Our Team<span class="orange"> ]</span></h1>
<p>A perfect blend of creativity and technical wizardry.</br>The best people formula for great websites!</p>
</div>
</div>
<div class="row no-gutter">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/1.jpg" title="">
<img src="img/team/1.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/2.jpg" title="">
<img src="img/team/2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/3.jpg" title="">
<img src="img/team/3.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/4.jpg" title="">
<img src="img/team/4.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/5.jpg" title="">
<img src="img/team/5.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/6.jpg" title="">
<img src="img/team/6.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/7.jpg" title="">
<img src="img/team/7.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/8.jpg" title="">
<img src="img/team/8.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<div class="team-box">
<div class="team-box-last">
<h3>Want to join our team?</h3>
<p>We’re always looking for talented designers, developers, project managers and anyone who’s driven and has a passion for the digital industries.
</p>
<ul>
<li>Check our jobs page</li>
<li>Send us your CV</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</section>
/* -------- TEAM SECTION -------- */
#team{
background-color: #fff;
text-align: center;
width: 100%;
}
#team h1{
color: #345;
font-weight: 700;
margin-top: 50px;
margin-bottom: 50px;
}
#team p{
color: #345;
font-size: 21px;
margin-top: 0px;
margin-bottom: 50px;
padding-left: 15px;
padding-right: 15px;
}
.no-padding {
padding: 0;
}
.no-gutter > [class*=col-] {
padding-right: 0;
padding-left: 0;
}
.team-box {
display: block;
position: relative;
margin: 0 auto;
max-width: 650px;
overflow: hidden;
}
.team-box img{
-moz-transition: all 1s;
-webkit-transition: all 1s;
transition: all 1s;
}
.team-box:hover img {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.team-box .team-box-caption {
display: block;
position: absolute;
bottom: 0;
width: 100%;
height: 100%;
text-align: center;
color: #fff;
opacity: 1;
background: transparent;
/* background: rgba(67,208,243,0.9);
-webkit-transition: all .35s;
-moz-transition: all .35s;
transition: all .35s; */
}
.team-box .team-box-caption .team-box-caption-content {
position: absolute;
bottom: 12px;
width: 100%;
text-align: left;
}
.team-box .team-box-caption .team-box-caption-content .name,
.team-box .team-box-caption .team-box-caption-content .position {
padding: 0 15px;
text-shadow: 0px 0px 5px #000;
}
.team-box .team-box-caption .team-box-caption-content .name {
text-transform: uppercase;
font-size: 12px;
font-weight: 700;
}
.team-box .team-box-caption .team-box-caption-content .position {
font-size: 12px;
text-transform: uppercase;
}
.team-box:hover .team-box-caption {
opacity: 1;
}
#media(min-width:768px) {
.team-box .team-box-caption .team-box-caption-content .name {
font-size: 15px;
}
.team-box .team-box-caption .team-box-caption-content .position {
font-size: 15px;
text-transform: uppercase;
}
}
.team-box-last{
text-align: left;
padding: 30px 30px;
}
.team-box:last-child{
background-color: #f3f3f3;
}
#team .team-box-last h3{
color: #345;
padding-top: 15px;
padding-left: 15px;
}
#team .team-box-last p{
font-size: 18px;
line-height: 23px;
padding-top: 15px;
margin-bottom: 30px;
}
#team .team-box-last ul{
padding-left: 15px;
}
#team .team-box-last ul li{
font-size: 18px;
font-weight: 500;
}
#team .team-box-last ul li{
list-style: none;
}
Well, you cannot really achieve this with CSS, you may add some Javascript code using jQuery to make it easier for you.
I am giving you an example just have a look to get an idea. The idea is to get the height of each image box which I have assigned id="getheight" and then add that height to the last box. Remember you need to use overflow:hidden if you want to see same height. I have altered your code and add some class and javascript to give you what you can do.
The problem in responsiveness in the last box is you need to also handle font-size or other stuff to make sure it always appears and perfect which I haven't touched that yet. However, you can still have scrollbar for longer text if you want.
All in all, this is one approach to solve your problem, there maybe more ways if spend more time.
** Please copy and see in bigger screen for responsiveness as well we watch console to see dynamic height. ***
var picHeight = $('#getheight').height();
$('.sameHeight').css('height',picHeight + 'px');
$('.team-box-last').css('height',picHeight + 'px')
$(window).on('resize',function(){
var picHeight = $('#getheight').height();
$('.sameHeight').css('max-height',picHeight + 'px');
})
/* -------- TEAM SECTION -------- */
#team{
background-color: #fff;
text-align: center;
width: 100%;
}
#team h1{
color: #345;
font-weight: 700;
margin-top: 50px;
margin-bottom: 50px;
}
#team p{
color: #345;
font-size: 21px;
margin-top: 0px;
margin-bottom: 50px;
padding-left: 15px;
padding-right: 15px;
}
.no-padding {
padding: 0;
}
.no-gutter > [class*=col-] {
padding-right: 0;
padding-left: 0;
}
.team-box {
display: block;
position: relative;
margin: 0 auto;
max-width: 650px;
overflow: hidden;
}
.team-box img{
-moz-transition: all 1s;
-webkit-transition: all 1s;
transition: all 1s;
}
.team-box:hover img {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.team-box .team-box-caption {
display: block;
position: absolute;
bottom: 0;
width: 100%;
height: 100%;
text-align: center;
color: #fff;
opacity: 1;
background: transparent;
/* background: rgba(67,208,243,0.9);
-webkit-transition: all .35s;
-moz-transition: all .35s;
transition: all .35s; */
}
.team-box .team-box-caption .team-box-caption-content {
position: absolute;
bottom: 12px;
width: 100%;
text-align: left;
}
.team-box .team-box-caption .team-box-caption-content .name,
.team-box .team-box-caption .team-box-caption-content .position {
padding: 0 15px;
text-shadow: 0px 0px 5px #000;
}
.team-box .team-box-caption .team-box-caption-content .name {
text-transform: uppercase;
font-size: 12px;
font-weight: 700;
}
.team-box .team-box-caption .team-box-caption-content .position {
font-size: 12px;
text-transform: uppercase;
}
.team-box:hover .team-box-caption {
opacity: 1;
}
#media(min-width:768px) {
.team-box .team-box-caption .team-box-caption-content .name {
font-size: 15px;
}
.team-box .team-box-caption .team-box-caption-content .position {
font-size: 15px;
text-transform: uppercase;
}
}
.sameHeight{
overflow:hidden;
}
.team-box-last{
text-align: left;
overflow:auto;
padding:30px 30px;
}
.team-box:last-child{
background-color: #f3f3f3;
}
#team .team-box-last h3{
color: #345;
padding-left: 15px;
}
#team .team-box-last p{
font-size: 18px;
line-height: 23px;
padding-top: 15px;
margin-bottom: 30px;
}
#team .team-box-last ul{
padding-left: 15px;
}
#team .team-box-last ul li{
font-size: 18px;
font-weight: 500;
}
#team .team-box-last ul li{
list-style: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- T E A M S E C T I O N -->
<section id="team" class="no-padding">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-center">
<h1><span class="orange">[ </span>Meet Our Team<span class="orange"> ]</span></h1>
<p>A perfect blend of creativity and technical wizardry.</br>The best people formula for great websites!</p>
</div>
</div>
<div class="row no-gutter">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4" id="getheight" >
<a class="team-box" rel="" href="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" title="">
<img src="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/2.jpg" title="">
<img src="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/3.jpg" title="">
<img src="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/4.jpg" title="">
<img src="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/5.jpg" title="">
<img src="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/6.jpg" title="">
<img src="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/7.jpg" title="">
<img src="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<a class="team-box" rel="" href="img/team/8.jpg" title="">
<img src="https://free4kwallpapers.com/uploads/originals/2015/07/13/natur-hintergrundbilder-09-2012-269-2.jpg" class="img-responsive" alt="">
<div class="team-box-caption">
<div class="team-box-caption-content">
<div class="name">
Full Name
</div>
<div class="position">
Position
</div>
</div>
</div>
</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 sameHeight">
<div class="team-box">
<div class="team-box-last">
<div class="t">
<h3>Want to join our team?</h3>
<p>We’re always looking for talented designers, developers, project managers and anyone who’s driven and has a passion for the digital industries.
</p>
<ul>
<li>Check our jobs page</li>
<li>Send us your CV</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<br/>
<br/>
<br/>
<br/><br/>
<br/>
<br/>
<br/>
<br/>
I also included resize option to tell how you can handle automatic height size.
Please feel free to change my code and make that nice and compatible with your requirement.