I've been making my anime website where people can watch anime for free with subtitles (Bulgarian subtitles, since I'm from Bulgaria). Now I'm remaking it from scratch because I have been using a theme but It didn't have much functionality... Now I'm making the slider for the recently added animes but I want it to be a custom one so I'm making.... the slider controls are not in a position, so I tried with float, flex with float, etc.... Here's a picture where it should belong: click to open the image (important)
Here's the HTML:
<div class="recent-anime">
<!-- Title and Controls -->
<div class="title-controls">
<h1 class="title">Наскоро добавни</h1>
<a><i class="fas fa-angle-left"></i></a>
<a><i class="fas fa-angle-right"></i></a>
</div>
<!-- Anime cards -->
<div class="animecards">
<div class="animecard">
<img src="images/cover.png">
<div class="ani">
<p class="anititle">Anime title</p>
<p class="aniepisode">Episode</p>
</div>
</div>
<div class="animecard ml">
<img src="images/cover.png">
<div class="ani">
<p class="anititle">Anime title</p>
<p class="aniepisode">Episode</p>
</div>
</div>
<div class="animecard ml">
<img src="images/cover.png">
<div class="ani">
<p class="anititle">Anime title</p>
<p class="aniepisode">Episode</p>
</div>
</div>
<div class="animecard ml">
<img src="images/cover.png">
<div class="ani">
<p class="anititle">Anime title</p>
<p class="aniepisode">Episode</p>
</div>
</div>
<div class="animecard ml">
<img src="images/cover.png">
<div class="ani">
<p class="anititle">Anime title</p>
<p class="aniepisode">Episode</p>
</div>
</div>
<div class="animecard ml">
<img src="images/cover.png">
<div class="ani">
<p class="anititle">Anime title</p>
<p class="aniepisode">Episode</p>
</div>
</div>
</div>
</div>
And the CSS:
.title-controls {
display: flex;
flex-direction: row;
font-size: 42px;
margin-bottom: 10px;
}
.title {
font-size: 26px;
}
.animecards {
display: flex;
}
.animecard {
display: block;
float: left;
}
.animecard img {
max-height: 325px;
}
.ml {
margin-left: 15px;
}
.ani {
text-align: center;
}
There's no JS. Still on the HTML and CSS part.
NOTE: This is clean CSS!
justify-content: space-between; on title-controls class will solve the issue shown in image
.title-controls {
display: flex;
flex-direction: row;
font-size: 42px;
margin-bottom: 10px;
justify-content: space-between;
}
Related
This question already has answers here:
Align an element to bottom with flexbox
(10 answers)
Closed 4 months ago.
I am brand new to coding (thanks for your patience!) and working on a portfolio project for a bootcamp course. I'd like to show headers & copy on the top of my cards with the images aligned underneath. We are using CSS flex. Currently if the text length differs between cards the images end up un-aligned. Here is a screenshot:
Screenshot of uneven card images:
Any suggestions on how I can keep the header + copy at the top but align the images to the bottom of the card?
.card-container {
display: flex;
flex-flow: row wrap;
justify-content: center;
margin: auto auto 60px auto;
max-width: 100vw;
/* 1000px; */
}
.card {
background-color: #f2f2f2;
width: 40%;
margin: 20px;
}
.card a:hover {
text-decoration: none;
}
.card-copy {
padding: 0 20px 20px 20px;
}
<section>
<h2 class="center">Apparel Design</h2>
<div class="card-container">
<!--Card 1-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Design Process</h3>
<p class="margin-top_zero">Copy here about my design process overview</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
<!--Card 2-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Professional Work</h3>
<p class="margin-top_zero">Copy here about my most recent professional work</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
<!--Card 3-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Exploratory Projects</h3>
<p class="margin-top_zero">Copy here about my recent stretch projects</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
</div>
</section>
There are several ways to do this. One is to make your anchors flex containers as well, with direction 'column'. You'd then make them full height and spread their child elements with space-between.
You could also apply flex-fill properties to the paragraph to make it expand to fill available space.
See https://css-tricks.com/snippets/css/a-guide-to-flexbox.
.card-container {
display: flex;
flex-flow: row wrap;
justify-content: center;
margin: auto auto 60px auto;
max-width: 100vw; /* 1000px; */
}
.card {
background-color: #f2f2f2;
width: 40%;
margin: 20px;
}
.card a {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.card a:hover {
text-decoration: none;
}
.card-copy {
padding: 0 20px 20px 20px;
}
.card img {
max-width: 100%;
}
<section>
<h2 class="center">Apparel Design</h2>
<div class="card-container">
<!--Card 1-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Design Process</h3>
<p class="margin-top_zero">Copy here</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
<!--Card 2-->
<div class="card">
<a href="">
<div class="card-copy">
<h3 class="margin-bottom_five">Professional Work</h3>
<p class="margin-top_zero">Copy here about my most recent professional work</p>
</div>
<img src="https://via.placeholder.com/400">
</a>
</div>
</div>
</section>
I'm using an article header to divide up some projects I wish to display:
.project-elem {
background-color: greenyellow;
padding-top: 5rem;
padding-bottom: 5rem;
height: 300px;
}
.projects {
margin: 0;
padding: .7rem;
background-color: #DDCDE8;
font: Asap, sans-serif;
height: 1000px;
}
.project-n {
background-color: green;
text-align: center;
width: 60%;
float: left;
padding: 2.5rem;
}
.img {
background-color: blue;
text-align: center;
padding: 3rem;
margin-left: 40%;
}
<div class="projects" id=#projects>
<h2>My Projects</h2>
<article class="project-elem">
<div class="project-n" id="dictocounter">
<h3>Dictation Counter</h3>
<p>info about proj</p>
<img src="dictocounter1.jpg" alt="Dictocounter in Action">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
<article class="project-elem">
<div class="project-n" id="calc">
<h3>RPN Calculator</h3>
<p>info about proj</p>
<img src="calc.jpg" alt="RPN Calculator Decoding Input">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
<article class="project-elem">
<div class="project-n" id="markov">
<h3>Markov Chain Text Generation</h3>
<p>info about proj</p>
<img src="calc.jpg" alt="Markov Chain Text Generation">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
<article class="project-elem">
<div class="project-n" id="audio">
<h3>Song Similarities</h3>
<p>info about proj</p>
<img src="calc.jpg" alt="Audio Spectral Analysis">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
<article class="project-elem">
<div class="project-n" id="tree">
<h3>DFS/BFS Search Tree</h3>
<p>info about proj</p>
<img src="calc.jpg" alt="Simple Trees">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
</div>
Yet, even though I pad project-elem explicitly, the actual project-elem articles are not padded (rather, smushed all together into one lime-green blob):
I can tell that there is no padding between the project elements because the outer division (with bkgrd color purple) cannot be seen between each of the lime-green project elements. Why is this the case, and how can I fix this?
Also, how can I make the img class vertically-even with the project-n class?
You might need margin-bottom instead of padding-bottom;
By using padding you don't seperate them, padding works kind of from-inside.
You may read about box-model here to understand this.
Since the project-elem has only padding and not margin, there is no gap between different elements with the class "project-elem"
Change padding to margin for your requirement as shown below:
.project-elem {
background-color: greenyellow;
margin-top: 5rem;
margin-bottom: 5rem;
height: 300px;
}
.projects {
margin: 0;
padding: .7rem;
background-color: #DDCDE8;
font: Asap, sans-serif;
height: 1000px;
}
.project-n {
background-color: green;
text-align: center;
width: 60%;
float: left;
padding: 2.5rem;
}
.img {
background-color: blue;
text-align: center;
padding: 3rem;
margin-left: 40%;
}
Understand the difference between padding and margin. You can refer this: https://stackoverflow.com/a/2189462/12774953
I suggest you to use flex-box for this.
It would be something like this:
html
<html>
<head>
<style>
.project-elem {
background-color: greenyellow;
padding-top: 5rem;
padding-bottom: 5rem;
height: 300px;
display: flex;
justify-content: space-between;
}
.projects {
margin: 0;
background-color: #DDCDE8;
font: Asap, sans-serif;
height: 1000px;
box-sizing: border-box;
}
.project-n {
background-color: green;
text-align: center;
width: 60%;
padding: 2.5rem;
box-sizing: border-box;
}
.img {
background-color: blue;
text-align: center;
padding: 3rem;
box-sizing: border-box;
width: 25%;
}
</style>
</head>
<body>
<div class="projects" id=#projects>
<h2>My Projects</h2>
<article class="project-elem">
<div class="project-n" id="dictocounter">
<h3>Dictation Counter</h3>
<p>info about proj</p>
<img src="dictocounter1.jpg" alt="Dictocounter in Action">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
<article class="project-elem">
<div class="project-n" id="calc">
<h3>RPN Calculator</h3>
<p>info about proj</p>
<img src="calc.jpg" alt="RPN Calculator Decoding Input">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
<article class="project-elem">
<div class="project-n" id="markov">
<h3>Markov Chain Text Generation</h3>
<p>info about proj</p>
<img src="calc.jpg" alt="Markov Chain Text Generation">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
<article class="project-elem">
<div class="project-n" id="audio">
<h3>Song Similarities</h3>
<p>info about proj</p>
<img src="calc.jpg" alt="Audio Spectral Analysis">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
<article class="project-elem">
<div class="project-n" id="tree">
<h3>DFS/BFS Search Tree</h3>
<p>info about proj</p>
<img src="calc.jpg" alt="Simple Trees">
</div>
<div class="img">
<p>heres SOME IMAGE</p>
</div>
</article>
</div>
</body>
</html>
I have 3 different account cards with varying content in each card. I want all the cards (which reside inside a col-md-4 class) to occupy the full height of the column.
I gathered from [this][1] thread that one way to achieve that is to use display: table. The main issue is that I have a div inside the my columns which I need to occupy the full height of the column. I set those divs to display: inline-block and height to 100% but divs seem to be behaving as if height was set to auto and not occupying full height
Here is my html:
.container {
display: table;
}
.row {
display: table-row;
height: 100%;
}
.col-md-4 {
display: table-cell;
float: none;
height: 100%;
}
.account {
background: $overlay-color;
text-align: center;
display: inline-block;
margin: 0;
padding: 0;
height: 100%;
}
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="account">
<h1 class="type">MINI ACCOUNT</h1>
<div class="details">
<h2 class="ad">A perfect account to start with!</h2>
<p class="detail">Spreads from 2.3 pips</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="account">
<h1 class="type">STANDARD ACCOUNT</h1>
<div class="details">
<h2 class="ad">An ideal account for every investor!</h2>
<p class="detail">Spreads from 1.9 pips</p>
<p class="detail">Minimum deposit = $25 000</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="account">
<h1 class="type">EXCLUSIVE ACCOUNT</h1>
<div class="details">
<h2 class="ad">An exclusive account for exclusive clients!</h2>
<p class="detail">Spreads from 0 pips</p>
<p class="detail">Minimum deposit = $50,000</p>
<p class="detail">Access to Daily Technical Analysis</p>
</div>
</div>
</div>
</div>
</div>
Try with flexbox
.container {
display: table;
}
.row {
display: flex;
}
.col-md-4 {
float: none;
}
.account {
background: rgba(0, 0, 0, 0.34);
text-align: center;
display: inline-block;
margin: 0;
padding: 0;
height: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="account">
<h1 class="type">MINI ACCOUNT</h1>
<div class="details">
<h2 class="ad">A perfect account to start with!</h2>
<p class="detail">Spreads from 2.3 pips</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="account">
<h1 class="type">STANDARD ACCOUNT</h1>
<div class="details">
<h2 class="ad">An ideal account for every investor!</h2>
<p class="detail">Spreads from 1.9 pips</p>
<p class="detail">Minimum deposit = $25 000</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="account">
<h1 class="type">EXCLUSIVE ACCOUNT</h1>
<div class="details">
<h2 class="ad">An exclusive account for exclusive clients!</h2>
<p class="detail">Spreads from 0 pips</p>
<p class="detail">Minimum deposit = $50,000</p>
<p class="detail">Access to Daily Technical Analysis</p>
</div>
</div>
</div>
</div>
</div>
I am trying to create a webpage for an imaginary pizzeria as practice. I want to insert the header of the webpage in between two images(same) such that the three(image, header, image) elements are in line. But with the code below I am getting a screen like this. How do I get them all on one line?
<body>
<div style='float:left'>
<img src='body.png' style='width:100px; height:100px;'>
</div>
<div style='font-family:amita; font-size:20px;'>
<h1 align='center' style='margin-bottom:5px;'>Ralph's Pizzeria</h1>
</div>
<div style='float:right'>
<img src='body.png' style='width:100px; height:100px;'>
</div>
<hr style='clear:both;' />
</body>
This can be done using display: flex and justify-content: space-between:
.header {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
<div class="header">
<div>
<img src='body.png' style='width:100px; height:100px;'>
</div>
<div style='font-family:amita; font-size:20px;'>
<h1 align='center' style='margin-bottom:5px;'>Ralph's Pizzeria</h1>
</div>
<div>
<img src='body.png' style='width:100px; height:100px;'>
</div>
</div>
I've added a container div and given it the class header and applied the flexbox to it.
You can simply do this :
header {
text-align: center;
}
h1 {
font-size: 25px;
display: inline-block;
vertical-align: top;
margin-top: 25px;
}
img {
display: inline-block;
width: 100px;
height: 100px;
margin:0 10px;
}
<header>
<img src='https://lorempixel.com/100/100/'>
<h1>Ralph's Pizzeria</h1>
<img src='https://lorempixel.com/100/100/'>
</header>
<hr>
Here's another solution if you want to continue to work with float.
Simply move the 2nd image to before the title.
<body>
<div style='float:left'>
<img src='body.png' style='width:100px; height:100px;'>
</div>
<div style='float:right'> <!-- Just moved this up here -->
<img src='body.png' style='width:100px; height:100px;'>
</div>
<div style='font-family:amita; font-size:20px;'>
<h1 align='center' style='margin-bottom:5px;'>Ralph's Pizzeria</h1>
</div>
<hr style='clear:both;'/>
</body>
However, I suggest using flex-box if you don't have to support older browsers.
How do I get the boxes to align underneath each other when the screen shrinks (responsive) Right now they just shrink against each other. I'll post images to give you a better idea of what's going on. Using CSS3, HTML5, Bootstrap v3.3.4
<section class="about-feature clearfix">
<div class="container-fluid">
<div class="row">
<div class="block about-feature-1 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".3s">
<h2>
TEXT
</h2>
<p>
text
</p>
</div>
<div class="block about-feature-2 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".5s">
<h2 class="item_title">
TEXT
</h2>
<p>
text
</p>
</div>
<div class="block about-feature-3 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".7s">
<h2 class="item_title">
TEXT
</h2>
<p>
text
</p>
</div>
</div>
</div>
</section>
CSS
.about-feature {
margin-top: 50px;
}
.about-feature .block {
color: #fff;
width: 33.33%;
padding: 5%;
float: left;
}
.about-feature .block p {
font-weight: 300;
}
.about-feature .about-feature-1 {
background: #02bdd5;
}
.about-feature .about-feature-2 {
background: #00B0C7;
}
.about-feature .about-feature-3 {
background: #00A6BB;
}
you could use flex and min-width to skip the mediaqueries:
.row {
display: flex;
flex-wrap: wrap;
}
.about-feature {
margin-top: 50px;
}
.about-feature .block {
color: #fff;
flex: 1;
min-width: 360px;
;
padding: 5%;
box-sizing: border-box;
}
.about-feature .block p {
font-weight: 300;
}
.about-feature .about-feature-1 {
background: #02bdd5;
}
.about-feature .about-feature-2 {
background: #00B0C7;
}
.about-feature .about-feature-3 {
background: #00A6BB;
}
<section class="about-feature clearfix">
<div class="container-fluid">
<div class="row">
<div class="block about-feature-1 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".3s">
<h2>
TEST
</h2>
<p>
Run me in full page and resize window to check me out
</p>
</div>
<div class="block about-feature-2 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".5s">
<h2 class="item_title">
TEXT
</h2>
<p>
text
</p>
</div>
<div class="block about-feature-3 wow fadeInDown" data-wow-duration="500ms" data-wow-delay=".7s">
<h2 class="item_title">
TEXT
</h2>
<p>
text
</p>
</div>
</div>
</div>
</section>