bootstrap 2 background-colors in 1 row - css

I hope this question makes sense. I'm stummped at what to do. I am currently developing a site where a section of the page will have two seperate background colors (1 for the left and 1 for the right). This is what I am trying to go for:
<div class="gray-bg">
<div class="span6">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad, consequuntur illo impedit libero nam voluptatem sed facere earum quam ullam velit iste necessitatibus aperiam dolor id. Quod rerum est vel.</p>
</div>
</div>
<div class="white-bg">
<div class="span6">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci quam sapiente ut iusto neque. Obcaecati, molestiae, consequuntur qui blanditiis libero odio fuga eum iusto illo eaque inventore ipsa eligendi ipsam!</p>
</div>
</div>
I've tried several varations of this, putting rows under the span, putting containers and subrows in the span, but I'm not able to create the affect I want. Can anyone please help out? Thanks!
Update: Heres a JSFiddle of what I am trying to do. It works, but its not in a container to space out the row correctly. When I put it in the container, The blue on the left does not extend all the way.
http://jsfiddle.net/BVmUL/622/

try the following: Bootply demo
<div class="container">
<div class="row">
<div class="span6">
<div class="gray-bg">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad, consequuntur illo impedit libero nam voluptatem sed facere earum quam ullam velit iste necessitatibus aperiam dolor id. Quod rerum est vel.</p>
</div>
</div>
<div class="span6">
<div class="white-bg">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci quam sapiente ut iusto neque. Obcaecati, molestiae, consequuntur qui blanditiis libero odio fuga eum iusto illo eaque inventore ipsa eligendi ipsam!</p>
</div>
</div>
</div>
</div>
css:
.gray-bg {
background-color:red;
}
.white-bg {
background-color:green;
}

Related

Implementing this design in CSS

I am trying to implement the design attached at the bottom. I am going to use CSS-grid to the implement the full design, however, I'm facing some trouble as to how to implement the part I have circled out.
I have thought of separating the left and the right part into separate columns under a single row to implement the overall design.
Current design
Target design
I'll attach my existing code below for better reference
import "./Content1.css";
export default function Content1() {
return (
<div className="row">
<div className="col-1"></div>
<div className="col-7 content1-content">
<h3>Justo Vulputate Tortor Sem</h3>
<h5>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nam deleniti
aliquam corrupti eius ratione rem veniam. Impedit qui obcaecati minus
at omnis delectus doloribus suscipit! In nesciunt maiores adipisci
inventore?
</h5>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iusto
reiciendis harum a cumque itaque non, deleniti, reprehenderit maxime
necessitatibus eum natus magnam, quasi voluptatem sapiente. Harum
aliquid facilis inventore.
</p>
</div>
<div className="col-4"></div>
</div>
);
}

how can i make cards equal height in react with react bootstrap? [duplicate]

This question already has answers here:
How to make Bootstrap 4 cards the same height in card-columns?
(22 answers)
Closed 9 months ago.
I using react with react-bootstrap. I want to design these card as a same height. For instance as in the attach image, when my second card title is break. So it needs to card height, then height of the second and 3rd card is increased, but first card has a small card title, so card take less height. I want all these card same heights, even other card height increase all card height increase.
is this possible with custom CSS or bootstrap classes?
If you can add custom CSS, using "display: flex" on the card's parent should do the trick. If you need to force the strech, you can add "align-items: stretch".
.wrapper {
display: flex;
justify-content: space-between;
align-items: stretch;
}
.card {
background: grey;
padding: 15px;
width: 30%;
}
<div class="wrapper">
<div class="card">
<h1>hello</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos, recusandae, error! Quos repellat qui autem velit, laboriosam temporibus, incidunt accusantium similique vitae harum quod asperiores corporis dolore cum amet omnis.
</p>
</div>
<div class="card">
<h1>hello</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos, recusandae, error! Quos repellat qui autem velit, laboriosam temporibus, incidunt accusantium similique vitae harum quod asperiores corporis dolore cum amet omnis.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos, recusandae, error! Quos repellat qui autem velit, laboriosam temporibus, incidunt accusantium similique vitae harum quod asperiores corporis dolore cum amet omnis.
</p>
</div>
<div class="card">
<h1>hello</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos, recusandae, error! Quos repellat qui autem velit, laboriosam temporibus, incidunt accusantium similique vitae harum quod asperiores corporis dolore cum amet omnis.
</p>
</div>
</div>

align items using css flexbox with read more button at the bottom

