I'm currently trying to figure out why my blank image placeholders aren't showing up when I use CSS grid. No matter what selectors I use and how I use them, I can't seem to figure out how to make it appear.
I've tried messing around with the class selectors and styles to make it appear, but I've been getting no luck in getting it to pop up. This is my current code right now revolving around the image placeholders:
.story {
display: flex;
flex-flow: row nowrap;
justify-content: flex-start;
align-items: flex-start;
align-content: flex-start;
gap: 1.618rem;
}
.story:nth-child(even) {
flex-direction: row-reverse;
}
.story .image {
aspect-ratio: 1;
background-color: #dadada;
flex: 0 0 calc(50% - 1.618rem);
}
.story .description {
flex: 1 0 50%;
}
#media screen and (min-width: 576px){
.story .image {
flex-basis: 30%;
}
}
#media screen and (min-width: 992px){
.story,
.story:nth-child(even) {
flex-flow: column wrap;
}
.story .image {
aspect-ratio: 16/9;
flex: 0 0 100%;
width: 100%;
background-color: blue;
}
}
And my HTML:
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-4 col-xl-12">
<h2>Articles</h2>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-xl-4">
<div class="story">
<div class="image">Image</div>
<div class="description">
<h2>Story Name</h2>
<p>Lorem ipsum...</p>
Link
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-xl-4">
<div class="story">
<div class="image">Image</div>
<div class="description">
<h2>Story Name</h2>
<p>Lorem ipsum...</p>
Link
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 col-xl-4">
<div class="story">
<div class="image">Image</div>
<div class="description">
<h2>Story Name</h2>
<p>Lorem ipsum...</p>
Link
</div>
</div>
</div>
</div>
</div>
Please help me understand what I am doing wrong! T_T
Related
I'm trying to achieve this, where brown gets pushed down when pink is too long, and pink is dynamically sized based on its text content.
I was only able to achieve this using javascript and two templates, if pink length is over X use second template, but I'm wondering if there's a way to achieve this using CSS only?
I tried meddling with grid auto-fill/auto-fit with minmax, float, flex with wrap, but I couldn't get to the desired result with these.
.parent {
width: 170px;
}
.flex {
display: flex;
}
div {
outline: 2px solid rgba(255, 0,0, 0.3);
}
<div>
<p>scenario A</p>
<div class="parent flex">
<div>
<div class="one">A short title</div>
<div class="three">Some text here</div>
<div class="three">some more text</div>
</div>
<div>
<button>A button</button>
</div>
</div>
</div>
<div>
<p>scenario B</p>
<div class="parent">
<div class="one">Testing a very long title</div>
<div class="flex">
<div>
<div class="three">Some text here</div>
<div class="three">some more text</div>
</div>
<div>
<button>A button</button>
</div>
</div>
</div>
</div>
<p>can a component achieve both a and b with only css?
I found a solution, it requires having fixed height in the first row, and the right side button will basically overflow when needed.
Will wait a bit before accepting my own solution in case someone came with a better one.
.container {
width: 300px;
display: flex;
gap: 10px;
padding: 16px;
font-size: 14px;
font-family: Arial;
}
.text {
flex: 1;
min-width: 0;
}
.first-row {
height: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
.image {
width: 40px;
height: 40px;
border-radius: 50%;
background-color: #444;
}
.title {
flex-grow: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<h2>Long title</h2>
<div class="container">
<div class="image"></div>
<div class="text">
<div class="first-row">
<div class="title">Test title test title test title</div>
<button>Visit store</button>
</div>
<div class="three">in the stores</div>
<div class="three">sponsored</div>
</div>
</div>
<h2>Short title</h2>
<div class="container">
<div class="image"></div>
<div class="text">
<div class="first-row">
<div class="title">Short title</div>
<button>Visit place</button>
</div>
<div class="three">in the stores</div>
<div class="three">sponsored</div>
</div>
</div>
<h2>Very long title</h2>
<div class="container">
<div class="image"></div>
<div class="text">
<div class="first-row">
<div class="title">Test title test titleTest title test titleTest title test title</div>
<button>Visit place</button>
</div>
<div class="three">in the stores</div>
<div class="three">sponsored</div>
</div>
</div>
The requirement here is to display a series of nested, centered CSS grid items. We're rendering something like a hierarchical tree, with the head node on top, then second level nodes, third level nodes, and so on.
The problem is that later levels run off the div in the negative and positive X-axis directions.
Setting overflow-x: scroll solves the problem only for the positive X-axis direction. That is to say, you can scroll to the right, but not to the left.
The example below is a greatly simplified example of the real problem I'm trying to address. The red element on the 3rd level is off the page in the negative X-axis. You can scroll to the right, but not the left.
What can be done to make it so the entire tree, and all nodes, are able to be scrolled to?
Code follows(Link to JS Fiddle.):
#tree {
overflow-x: scroll;
}
.flex-col {
display: flex;
flex-direction: column;
align-items: center;
}
.grid {
display: grid;
}
.content {
width: 300px;
border-radius: 5px;
background-color: blue;
color: white
}
<div id="tree" class="flex-col">
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1">
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1;">
<div class="content" style="background-color: red;">** This is off the screen **</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
</div>
</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1">
<div class="content">Content</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
</div>
</div>
</div>
</div>
</div>
You can create an extra wrapper inside the tree element which will be an inline flexbox container so that it takes as much space as its contents. Use text-align: center to center the tree when there is no scroll - see demo below:
#tree {
overflow-x: auto; /* overflow horizontally here */
text-align: center; /* align horizontally */
}
#tree > .flex-col {
display: inline-flex; /* inline flex container */
text-align: initial; /* reset text align to default left */
}
.flex-col {
display: flex;
flex-direction: column;
align-items: center;
}
.grid {
display: grid;
}
.content {
width: 300px;
border-radius: 5px;
background-color: blue;
color: white
}
<div id="tree">
<div class="flex-col"> <!-- <-- extra wrapper -->
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1">
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1;">
<div class="content" style="background-color: red;">** This is off the screen **</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
</div>
</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1">
<div class="content">Content</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
</div>
</div>
</div>
</div>
</div>
</div>
You need to make sure that the grid elements don't expand wider than their container.
To resolve this, you can set max-width: 100% on .grid:
#tree {
overflow-x: scroll;
}
.flex-col {
display: flex;
flex-direction: column;
align-items: center;
}
.grid {
display: grid;
max-width: 100%;
}
.content {
width: 300px;
border-radius: 5px;
background-color: blue;
color: white
}
<div id="tree" class="flex-col">
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1">
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1;">
<div class="content" style="background-color: red;">** This is off the screen **</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
</div>
</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
<div class="grid">
<div class="flex-col" style="grid-column: 1">
<div class="content">Content</div>
</div>
<div class="flex-col" style="grid-column: 2">
<div class="content">Content</div>
</div>
</div>
</div>
</div>
</div>
I'm trying to make a grid of 5 boxes (divs) where the first one has a portrait layout, and the rest have half the height of the first one (screenshot below)
My HTML looks like this:
<div class="container">
<div class="row">
<div class="col-md-4 portrait"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
</div>
It would have been easy using float:left and display block, but i'm using bootstrap 4 which uses flexbox so no support for float left and i can't get it to work as expected. Is there a way to do this even with flexbox ?
PS: the row div has flex-wrap: wrap;
.row {
display: flex;
flex-wrap: wrap;
flex-direction: column;
display: -webkit-flex;
-webkit-flex-wrap: wrap;
-webkit-flex-direction: column;
height: 200px;
justify-content: flex-start;
}
.col-md-4 {
flex: 0 0 50%;
-webkit-flex: 0 0 50%;
background: green;
}
.portrait {
-webkit-flex: 0 0 100%;
flex: 0 0 100%;
background: blue;
}
.red {
background: red;
}
<div class="container">
<div class="row">
<div class="col-md-4 portrait"></div>
<div class="col-md-4 red"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4 red"></div>
</div>
</div>
You can use the following to achieve the results displayed in your image.
<div class="container">
<div class="row">
<div class="col-md-6 portrait">PUT YOUR PORTRAIT CONTENT HERE</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6">TOP LEFT AFTER PORTRAIT</div>
<div class="col-md-6">TOP RIGHT AFTER PORTRAIT</div>
</div>
<div class="row">
<div class="col-md-6">BOTTOM LEFT AFTER PORTRAIT</div>
<div class="col-md-6">BOTTOM RIGHT AFTER PORTRAIT</div>
</div>
</div>
</div>
</div>
This is done by creating a new row, inside of a col, which is itself inside of another row.
Issue: So vertical alignment issue is I have two divs in the last column and I'm trying to get one to stay at top and one to stay at the bottom regardless of how the central column grows. I can work this out by using fixed heights but that's no good in this case.
Here is my code example : JS Fiddle
HTML:
<div class="row" class="property-bundle"><!-- (x) number of these -->
<div class="col-xs-11 wrapper">
<div class="row">
<div class="col-xs-2 pull-left vendor">
<img src="http://placehold.it/100x100" />
</div>
<div class="col-xs-8 properties-list">
<div class="row" class="property-line">
<div class="col-xs-2"><img src="http://placehold.it/80x140" /></div>
<div class="col-xs-10"><p>Flat 1</p></div>
</div>
<div class="row"><hr/></div>
<div class="row" class="property-line">
<div class="col-xs-2"><img src="http://placehold.it/80x140" /></div>
<div class="col-xs-10"><p>Flat 2</p></div>
</div>
<div class="row"><hr/></div>
<div class="row" class="property-line">
<div class="col-xs-2"><img src="http://placehold.it/80x140" /></div>
<div class="col-xs-10"><p>Flat 3</p></div>
</div>
</div>
<div class="col-xs-2 costs"><!-- costs column -->
<div class="row total">
<h3 class="text-right">TOTAL: £1,2M</h3><!--stay at top-->
</div>
<div class="row" class="fees"> <!--stay at bottom-->
<div class="col-xs-12">
<hr/>
<p class="text-right">+ Materials £300K</p>
<p class="text-right">+ Build £100K</p>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.wrapper {border: 1px solid black; padding: 10px; margin: 15px;}
.vendor {min-width: 120px;}
.properties-list {background-color: aquamarine}
.costs {vertical-align: top; min-width: 150px; vertical-align: center}
.fees {vertical-align: bottom; }
h3 {font-weight: 400}
h4 {color: green}
.total { margin-right: 0px; }
Hi you can try using flexbox
I just change your html like this:
<div class="col-xs-2 costs">
<!--stay at top-->
<div class="total">
<h3 class="text-right">TOTAL: £1,2M</h3>
</div>
<hr/>
<div class="materials">
<p class="text-right">+ Materials £300K</p>
<p class="text-right">+ Build £100K</p>
</div>
</div>
</div>
Then I add on costs div display:flex;and on total div flex-grow: 1 This flex-grow will push materials on bottom of div.
You just need to add on body, html, row and costs div height:100%
Here is css:
.costs {
vertical-align: center;
display: flex;
flex-direction: column;
height: 100%;
}
.total {
flex-grow: 1;
}
You can see example on this link: https://jsfiddle.net/3L5Lbwhn/9/
Ok I simplified this a bit, but essentially flex did what I needed so many thanks to Edin Puzic for putting me on the right lines! It also allowed me to fix the 1st and last col width and make the middle one dynamic horiontally too.
JsFiddle
<div class="row-flex">
<div class="col-flex-1">
<img src="http://placehold.it/100x100" />
</div>
<div class="col-flex-2">
<div class="row" class="property-line">
<div class="col-xs-2"><img src="http://placehold.it/80x140" /></div>
<div class="col-xs-10">
<p>Flat 1</p>
</div>
</div>
<div class="row">
<hr/>
</div>
<div class="row" class="property-line">
<div class="col-xs-2"><img src="http://placehold.it/80x140" /></div>
<div class="col-xs-10">
<p>Flat 2</p>
</div>
</div>
<div class="row">
<hr/>
</div>
<div class="row" class="property-line">
<div class="col-xs-2"><img src="http://placehold.it/80x140" /></div>
<div class="col-xs-10">
<p>Flat 3</p>
</div>
</div>
</div>
<div class="col-flex-3">
<div class="pos-top">
<div class="row right-text">
TOP right
</div>
</div>
<div class="pos-bottom">
<div class="row right-text">
<p>
BOTTOM right
</p>
</div>
</div>
</div>
</div>
CSS
.row-flex {
height: auto;
display: flex;
flex-flow: row column;
}
.col-flex-1 {
min-width: 200px;
border-left: 1px #ccc solid;
flex: 0 0;
}
.col-flex-2 {
width: 80%;
border-left: 1px #ccc solid;
flex: 1 1;
}
.col-flex-3 {
min-width: 200px;
border-left: 1px #ccc solid;
flex: 0 0;
}
.flex-container {
display: -webkit-flex;
display: flex;
width: 100%;
height: 100%;
background-color: lightgrey;
}
.pos-top {
display: -webkit-flex;
display: flex;
height: 50%;
width: 100%;
-webkit-align-items: flex-start;
align-items: flex-start;
background-color: yellow;
}
.pos-bottom {
display: -webkit-flex;
display: flex;
height: 50%;
width: 100%;
-webkit-align-items: flex-end;
align-items: flex-end;
background-color: green;
}
.right-text {
text-align: right;
width: 100%;
}
I've seen this thread but its for 2 column (col-md-6) and I've tried the jsfidlle too for 3 column but column 1st and column 2nd become stack.
Bootstrap 3 Align Text To Bottom of Div
what I want for my project is
.row {
position: relative;
}
.bottom-align-text {
position: absolute;
bottom: 0;
right: 0;
}
<div class="container">
<div class="row">
<div class="bottom-align-text col-sm-4">
<h3>Some Text</h3>
</div>
<div class="col-sm-4">
<img src="//placehold.it/600x300" alt="Logo" class="img-responsive"/>
</div>
<div class="bottom-align-text col-sm-4">
<h3>Some Text</h3>
</div>
</div>
</div>
how to make them both align bottom?
flexbox can do that
.row div {
border: 1px solid red;
}
.flexy {
display: flex;
text-align: center;
}
.flexy .bottom-align-text {
display: flex;
justify-content: center;
align-items: flex-end;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row flexy">
<div class="bottom-align-text col-sm-4">
<h3>Some Text</h3>
</div>
<div class="col-sm-4">
<img src="//placehold.it/600x300" alt="Logo" class="img-responsive" />
</div>
<div class="bottom-align-text col-sm-4">
<h3>Some Text</h3>
</div>
</div>
</div>
You can wrap column 1st and column 2nd in to a row then we'll have 2 columns structure. See my jsFiddle demo: https://jsfiddle.net/robinhuy/kg1ykfL1/3/