This question already has answers here:
CSS-only masonry layout
(4 answers)
Bootstrap 4 masonry layout utilizing flexbox grid
(3 answers)
Closed 2 years ago.
This my displayed gallery:
And this is what I want
I want to displayed image like that, a little messy but awesome
And this my trouble when some image have different height
there have whitespace and does not automatically fill the whitespace section So this whitespace should be fill.
This my HTML & CSS Code :
.detail-img{
width: 23%;
margin: 10px;
position: relative;
min-height: 280px;
max-height: 450px;
}
.galeri-row{
margin: auto;
}
.galeri-row img{
border-radius: 15px;
object-fit: cover;
object-position: center;
cursor: pointer;
width: 100%;
height: 100%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<section>
<div class="container">
<div class="row galeri-row justify-content-md-center">
<a href="#" class="detail-img">
<img src="img/src">
<div class="detail-text">
<span class="my-tag btn-success">TAG</span>
<p>
Lorem ipsum dolor sit amet consectetur...
</p>
</div>
</a>
<a href="#" class="detail-img galeri-sm">
<img src="img/src">
<div class="detail-text">
<span class="my-tag btn-success">TAG</span>
<p>
Lorem ipsum dolor sit amet...
</p>
</div>
</a>
<a href="#" class="detail-img galeri-sm">
<img src="img/src">
<div class="detail-text">
<span class="my-tag btn-success">TAG</span>
<p>
Lorem ipsum dolor sit amet...
</p>
</div>
</a>
<a href="#" class="detail-img">
<img src="img/src">
<div class="detail-text">
<span class="my-tag btn-success">TAG</span>
<p>
Lorem ipsum dolor sit amet...
</p>
</div>
</a>
...................
</div>
</div>
</section>
if you want to stick to fixed column layout I would use flexbox, with a flex-direction: column, to manage each column individually
Related
I wanted to create something like this
But my code is coming out to be completely different and I am not able to figure out why.
The image is enlarged and going out of the div. Also if I try to shift the image towards right it instead is going to the left. I think I messed up in the positioning part of the image. How can I fix this issue and why is it happening? Here is my code:
#title {
background-color: #916BBF;
}
.container-fluid {
padding: 3% 15%;
}
/* Download Buttons */
.download-button {
margin: 5% 3% 5% 0;
}
/* Title */
.title-img {
width: 60%;
transform: rotate(25deg);
position: absolute;
}
#features {
padding: 7% 15%;
background-color: #fff;
position: relative;
z-index: 1;
}
.feature-box {
text-align: center;
padding: 5%;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<!-- CSS bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<!-- JS bootstrap -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
<!-- CSS -->
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!-- Title -->
<section id="title">
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
<button type="button" class="btn btn-dark btn-lg download-button"><i class="fab fa-apple"></i> Download</button>
<button type="button" class="btn btn-outline-light btn-lg download-button"><i class="fab fa-google-play"></i> Download</button>
</div>
<div class="col-lg-6">
<img class="title-img" src="https://www.transparentpng.com/thumb/-iphone-x/jPIkq8-iphone-glass-lens-screen-replacement-fixez.png" alt="iphone-mockup">
</div>
</div>
</div>
</section>
<!-- Features -->
<section id="features">
<div class="row">
<div class="feature-box col-lg-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div class="feature-box col-lg-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div class="feature-box col-lg-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
</div>
</section>
</body>
</html>
I went ahead and took your width off your img class and added a few styles. Next steps to achieve this look would be to contain your h1 and buttons on the left and provide a margin left.
EDIT:
I also added a col-sm-6 Bootstrap class to your col-lg-6 to make it mobile responsive. The #media only screen on your img class allows you to adjust the img to make it positioned just right on a different device.
#title {
background-color: #916BBF;
}
.container-fluid {
padding: 3% 15%;
}
/* Download Buttons */
.download-button {
margin: 5% 3% 5% 0;
}
/* Title */
.title-img {
transform: rotate(27deg);
position: absolute;
margin-top: 5rem;
overflow-x: hidden;
}
/* Title Responsive */
#media only screen and (max-width: 900px) {
.title-img {
transform: rotate(27deg);
position: absolute;
margin-top: 5rem;
right: 2rem;
overflow-x: hidden;
}
}
#features {
padding: 7% 15%;
background-color: #fff;
position: relative;
z-index: 1;
}
.feature-box {
text-align: center;
padding: 5%;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<!-- CSS bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<!-- JS bootstrap -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
<!-- CSS -->
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!-- Title -->
<section id="title">
<div class="container-fluid">
<div class="row">
<div class="col-lg-6 col-sm-6">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
<button type="button" class="btn btn-dark btn-lg download-button"><i class="fab fa-apple"></i> Download</button>
<button type="button" class="btn btn-outline-light btn-lg download-button"><i class="fab fa-google-play"></i> Download</button>
</div>
<div class="col-lg-6 col-sm-6">
<img class="title-img" src="https://www.transparentpng.com/thumb/-iphone-x/jPIkq8-iphone-glass-lens-screen-replacement-fixez.png" alt="iphone-mockup">
</div>
</div>
</div>
</section>
<!-- Features -->
<section id="features">
<div class="row">
<div class="feature-box col-lg-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div class="feature-box col-lg-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div class="feature-box col-lg-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
</div>
</section>
</body>
</html>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<!-- CSS bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<!-- JS bootstrap -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
<!-- CSS -->
<link rel="stylesheet" href="styles.css">
</head>
<style>
#title {
background-color: #916BBF;
}
.container-fluid {
padding: 3% 15%;
}
/* Download Buttons */
.download-button {
margin: 5% 3% 5% 0;
}
/* Title */
.title-img {
width: 60%;
transform: rotate(25deg);
position: relative;
}
#features {
padding: 7% 15%;
background-color: #fff;
position: relative;
z-index: 1;
margin-top: -128px;
}
.feature-box {
text-align: center;
padding: 5%;
}
</style>
<body>
<!-- Title -->
<section id="title">
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
<button type="button" class="btn btn-dark btn-lg download-button"><i class="fab fa-apple"></i> Download</button>
<button type="button" class="btn btn-outline-light btn-lg download-button"><i class="fab fa-google-play"></i> Download</button>
</div>
<div class="col-lg-6">
<img class="title-img" src="https://www.transparentpng.com/thumb/-iphone-x/jPIkq8-iphone-glass-lens-screen-replacement-fixez.png" alt="iphone-mockup">
</div>
</div>
</div>
</section>
<!-- Features -->
<section id="features">
<div class="row">
<div class="feature-box col-md-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div class="feature-box col-md-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
<div class="feature-box col-md-4">
<h3>Lorem Ipsum</h3>
<p>Lorem ipsum dolor sit amet consectetur.</p>
</div>
</div>
</section>
</body>
</html>
I'm have a form with some tags. The from is pre-populated, but I cannot seem to be able to assign the initial height of the item using min-content. For instance:
.item {
display: flex;
align-items: center;
padding: 0 0.5rem 0 0.5rem;
font-size: 0.8rem;
}
.item > textarea {
width:100%;
margin: 1rem 0 0 1rem;
min-height: 20px;
height: min-content;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sandbox index</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-4"></div>
<div class="col-4">
<div class="item"><label for="">some label</label><textarea name="" id="" cols="30" rows="10">Lorem ipsum dolor sit amet consectetur adipisicing elit. Delectus autem </textarea></div>
<div class="col-4"></div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
</body>
</html>
I don't need to resize based on input (e.g. I've seen other questions, that involve javascript in some ways). But it seems to me there really should be a way to set it directly with css if it only needs to remain static, non?
How about using a contenteditable that looks like textarea with css?
.textarea {
display: block;
width: 100%;
overflow: hidden;
resize: both;
min-height: 40px;
line-height: 20px;
border: 1px solid #ccc;
padding: 1px 6px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sandbox index</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-4"></div>
<div class="col-4">
<div class="item"><label for="">some label</label><span contenteditable class="textarea" name="" id="" cols="30" rows="10">Lorem ipsum dolor sit amet consectetur adipisicing elit. Delectus autem </span></div>
<div class="col-4"></div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
</body>
</html>
You can have a static placeholder using CSS
.textarea[contenteditable]:empty::before {
content: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Delectus autem";
color: gray;
}
This question already has answers here:
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
How can I horizontally center an element?
(133 answers)
Closed 2 years ago.
In the below code snippet, I tried to align the div inside .jumbotron to the center but it didn't work. Is there any extra class needed because I already tried .justify-content-center and .mx-auto.
<!-- CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<!-- EndCSS -->
<div class="jumbotron">
<div class="justify-content-center">
<h1 class="display-3">Lorem.</h1>
<p class="lead">Lorem, ipsum dolor.<span class="text-
warning">Lorem, ipsum.</span><br>Lorem ipsum dolor
sitamet.
</p>
</div>
</div>
<!-- JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<!-- EndJS -->
text-center class of bootstrap may help
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="jumbotron text-center">
<h1 class="display-3">Lorem.</h1>
<p class="lead">Lorem, ipsum dolor.<span class="text-
warning">Lorem, ipsum.</span><br>Lorem ipsum dolor sitamet.
</p>
</div>
You can use the following solution:
Set d-flex to the jumbotron to use flex classes (like justify-content-center) on the jumbotron.
Set the justify-content-center to the jumbotron itself to center its content.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<div class="jumbotron d-flex justify-content-center">
<div>
<h1 class="display-3">Lorem.</h1>
<p class="lead">Lorem, ipsum dolor.<span class="text-
warning">Lorem, ipsum.</span><br>Lorem ipsum dolor
sitamet.
</p>
</div>
</div>
<!-- CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<!-- EndCSS -->
<div class="jumbotron">
<div class="d-flex flex-row justify-content-center">
<h1 class="display-3">Lorem.</h1>
<p class="lead">Lorem, ipsum dolor.<span class="text-
warning">Lorem, ipsum.</span><br>Lorem ipsum dolor
sitamet.
</p>
</div>
</div>
<!-- JS -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<!-- EndJS -->
Please try this code,To Is there any way to align jumbotron elements in center?
<!DOCTYPE html>
<html>
<head>
<!-- Credit: http://stackoverflow.com/questions/22196587/how-to-center-align-vertically-the-container-in-bootstrap -->
<title>Bootstrap Centered Jumbotron</title>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.css" />
<style type="text/css">
html, body {
height: 100%;
}
.container{
width: 1025px;
}
.vertical-center {
height: 100%;
width: 100%;
text-align: center; /* align the inline(-block) elements horizontally */
font: 0/0 a; /* remove the gap between inline(-block) elements */
}
.vertical-center:before { /* create a full-height inline block pseudo=element */
content: ' ';
display: inline-block;
vertical-align: middle; /* vertical alignment of the inline element */
height: 100%;
}
.vertical-center > .container {
max-width: 100%;
background-color: gold;
display: inline-block;
vertical-align: middle; /* vertical alignment of the inline element */
font: 16px/1 "Helvetica Neue", Helvetica, Arial, sans-serif; /* <-- reset the font property */
}
#media (max-width: 768px) {
.vertical-center:before {
/* height: auto; */
display: none;
}
}
</style>
</head>
<body>
<div class="jumbotron vertical-center">
<div class="container text-center">
<h1>The easiest and powerful way</h1>
<div class="row">
<div class="col-md-7">
<div class="top-bg"></div>
</div>
<div class="col-md-5 iPhone-features" style="margin-left:-25px;">
<ul class="top-features">
<li>
<span><i class="fa fa-random simple_bg top-features-bg"></i></span>
<p><strong>Redirect</strong><br>Visitors where they converts more.</p>
</li>
<li>
<span><i class="fa fa-cogs simple_bg top-features-bg"></i></span>
<p><strong>Track</strong><br>Views, Clicks and Conversions.</p>
</li>
<li>
<span><i class="fa fa-check simple_bg top-features-bg"></i></span>
<p><strong>Check</strong><br>Constantly the status of your links.</p>
</li>
<li>
<span><i class="fa fa-users simple_bg top-features-bg"></i></span>
<p><strong>Collaborate</strong><br>With Customers, Partners and Co-Workers.</p>
</li>
GET STARTED
<h6 class="get-Started-sub-btn">FREE VERSION AVAILABLE!</h6>
</ul>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
</body>
</html>
I hope this code will be useful for you.
Thank you.
Could I please have some help, I am fairly new. I'm trying to move the second section tag down the page but it keeps overlapping with the other section.
I'm trying to make it in its own container without the body background overlapping it. Any help would be appreciated.
body {
background: url(https://cdn.pixabay.com/photo/2018/03/31/23/08/water-3279564_1280.jpg);
background-size: cover;
background-position: center;
text-align: center;
}
h1 {
padding-top: 20%;
padding-bottom: 40px;
}
h6 {
padding-bottom: 20px;
}
#content {
color: white;
}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="assets/css/oil.css">
<title>Oil Rig</title>
</head>
<body>
<section>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div id="content">
<h1>Welcome to Oil Rig Company</h1>
<h6>Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet</h6>
<button class="btn btn-warning">About Us</button>
</div>
</div>
</div>
</section>
<section class="about" id="about">
<div class="container">
<div class="row">
<div class="col-lg-6">
<img src="https://cdn.pixabay.com/photo/2012/04/13/14/34/oil-platform-32639_1280.png">
</div>
<div class="col-md-6">
<h3>Our Mission</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing anim id est laborum.</p>
</div>
</div>
</div>
</section>
</body>
</html>
I use Bootstrap V3.3.5. Screen divided in 3 columns horizontal.
Each column has different text length that can be changed by user.
Columns are responsive horizontal (by Bootstrap).
Goal... how to fix: I want same height for those 3 columns -boxes. Each columns-box must have the height of highest column-box.... so all column-boxes have same height.
Except....in Bootstrap "xs" mode, boxes are vertical (there is no problem).
Problem is in "sm, md and lg" mode (Bootstrap) when columns are horizontally next to each other.
EDIT:
I thought the problem was in the text, but it seems to be in the button of a bootstrap MODAL ... so I had not place the modal code in the first code.
I did: place style="white-space: normal;" (to fit text in modal) - seems there is a conflict with this style
Wanted:
Modal buttons height the same in bootstrap sm, md, lg mode (height of largest button)
Text begin at same height
Text fit in button
See snippet in Full-page mode!
Code:
<!doctype html>
<html>
<head>
<style>
.row {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
#media (max-width: 768px) {
.row {
flex-wrap: wrap;
}
}
.row > [class*='col-'] {
display: flex;
flex-direction: column;
}
</style>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></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">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
</head>
<body>
<!-- BootsTrap V 3.3.5 -->
<div class="container-fluid">
<div class="row RowHeight" >
<div class="col-xs-12 col-sm-3">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal_1" style="white-space: normal;">
Launch demo modal 11 11 111 111
</button>
<!-- Modal -->
<div class="modal fade" id="myModal_1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel_1">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel_1">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div> </div><!-- col2 -->
<!-- Button trigger modal (end) -->
<div class="col-xs-12 col-sm-3">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal_2" style="white-space: normal;">
Launch demo modal 2222 222 222 222 222 222 222 22222222 22 22222 2222
</button>
<!-- Modal -->
<div class="modal fade" id="myModal_2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel_2">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel_2">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div> </div><!-- col2 -->
<!-- Button trigger modal (end) -->
</div>
</div>
</body>
</html>
Use flexbox to achieve it, you can easily have the same height for all .box based on the max height column, I made a short example based on your code, take a look:
.box {
background-color: lightgray;
margin-left: 10px;
}
.row{
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.row > [class*='col-'] {
display: flex;
flex-direction: column;
}
<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">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<body>
<!-- BootsTrap V 3.3.5 -->
<div class="container-fluid">
<div class="row" >
<!-- for test! -->
<div class="col-xs-4 col-sm-4 box">
<p> Lorem ipsum dolor sit amet</p>
</div>
<div class="col-xs-4 col-sm-4 box">
<p> Lorem ipsum dolor sit amet, consec tetuer adipiscing consec elit.</p>
</div>
<div class="col-xs-4 col-sm-4 box">
<p> Lorem ipsum dolor sit amet, consec tetuer adipis cing elit. Aenean commodo ligula eget dolor. Aenean massa cing.</p>
</div>
</div>
</div>
</body>
You can also try like this:
.box {
background-color: lightgray;
padding: 5px 10px;
min-height: 200px;
}
#media (max-width: 768px) {
.box {
min-height: auto;
margin-bottom: 15px;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<!-- for test! -->
<div class="col-xs-12 col-sm-4">
<div class="box">
<p> Lorem ipsum dolor sit amet</p>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="box">
<p> Lorem ipsum dolor sit amet, consec tetuer adipiscing consec elit.</p>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="box">
<p> Lorem ipsum dolor sit amet, consec tetuer adipis cing elit. Aenean commodo ligula eget dolor. Aenean massa cing.</p>
</div>
</div>
</div>
Can u add this on your onload function `
var heighest = document.getElementsByClassName("box")[0].offsetHeight;
for(i = 1;i<3; i++){
if(heighest < document.getElementsByClassName("box")[i].offsetHeight){
heighest = document.getElementsByClassName("box")[i].offsetHeight;
}
}`
After that u can use heighest
.box {
background-color: lightgray;
height: heighest;
}
The simplest solution is to assign a hardcoded height to your "box" class, based on your highest column-box, for example:
.box {
height: 300px;
}
Other solution could be calculating your highest column box height via JavaScript and assign the same height to the other 2 boxes dynamically, also via JS.