this is the default structure of two side by side divisions,
I want to keep the read more button at the bottom of the screen even the content is less.
<div class="row">
<div class="col-12"> Image </div>
<div class="col-12">
<h1>Lorem ipsum</h1>
<p>all the content which will be strecth to full height</p>
<a>Read more</a>
</div>
</div>
Also when i make row 100% heigth and align item : strecth, I am getting space between two columns.
As pointed by IvanS95, you can use Card Deck component of Bootstrap. If you really want to use the flexbox on your own probably below solution can be helpful.
The below solution uses Bootstrap 4.4.1
You can view the working code pen solution here
.image-style {
max-width: 100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container py-4">
<div class="row">
<div class="col-6 p-2 d-flex flex-column justify-content-start">
<img src="https://picsum.photos/500/250" class="image-style" />
<h4 class="px-2 mt-2">Lorem ipsum title</h4>
<p class="px-2">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
<p class="px-2">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus, fugit. Fugit iure qui expedita, necessitatibus beatae quaerat distinctio soluta quam ut enim doloremque mollitia ratione illo officiis, quibusdam fuga voluptate.
</p>
<p class="px-2">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quas architecto odit repudiandae libero ex, neque modi explicabo quia delectus qui natus officiis nihil autem sit alias ab odio quisquam. Perferendis?
</p>
Read more
</div>
<div class="col-6 p-2 d-flex flex-column justify-content-start">
<img src="https://picsum.photos/500/250" class="image-style" />
<h4 class="px-2 mt-2">Lorem ipsum title</h4>
<p class="px-2">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
<p class="px-2">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus, fugit. Fugit iure qui expedita, necessitatibus beatae quaerat distinctio soluta quam ut enim doloremque mollitia ratione illo officiis, quibusdam fuga voluptate.
</p>
Read more
</div>
</div>
</div>
In above html inside row there are two 6 unit wide columns that can sit side by side. Each column is converted to flex box using d-flex class, flex direction is set to column using flex-column class and using set the justify-content using justify-content-start class. Now, if I set margin-top to auto on read more button it will always stick to bottom.
To make sure the image width does not create problems I have set the image-style class on the image element which is defined as follows,
CSS
image-style {
max-width: 100%;
}
You can go with code that #Hiren suggested but you also don't need to use a flexbox if you don't want to. Here is an example of how you can achieve the wanted layout:
<div class="container">
<div class="row">
<div class="col-6">
<div class="card">
<img src="https://picsum.photos/500/250" class="image-style" />
<h4>Lorem ipsum title</h4>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
Read more
</div>
</div>
<div class="col-6">
<div class="card">
<img src="https://picsum.photos/500/250" class="image-style" />
<h4>Lorem ipsum title</h4>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Praesentium ab inventore corrupti fugiat aperiam beatae nisi quod mollitia, soluta dolorum sequi blanditiis delectus ex impedit quia? Expedita eius libero adipisci!
</p>
Read more
</div>
</div>
</div>
</div>
CSS:
.card {
position: relative;
height: 100%;
padding: 10px;
padding-bottom: 30px;
}
.read-more-button {
position: absolute;
left: 10px;
bottom: 15px;
}
As you can see, I added padding to the parent element (card) and an absolute position to the 'read more' button. This is how we did it when there was no flexbox.
Note that I still use the Bootstrap (which is flexbox).

Column top offset in css grid

I need some help with my css code.
I'm using css grid.
I have 2 columns.
How to add a top offset for the right column?
That is result that I want to get:
.parent {
background-color:#ddd;
display:grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
}
.child {
background-color:#aaa;
padding:15px;
}
<div class="parent">
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, </p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus? in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus? in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
</div>
There is just a dummy text because stackoverflow thinks there is not enough details for submit my question.
You can use top: 20px for the even child element. (Remember to set position: relative to child element)
.parent {
background-color: #ddd;
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
padding-bottom: 20px;
}
.child {
background-color: #aaa;
padding: 15px;
}
.child:nth-of-type(even) {
top: 20px;
position: relative;
}
<div class="parent">
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, </p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus? in quam quae adipisci
vel culpa quibusdam, iure expedita nam doloribus? in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
<div class="child">
<h1>title</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum provident adipisci, voluptates aliquam corporis magnam. Dolor aliquam reprehenderit molestiae in quam quae adipisci vel culpa quibusdam, iure expedita nam doloribus?</p>
</div>
</div>

Make a position absolute element appear like it is still in the document flow?

I have a div which is position absolute causing the proceeding content to sit over it which is understandable, I was wondering how I can have the div remain as position: absolute but have the content continuing as if the div was still in the document flow? Would this call for a padding bottom trick on the absolute content?
HTML
<div class="content">
<h1>Heading</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet provident aperiam consequuntur veniam repellendus eaque repudiandae, modi architecto aut fugit esse nostrum quidem quo molestiae quasi! Sed facilis, molestias perspiciatis.</p>
<div class="absolute">
<h2>Position absolute content</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem distinctio hic quidem vero tenetur ad mollitia voluptas libero, voluptates dolore quasi doloremque id cum! Facilis qui similique facere commodi quisquam.</p>
</div>
<div>
<h2>Heading 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium voluptas non dolor facilis natus nam. Voluptas commodi illum aut quasi voluptatibus cupiditate doloribus at officia voluptates. Reiciendis placeat delectus repellendus.</p>
</div>
</div>
CSS
.absolute {
position: absolute;
}
JsFiddle: https://jsfiddle.net/mz41jzqd/
function updateTopMargin(){
var abs = $('.absolute').eq(0);
abs.next().css({'margin-top':abs.outerHeight()+'px'});
}
$(window).on('load resize', updateTopMargin);
$('.absolute').on('resize', updateTopMargin);
.absolute {
position: absolute;
}
.absolute + * {
padding-top: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content">
<h1>Heading</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet provident aperiam consequuntur veniam repellendus eaque repudiandae, modi architecto aut fugit esse nostrum quidem quo molestiae quasi! Sed facilis, molestias perspiciatis.</p>
<div class="absolute">
<h2>Position absolute content</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem distinctio hic quidem vero tenetur ad mollitia voluptas libero, voluptates dolore quasi doloremque id cum! Facilis qui similique facere commodi quisquam.</p>
</div>
<div>
<h2>Heading 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium voluptas non dolor facilis natus nam. Voluptas commodi illum aut quasi voluptatibus cupiditate doloribus at officia voluptates. Reiciendis placeat delectus repellendus.</p>
</div>
</div>

Resources