I'm trying to create a page using css grid and flex. I have defined the grid areas and positioned them.
When I'm adding content to blog-post-list section contents goes beyond <section> the specified area.
I'm expecting 3rd and 4th blog-card boxes to go to next row rather than going across the aside. Shouldn't it act like a container if it has more content its height get increase ?
TIA
body{
color: #000;
text-align: center;
}
.content{
display:grid;
grid-template-columns: repeat(12,1fr);
grid-auto-rows: minmax(50px, auto);
grid-gap: 2px;;
max-width:960px;
margin: 0 auto;
}
.content > *{
background: #3bbced;
padding: 30px;
}
header{
grid-column: 1/13;
}
nav{
grid-column: 1/13;
}
section{
grid-column: 1/8;
grid-row: 3/9;
}
aside{
grid-column: 8 /13;
grid-row: 3/9;
}
footer{
grid-column: 1 / 13;
}
.blog-post-list{
display: flex;
}
.blog-card{
border: 1px solid black;
padding: 20px;
margin: 15px;
min-width: 38%;
}
<div class="content">
<header>
header
</header>
<nav>
Navigation
</nav>
<section>
<div class="blog-post-list">
<div class="blog-card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</div>
<div class="blog-card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</div>
<div class="blog-card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</div>
<div class="blog-card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</div>
</div>
</section>
<aside>
aside
</aside>
<footer>
Footer
</footer>
</div>
You should change this part with flex-wrap. If you want to have all in same row then you should give smaller percentage for child elements
.blog-post-list{
display: flex;
flex-wrap: wrap;
}
body{
color: #fff;
text-align: center;
}
.content{
display:grid;
grid-template-columns: repeat(12,1fr);
grid-auto-rows: minmax(50px, auto);
grid-gap: 2px;;
max-width:960px;
margin: 0 auto;
}
.content > *{
background: #3bbced;
padding: 30px;
}
header{
grid-column: 1/13;
}
nav{
grid-column: 1/13;
}
section{
grid-column: 1/8;
grid-row: 3/9;
}
aside{
grid-column: 8 /13;
grid-row: 3/9;
}
footer{
grid-column: 1 / 13;
}
.blog-post-list{
display: flex;
flex-wrap: wrap;
}
.blog-card{
border: 1px solid black;
padding: 20px;
margin: 15px;
min-width: 38%;
}
<div class="content">
<header>
header
</header>
<nav>
Navigation
</nav>
<section>
<div class="blog-post-list">
<div class="blog-card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</div>
<div class="blog-card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</div>
<div class="blog-card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</div>
<div class="blog-card">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
</div>
</div>
</section>
<aside>
aside
</aside>
<footer>
Footer
</footer>
</div>
Related
I was trying to create a layout with 5 columns,
the height should be stretch by its content,
so i cannot set a fixed height for it,
but it doesn't work in my codepen work
https://codepen.io/yyywork/pen/MWGLJwN
body {
height: 100%;
}
#outer-container {
display: flex;
flex-direction: row;
height: 100%;
}
#inner-container {
flex-grow: 1;
column-count: 5;
height: 100%;
}
.item {
break-inside: avoid;
height: 100%;
}
<div id="outer-container">
<div id="inner-container">
<div class="item item-1">
<b>Col 1</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type sp
</div>
<div class="item item-2">
<b>Col 2</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="item item-3">
<b>Col 3</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="item item-4">
<b>Col 4</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="item item-5">
<b>Col 5</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type sp
</div>
</div>
</div>
Try to use below CSS its working perfectly on Chrome and Mozilla Firefox.
#inner-container {
display: flex;
flex-direction: row;
align-items: stretch;
}
.item {
flex-basis: calc(100% / 5);
border:1px solid #000;
}
<div id="outer-container">
<div id="inner-container">
<div class="item item-1">
<b>Col 1</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type sp
</div>
<div class="item item-2">
<b>Col 2</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="item item-3">
<b>Col 3</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="item item-4">
<b>Col 4</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="item item-5">
<b>Col 5</b> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type sp
</div>
</div>
</div>
I am trying to change below the CSS to flex but not working. instead of display block and width 100%, I want to do in flex. What is the equal of display block and width 100% in flex?
h1,
h2 {
font-family: Lato;
}
div {
display: flex;
flex-direction: row;
align-items: flex-end;
}
.test1 {
display: flex;
flex-direction: column;
align-items: flex-start;
background-color: #3fd819;
}
.test2 {
background-color: rgb(122, 117, 202);
margin: 5px;
width: 100%;
display: block;
}
.container {
position: relative;
display: inline-block;
flex-direction: column;
}
<div class="container">
<div>
<div class="test1">
<div class="test2">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book.
</div>
</div>
</div>
</div>
You're over-thinking it. Assuming you can't change the markup, all you need is this:
.test1 {
border: 5px solid #3fd819;
background-color: rgb(122, 117, 202);
}
.test2 {
display: contents;
}
<div class="container">
<div>
<div class="test1">
<div class="test2">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book.
</div>
</div>
</div>
</div>
If you anticipate having multiple .test2 children of div.test1 and you want them stacked vertically, then that's also simple:
.test1 {
border: 5px solid #3fd819;
background-color: rgb(122, 117, 202);
}
.test2 {
margin: 1em;
}
<div class="container">
<div>
<div class="test1">
<div class="test2">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book.
</div>
<div class="test2">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book.
</div>
<div class="test2">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book.
</div>
</div>
</div>
</div>
My issues:
I am creating a webiste with articles and I have to make that site for responsive.
I am using CSS GRID for my site. I have a problem on mobile devices.
I have two types of articles (picture on the left and picture on the right). But when viewed on mobile devices, these two pictures are not under the articles. The image from the first articles should be at the bottom.
#news_content {
padding: 215px 15px 0px 15px;
}
#news_content>.row {
grid-template-columns: repeat(12, 8.533333%);
}
#news_content>.row>.col-1 {
grid-column: span 6;
}
#news_content>.row>.col-1>.col-1-padding {
padding: 20px 0px 0px 30px;
}
#news_content>.row>.col-2 {
grid-column: span 6;
}
#news_content>.row>.col-2>.col-2-padding {
padding: 20px 0px 20px 30px;
}
#media (max-width: 720px) {
#news_content>.row>.col-1,
#news_content>.row>.col-2 {
grid-column: span 12;
}
}
#media (max-width: 720px) {
#news_content {
padding: 50px 45px 0px 15px;
}
}
<div id="news_content" class="grid">
<div class="row">
<div class="col-1">
<div class="col-1-padding">
<img src="https://via.placeholder.com/300x200" id="Image_style">
</div>
</div>
<div class="col-2">
<div class="col-2-padding">
<h1>Lorem Lorem?</h1>
<p class="news">
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem
Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</p>
</div>
</div>
</div>
</div>
<div id="news_content" class="grid">
<div class="row">
<div class="col-1">
<div class="col-1-padding">
<h1>Lorem Lorem?</h1>
<p class="news">
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</p>
<p>
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem
Ipsum is simply dummy text of the printing and typesetting industry. Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</p>
</div>
</div>
<div class="col-2">
<div class="col-2-padding">
<img src="https://via.placeholder.com/300x200" id="Image_style">
</div>
</div>
</div>
</div>
<div id="news_content" class="grid">
<div class="row">
<div class="col-1">
<div class="col-1-padding">
<img src="img/poco.jpg" id="Image_style">
</div>
</div>
<div class="col-2">
<div class="col-2-padding">
<h1>Lorem Lorem?</h1>
<p class="news">
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</p>
</div>
</div>
</div>
</div>
<div id="news_content" class="grid">
<div class="row">
<div class="col-1">
<div class="col-1-padding">
<h1>Lorem Lorem?</h1>
<p class="news">
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</p>
<p>
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</p>
</div>
</div>
<div class="col-2">
<div class="col-2-padding">
<img src="img/video.jpg" id="Image_style">
</div>
</div>
</div>
</div>
#news_content
{
padding: 215px 15px 0px 15px;
}
#news_content > .row
{
grid-template-columns: repeat(12, 8.533333%);
}
#news_content > .row > .col-1
{
grid-column: span 6;
}
#news_content > .row > .col-1 > .col-1-padding
{
padding: 20px 0px 0px 30px;
}
#news_content > .row > .col-2
{
grid-column: span 6;
}
#news_content > .row > .col-2 > .col-2-padding
{
padding: 20px 0px 20px 30px;
}
#media (max-width: 720px)
{
#news_content > .row > .col-1, #news_content > .row > .col-2
{
grid-column: span 12;
}
}
#media (max-width: 720px)
{
#news_content
{
padding: 50px 45px 0px 15px;
}
}
I am trying to create something similar to https://www.pinterest.com/ homepage where height is decided as per content of Div & all divs automatically adjusts it self using bootstrap.
I tried to do it but It is not working as expected.
Here is fiddle link of what I have tried http://jsfiddle.net/gmm2jcn5/
In fiddle we can see that there is white gap between 2 divs I want to eliminate that gap.
.col-xs-6 {
border: 1px solid black;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.0.1/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-6">
<p class="inntertopheading">heading</p>
<div class="hr"></div>
<div class="innter-md-text">
text
<div class="spacer10"></div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div class="col-xs-6">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="col-xs-6">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="col-xs-6">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
</div>
</div>
vaibhav shah Hi there.
To have each div block have the same Height no matter the content you could use a little jquery like this...
$(document).ready( function(){
var heightArray = $(".block1").map( function(){
return $(this).height();
}).get();
var maxHeight = Math.max.apply( Math, heightArray);
$(".block2").height(maxHeight);
$(".block3").height(maxHeight);
})
Here is a working Fiddle.
Does this help for what you are wanting here?
If you resize the window with your mouse just refresh and see the div blocks change to all having the same height.
Try the CSS3 column method, this will only require CSS, no modification of markup. The below script will adjust anywhere from 1 to 5 columns based on viewport width:
.col-xs-6 {
display: inline-block;
width: 100%;
border: 1px solid black;
-webkit-column-break-inside: avoid;
-moz-column-break-inside: avoid;
-o-column-break-inside: avoid;
-ms-column-break-inside: avoid;
column-break-inside: avoid;
}
/* Custom, iPhone Retina */
#media only screen and (min-width: 320px) {
.row {
-moz-column-count: 1;
-moz-column-gap: 0px;
-webkit-column-count: 1;
-webkit-column-gap: 0px;
column-count: 1;
column-gap: 0px;
width: 100%;
}
}
/* Extra Small Devices, Phones */
#media only screen and (min-width: 480px) {
.row {
-moz-column-count: 2;
-moz-column-gap: 10px;
-webkit-column-count: 2;
-webkit-column-gap: 10px;
column-count: 2;
column-gap: 10px;
width: 100%;
}
}
/* Small Devices, Tablets */
#media only screen and (min-width: 768px) {
.row {
-moz-column-count: 3;
-moz-column-gap: 10px;
-webkit-column-count: 3;
-webkit-column-gap: 10px;
column-count: 3;
column-gap: 10px;
width: 100%;
}
}
/* Medium Devices, Desktops */
#media only screen and (min-width: 992px) {
.row {
-moz-column-count: 4;
-moz-column-gap: 10px;
-webkit-column-count: 4;
-webkit-column-gap: 10px;
column-count: 4;
column-gap: 10px;
width: 100%;
}
}
/* Large Devices, Wide Screens */
#media only screen and (min-width: 1200px) {
.row {
-moz-column-count: 5;
-moz-column-gap: 10px;
-webkit-column-count: 5;
-webkit-column-gap: 10px;
column-count: 5;
column-gap: 10px;
width: 100%;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.0.1/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-6">
<p class="inntertopheading">heading</p>
<div class="hr"></div>
<div class="innter-md-text">
text
<div class="spacer10"></div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div class="col-xs-6">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="col-xs-6">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</div>
<div class="col-xs-6">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's
</div>
</div>
I am doing css/html for a school assignment, but I got stuck. I am trying to build a newsoverview but I don't know how to build this in the good/qualitative way.
Problems:
Is this a good way to put 'Laatste nieuws' in that position?
I want to get rid of the div's because I think it will be better to
use ul/li, but I don't know how I can use it in this case.
Positioning title and description of each article like the 1st
picture.
I need:
http://i.imgur.com/vz51zyA.png
I have:
http://i.imgur.com/4wTmtXu.png
<div id="newsListContainer">
<div id="newsListHeader"><h1>Laatste nieuws</h1></div>
<div class="newsListItem">
<img src="img/item3.jpg" width="100" height="75">
<h2> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
CSS:
#newsListContainer {
float:left;
width:100%;
background: url("img/body_bg.png") repeat-y;
}
#newsListHeader{
float:left;
width:690px;
height:40px;
margin-top:10px;
margin-bottom:10px;
border-bottom:1px solid #d6d6d6;
margin-left:133px;
}
.newsListItem {
margin-left:150px;
}
.newsListItem img{
float:left;
}
HTML UPDATED:
<div id="newsListContainer">
<div id="newsListHeader"><h1>Laatste nieuws</h1></div>
<ul><li class="newsListItem">
<img src="img/item3.jpg">
<h2> Lorem Ipsum is simply dummy text of </h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
</li></ul>
<ul><li class="newsListItem">
<img src="img/item3.jpg">
<h2> Lorem Ipsum is simply dummy text of </h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
</li></ul>
</div>
CSS UPDATED:
#newsListContainer {
float:left;
width:100%;
background: url("img/body_bg.png") repeat-y;
}
#newsListHeader{
float:left;
width:690px;
height:40px;
margin-top:10px;
margin-bottom:10px;
border-bottom:1px solid #d6d6d6;
margin-left:133px;
}
.newsListItem {
/*margin-left:150px;*/
padding-left: 115px;
}
.newsListItem img{
float:left;
width: 100px;
margin-left: -115px; /* SAME AS PADDING ABOVE */
In answer to your questions, and trying not to do your assignment for you:
Yes, the header is outside the 'list' of items which is good. Do you need the <div id="newsListHeader"> container though?
A list would be better, try it and see how you get on (<ul><li class="newsListItem">News item here</li></ul>).
This can be tricky at first and there's many ways of doing it (css html news list creation little help please). My preferred technique if I know the width of the image, is to add a padding to the .newsItemContainer and then negatively margin back the image by the same width. That means that the text will always line up along that padding line.
Code snippet:
.newsListItem {
padding-left: 115px;
}
.newsListItem img {
float: left;
width: 100px;
/* Added */
margin-left: -115px;
/* SAME AS PADDING ABOVE */
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class="newsListItem">
<img src="http://placehold.it/100x75" width="100" height="75">
<h2> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="newsListItem">
<img src="http://placehold.it/100x75" width="100" height="75">
<h2> Lorem Ipsum is simply dummy text of the printing and typesetting industry. </h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</body>
</html>
.newsListItem img{
float:left;
margin-right:16px;
}