I have built a plain HTML & CSS Page & built my own card component using flex box.
If you observe the images here, the button 'read more' is not aligning itself to the other card components to the bottom:
In what way I can alter the code (using flexbox only) so that all "read More" buttons will appear on a single line i.e Pushed to the bottom of the card component ??
.container {
max-width: 1200px;
margin: 0 auto;
}
.main-content {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
img {
max-width: 100%;
display: block;
}
.entry {
flex: 0 0 calc(33.33% - 1rem);
margin-bottom: 1rem;
background-color: white;
}
.entry .content {
padding: 1rem;
text-align: center;
text-transform: uppercase;
}
h3 {
margin: 0;
font-weight: 700;
}
.content h3 {
font-size: 0.9rem;
line-height: 1.5rem;
}
.content span {
color: #db008d;
}
.button {
background-color: dodgerblue;
color: white;
text-decoration: none;
padding: .6rem 2rem;
margin-top: 1rem;
display: inline-block;
}
.content {
/*What to write here ?? */
}
<main class="main-content">
<article class="entry">
<img src="img/01.jpg" alt="entry image">
<div class="content">
<h3>Tips for Saving Money in your Next Travel</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
<article class="entry">
<img src="img/02.jpg" alt="entry image">
<div class="content">
<h3>The Complete Guide for Traveling</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
<article class="entry">
<img src="img/03.jpg" alt="entry image">
<div class="content">
<h3>Ultimate Guide to Take the best Pictures</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
</main>
the problem is in h3 and p in the content. they resize according to text wrap. so just define a fixed height for them.
.content h3 , p {
border: 1px solid red;
height: 40px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.main-content {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
img {
max-width: 100%;
display: block;
}
.entry {
flex: 0 0 calc(33.33% - 1rem);
margin-bottom: 1rem;
background-color: white;
}
.entry .content {
padding: 1rem;
text-align: center;
text-transform: uppercase;
}
h3 {
margin: 0;
font-weight: 700;
}
.content h3 {
font-size: 0.9rem;
line-height: 1.5rem;
}
.content span {
color: #db008d;
}
.button {
background-color: dodgerblue;
color: white;
text-decoration: none;
padding: .6rem 2rem;
margin-top: 1rem;
display: inline-block;
}
.content {
/*What to write here ?? */
}
.content h3 , p {
border: 1px solid red;
height: 50px;
}
<main class="main-content">
<article class="entry">
<img src="img/01.jpg" alt="entry image">
<div class="content">
<h3>Tips for Saving Money in your Next Travel</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
<article class="entry">
<img src="img/02.jpg" alt="entry image">
<div class="content">
<h3>The Complete Guide for TravelingTravelingTraveling</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
<article class="entry">
<img src="img/03.jpg" alt="entry image">
<div class="content">
<h3>Ultimate Guide to Take the best Pictures</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
</main>
With your current code, you need to make .entry a flexbox column container and apply proper justification to its child elements: justify-content: space-between.
* {
outline: 1px dashed
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.main-content {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
img {
max-width: 100%;
display: block;
}
.entry {
/* ADDED */
display: flex;
flex-flow: column wrap;
justify-content: space-between;
/**/
flex: 0 0 calc(33.33% - 1rem);
margin-bottom: 1rem;
background-color: white;
}
.entry .content {
padding: 1rem;
text-align: center;
text-transform: uppercase;
}
h3 {
margin: 0;
font-weight: 700;
}
.content h3 {
font-size: 0.9rem;
line-height: 1.5rem;
}
.content span {
color: #db008d;
}
.button {
background-color: dodgerblue;
color: white;
text-decoration: none;
padding: .6rem 2rem;
margin-top: 1rem;
display: inline-block;
}
.content {
/*What to write here ?? */
}
<main class="main-content">
<article class="entry">
<img src="img/01.jpg" alt="entry image">
<div class="content">
<h3>Tips for Saving Money in your Next Travel</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
<article class="entry">
<img src="img/02.jpg" alt="entry image">
<div class="content">
<h3>The Complete Guide for Traveling</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
<article class="entry">
<img src="img/03.jpg" alt="entry image">
<div class="content">
<h3>Ultimate Guide to Take the best Pictures</h3>
<p>Published on: <span>July 19th, 2019</span></p>
<p>By: <span>The Travel Blog</span></p>
Read More
</div>
</article>
</main>
.parent {
display: flex;
flex-direction: row;
padding: 10px;
}
.parent .child {
padding-right: 10px;
flex-grow: 1;
width: 33%;
position:relative;
}
.parent .child .content {
height: 100%;
box-shadow: 0 0 1em gray;
}
.content img{
background-size:cover;
width:100%;
}
.content h3,p{
padding:10px;
}
.content input{
position:absolute;
bottom:5px;
margin-left: 35%;
margin-top:10px;
}
<div class="parent">
<div class="child">
<div class="content">
<div>
<img src="https://www.w3schools.com/html/pic_mountain.jpg"/>
<h3> test 3</h3>
<p>text text text text text text text text text text text text text text text text text text text</p>
</div>
<div><input type="button" value="click" /></div>
</div>
</div>
<div class="child">
<div class="content">
<div>
<img src="https://www.w3schools.com/html/pic_mountain.jpg"/>
<h3> test 2</h3>
<p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text tex </p>
</div>
<div><input type="button" value="click" /></div>
</div>
</div>
<div class="child">
<div class="content">
<div>
<img src="https://www.w3schools.com/html/pic_mountain.jpg"/>
<h3> test 1</h3>
<p>text text text text text text text text text text text text tex</p>
</div>
<div><input type="button" value="click" /></div>
</div>
</div>
</div>
please check this.....
Related
I want possibly the simplest CSS code for aligning 2 lines of text with 1 single icon on the left side. I am attaching the sample here: https://prnt.sc/1udg41j
Please help with the minimal code if possible.
Make sure the image is within the same parent as the text and then to have the icon be on the left side. I believe you'll need to type:
example {
float: left;
}
It would be much easier if you included the code. :P
.main {
display: flex;
}
.iconbox {
display: flex;
align-items: center;
background-color: #f5f5f5;
}
.icon {
margin-right: 10px;
border: 1px solid red;
font-size: 42px;
height: 50px;
width: 50px;
display: grid;
place-content: center;
}
h3 {
margin: 0;
}
p {
margin: 5px 0 0;
}
<div class="main">
<div class="iconbox">
<span class="icon">⅀</span>
<div class="detail">
<h3>heading here</h3>
<p>discription here..</p>
</div>
</div>
<div class="iconbox">
<span class="icon">⅀</span>
<div class="detail">
<h3>heading here</h3>
<p>discription here..</p>
</div>
</div>
<div class="iconbox">
<span class="icon">⅀</span>
<div class="detail">
<h3>heading here</h3>
<p>discription here..</p>
</div>
</div>
</div>
I have two headers (h2 and h3) inside a div, and I want to align the second (h3) to the bottom of the div right above the bottom-border. I'm working with some inherited code, and the height is responsive, so can't be set. Here's the codepen. Here's the HTML:
<div id="toc-texts">
<div class="toc-entry">
<h2>Title 1 That is Actually Really Long</h2>
<h3 class="author">Author Name 1</h3>
</div>
<div class="toc-entry">
<h2>Title 2</h2>
<h3 class="author">Author Name 2</h3>
</div>
<div class="toc-entry">
<h2>Title 3</h2>
<h3 class="author">Author Name 3</h3>
</div>
</div>
And here's the css I have so far:
div#toc-texts {
display: inline;
}
div.toc-entry {
text-align: center;
border-bottom: 2px solid blue;
}
#media (min-width: 30em) {
div#toc-texts {
margin-bottom: 4rem;
display: inline-grid;
grid-template-columns: 9rem 9rem 9rem;
grid-gap: 4em;
}
}
How can I align the h3 to the bottom of the div in a way that works on all browsers and on mobile?
Use a flexbox column.
Push the h3 to the bottom with margin-top:auto and then align right.
div#toc-texts {
display: inline;
}
div.toc-entry {
text-align: center;
border-bottom: 2px solid blue;
display: flex;
flex-direction: column;
}
h3.author {
font-size: .9em;
font-style: italic;
margin-top: auto;
text-align: right;
}
#media (min-width: 30em) {
div#toc-texts {
margin-bottom: 4rem;
display: inline-grid;
grid-template-columns: 9rem 9rem 9rem;
grid-gap: 4em;
}
}
<div id="toc-texts">
<div class="toc-entry">
<h2>Title 1 That is Actually Really Long</h2>
<h3 class="author">Author Name 1</h3>
</div>
<div class="toc-entry">
<h2>Title 2</h2>
<h3 class="author">Author Name 2</h3>
</div>
<div class="toc-entry">
<h2>Title 3</h2>
<h3 class="author">Author Name 3</h3>
</div>
</div>
This containers are arranged using nested flexbox. When I added an unordered list with zero padding, it got outside the child container. Not only that it also goes outside the parent container.
:root {
--main-bg-color: #3D3E5D;
--bg-color-red: #F06D4F;
--bg-color-aqua: #2DA6A4;
--bg-color-orange: #EFB85E;
--txt-color-primary: black;
--txt-color-secondary: white;
--heading: 3rem;
--sub-heading: 2rem;
--normal: 1rem;
--small: 0.5rem;
--main-padding: 10px;
}
* {
margin: none;
padding: 0;
box-sizing: border-box;
}
.container__main {
width: 90%;
margin: auto;
}
.container__flex {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.flex__box {
font-weight: 900;
font-size: var(--normal);
background-color: aqua;
flex: 0 0 calc(50% - 10px);
}
.red {
background-color: red;
}
.gray {
background-color: gray;
}
.container__main>.container__flex {
margin-bottom: 10px;
}
.container__flex>.flex__box {
padding: var(--main-padding);
}
.p-0 {
padding: 0 !important;
}
<div class="container__main">
<div class="container__flex">
<div class="flex__box">
<b></b>
<span class="heading">W</span>eb <span class="heading">A</span>pplication <span class="heading">T</span>echnologies
</div>
<div class="flex__box gray">
<div class="container__flex">
<div class="flex__box p-0 red">
<span class="sub-heading">Links</span>
<ul>
<li>Chubkins</li>
<li>W3 Schools</li>
<li>Learn Web Dev</li>
<li>Colour Reference</li>
</ul>
</div>
<div class="flex__box p-0 red">
</div>
</div>
</div>
</div>
<div class="container__flex">
<div class='flex__box'>
box1
</div>
<div class='flex__box'>
box2
</div>
</div>
</div>
Picture of the mentioned problem: https://prnt.sc/plgv0y
If you want to help me debug this view this codepen link:
https://codepen.io/bishant-bhattarai/pen/qBBqqYE
Since this was a small project I didn't add any comments, sorry for inconvineince.
This is probably due to the default value of the CSS property list-style-position.
You can try and change that like this:
:root {
--main-bg-color: #3D3E5D;
--bg-color-red: #F06D4F;
--bg-color-aqua: #2DA6A4;
--bg-color-orange: #EFB85E;
--txt-color-primary: black;
--txt-color-secondary: white;
--heading: 3rem;
--sub-heading: 2rem;
--normal: 1rem;
--small: 0.5rem;
--main-padding: 10px;
}
* {
margin: none;
padding: 0;
box-sizing: border-box;
}
.container__main {
width: 90%;
margin: auto;
}
.container__flex {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.flex__box {
font-weight: 900;
font-size: var(--normal);
background-color: aqua;
flex: 0 0 calc(50% - 10px);
}
.red {
background-color: red;
}
.gray {
background-color: gray;
}
.container__main>.container__flex {
margin-bottom: 10px;
}
.container__flex>.flex__box {
padding: var(--main-padding);
}
.p-0 {
padding: 0 !important;
}
ul {
list-style-position: inside;
}
<div class="container__main">
<div class="container__flex">
<div class="flex__box">
<b></b>
<span class="heading">W</span>eb <span class="heading">A</span>pplication <span class="heading">T</span>echnologies
</div>
<div class="flex__box gray">
<div class="container__flex">
<div class="flex__box p-0 red">
<span class="sub-heading">Links</span>
<ul>
<li>Chubkins</li>
<li>W3 Schools</li>
<li>Learn Web Dev</li>
<li>Colour Reference</li>
</ul>
</div>
<div class="flex__box p-0 red">
</div>
</div>
</div>
</div>
<div class="container__flex">
<div class='flex__box'>
box1
</div>
<div class='flex__box'>
box2
</div>
</div>
</div>
cf. https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-position
I am using angular-material and materializecss. I'm not really strong with css but i tried to play with it and not much of results ...
I am trying to inline the avatar with the text so far i tried to use span with class to try style the text together with img but no success..
Best result i got so far is , text after avatar but slightly below avatar.
my HTML and custom css.
.gallery{
margin-bottom: 10px;
}
.responsive-img{
width: 100%;
}
.img-info{
text-align: center;
background: #b3e5fc;
color: black;
width: 100%;
margin-bottom: 10px;
padding: 10px 0;
}
.circle{
width: 60;
margin: 10px 5%;
}
.black-text{
text-align: center;
}
.circle .black-text{
display: inline;
}
<div class="row gallery">
<div class="col l3 col m4 col s12" ng-repeat="image in images">
<md-card class="z-depth-3">
<!--INSTAGRAM PHOTOS-->
<a>
<img class="responsive-img" ng-src="{{image.images.standard_resolution.url}}" alt="">
</a>
<!--USER AND AVATAR-->
<div class="img-info">
<img class="circle" ng-src="{{image.user.profile_picture}}">{{image.user.username}}
</div>
</md-card>
</div>
</div>
Use this:
.img-info img.circle{
vertical-align: middle;
}
And next time, share rendered HTML, the html you was shared is not useful.
snippet:
.img-info img.circle{
vertical-align: middle;
}
.gallery{
margin-bottom: 10px;
}
.responsive-img{
width: 100%;
}
.img-info{
text-align: center;
background: #b3e5fc;
color: black;
width: 100%;
margin-bottom: 10px;
padding: 10px 0;
}
.circle{
width: 60;
margin: 10px 5%;
}
.black-text{
text-align: center;
}
.circle .black-text{
display: inline;
}
<div class="row gallery">
<div class="col l3 col m4 col s12" ng-repeat="image in images">
<md-card class="z-depth-3">
<!--INSTAGRAM PHOTOS-->
<a>
<img class="responsive-img" ng-src="{{image.images.standard_resolution.url}}" alt="">
</a>
<!--USER AND AVATAR-->
<div class="img-info">
<img class="circle" src="http://dummyimage.com/50x50/000655/fff"> The text
</div>
</md-card>
</div>
</div>
I am putting together a dynamic photo gallery and getting stuck trying to place thumbnails. Basically I am trying to place each thumbnail and caption in its own DIV, floated to the left. The thumbnails are working just as I want them to but for some reason the parent DIV refuses to cover the height of the thumbnail area. Here is the CSS I am using..
#galleryBox {
width: 650px;
background: #fff;
margin: auto;
padding: 5px;
text-align: center;
}
.item {
display: block;
margin: 10px;
padding: 10px;
float: left;
background: #353535;
min-width: 120px;
}
.label {
display: block;
color: #fff;
}
I have tried height: auto and that hasn't done anything. Here is what I am trying to style:
<div id="galleryBox" class="ui-corner-all">
<div class="item ui-corner-all">
<img src="http://tapp-essexvfd.org/images/ajax-loader.gif" alt="test"/><br/>
<p><span class="label">Testing</span></p>
</div>
<div class="item ui-corner-all">
<img src="http://tapp-essexvfd.org/images/ajax-loader.gif" alt="test"/><br/>
<p><span class="label">Testing</span></p>
</div>
<div class="item ui-corner-all">
<img src="http://tapp-essexvfd.org/images/ajax-loader.gif" alt="test"/><br/>
<p><span class="label">Testing</span></p>
</div>
<div class="item ui-corner-all">
<img src="http://tapp-essexvfd.org/images/ajax-loader.gif" alt="test"/><br/>
<p><span class="label">Testing</span></p>
</div>
<div class="item ui-corner-all">
<img src="http://tapp-essexvfd.org/images/ajax-loader.gif" alt="test"/><br/>
<p><span class="label">Testing</span></p>
</div>
<div class="item ui-corner-all">
<img src="http://tapp-essexvfd.org/images/ajax-loader.gif" alt="test"/><br/>
<p><span class="label">Testing</span></p>
</div>
<div class="item ui-corner-all">
<img src="http://tapp-essexvfd.org/images/ajax-loader.gif" alt="test"/><br/>
<p><span class="label">Testing</span></p>
</div>
</div>
Thanks!
Give your wrapper div an overflow: auto; so it contains the floated children correctly, like this:
#galleryBox {
overflow: auto; /* Only addition to your current styles */
width: 650px;
background: #fff;
margin: auto;
padding: 5px;
text-align: center;
}
This requires no HTML changes, just the style should do.
You need a clearfix
Add the below code to your css file and set the class of #gallerybox to clearfix
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}
UPDATE:
Link