Aligning elements in row to top? - html

I'm trying to align the contents of a row, which is inside of a container, to the top of said row.
This is my current html:
<div class="container">
<div class="row">
<div class="ticket">
<!-- content -->
</div>
</div>
</div>
CSS for ticket:
<style>
.ticket{
border:5px solid black;
border-radius: 15px 50px 30px 5px;
width:20%;
height: fit-content;
display:inline-block;
clear: left;
margin-left:30px;
background-color:#eee;
}
</style>
"row" and "container" are both bootstrap.
Trying to align the 'tickets' with the top (red line)
I've tried using align-content and align-items but neither seem to be doing anything. Any help would be appreciated! Thank you.

You can use align-items: flex-start; in container of tickets.
.ticket {
display:flex;
align-items:flex-start;
}
.tick {
padding:20px;
border:4px solid #000;
margin:50px;
border-radius:0 30px 0 0;
}
<div class="container">
<div class="row">
<div class="ticket">
<div class="tick">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam adipisci suscipit, labore accusamus, libero ad dolorum officia error quo, et molestiae fugit placeat maxime ratione vel minus delectus magni. Consequatur! Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam adipisci suscipit, labore accusamus, libero ad dolorum officia error quo, et molestiae fugit placeat maxime ratione vel minus delectus magni. Consequatur!Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam adipisci suscipit, labore accusamus, libero ad dolorum officia error quo, et molestiae fugit placeat maxime ratione vel minus delectus magni. Consequatur!</div>
<div class="tick">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quisquam adipisci suscipit, labore accusamus</div>
<div class="tick">Lorem ipsum dolor sit amet consectetur, adipisicing elit. </div>
</div>
</div>
</div>

Try to use next css code:
.ticket {
display: flex;
}
.item-in-container {
#flex: 1;
}
Uncomment flex: 1; if you want them to have the same width

If you used the default behaviour of bootstrap it's aligned to the top:
.ticket {
height: 100px;
background-color: red;
}
.ticket:nth-child(2) {
height: 70px;
}
.ticket:nth-child(3) {
height: 50px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="ticket col-3 m-3"></div>
<div class="ticket col-3 m-3"></div>
<div class="ticket col-3 m-3"></div>
</div>
</div>

Related

Why does my flexbox does not occupy the entire height of the container it is enclosed in?

I am doing a course on Frontend Masters. This is the first project of the introductory course. I made the website according to the one said at: https://btholt.github.io/intro-to-web-dev-v2/news.html
Here's my HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css2?family=Cedarville+Cursive&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="P1.css">
<link href="https://fonts.googleapis.com/css2?family=Aladin&display=swap" rel="stylesheet">
<title>The News Times</title>
<link href="https://fonts.googleapis.com/css2?family=Monoton&display=swap" rel="stylesheet">
</head>
<body>
<div>
<h1 class="heading">The News Times</h1>
</div>
<div class="flex">
<div class="blk s25">
<h3 class="title">Student Learns HTML</h3>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro, reprehenderit!
Et tempora eum consequuntur dolores quasi iusto deserunt illo aperiam eaque consectetur sequi qui amet sint,
dolore nesciunt repellat ipsum?
</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro, reprehenderit!
Et tempora eum consequuntur dolores quasi iusto deserunt illo aperiam eaque consectetur sequi qui amet sint,
dolore nesciunt repellat ipsum?
</p>
</div>
<div class="blk s50">
<h3 class="title">BREAKING: Puppies are adorable</h3>
<img src="http://placecorgi.com/600/300" alt="Corgie" style="width: 96%;">
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro, reprehenderit!
Et tempora eum consequuntur dolores quasi iusto deserunt illo aperiam eaque consectetur sequi qui amet sint,
dolore nesciunt repellat ipsum?
</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro, reprehenderit!
Et tempora eum consequuntur dolores quasi iusto deserunt illo aperiam eaque consectetur sequi qui amet sint,
dolore nesciunt repellat ipsum?
</p>
</div>
<div class="blk s25">
<h3 class="title">CSS is Apparently a Thing</h3>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro, reprehenderit!
Et tempora eum consequuntur dolores quasi iusto deserunt illo aperiam eaque consectetur sequi qui amet sint,
dolore nesciunt repellat ipsum?
</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro, reprehenderit!
Et tempora eum consequuntur dolores quasi iusto deserunt illo aperiam eaque consectetur sequi qui amet sint,
dolore nesciunt repellat ipsum?
</p>
</div>
</div>
<div class="flex">
<div class="blk s25 cust">
<h3 class="title">Boy likes Turtle</h3>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro, reprehenderit!
Et tempora eum consequuntur dolores quasi iusto deserunt illo aperiam eaque consectetur sequi qui amet sint,
dolore nesciunt repellat ipsum?
</p>
<p>Voluptate, ut, cupiditate ducimus vitae blanditiis ex impedit debitis est tempora dolores nam sed. Esse nobis
ea inventore qui enim quia beatae ab commodi laboriosam quam aliquam aut perspiciatis fuga nam rerum temporibus
voluptatum explicabo voluptate, pariatur ullam laudantium eligendi.
</p>
</div>
<div class="blk s75">
<div class="inner-flex">
<div class="element politics">
<h1>Politics</h1>
</div>
<div class="element technology">
<h1>Technology</h1>
</div>
<div class="element local">
<h1>Local</h1>
</div>
<div class="element sports">
<h1>Sports</h1>
</div>
<div class="element opinion">
<h1>Opinion</h1>
</div>
</div>
</div>
</div>
</body>
</html>
Here's my CSS code:
body
{
background-color: indianred;
}
.heading
{
text-align: center;
font-size: 120px;
font-family: 'Cedarville Cursive', cursive;
margin: 0px 0px;
}
.flex
{
display: flex;
align-items:stretch;
border: 2px solid black;
align-content: center;
margin:2.0%;
height: 100%;
}
.blk
{
padding: 7px;
text-align: center;
}
.s50
{
width: 50%;
border-left: 2px solid black;
border-right: 2px solid black;
}
.s25
{
height: inherit;
width: 25%;
}
.s75
{
width: 75%;
}
.title
{
font-family: 'Aladin', cursive;
font-size: 60px;
}
.cust
{
border-right: 2px black solid;
}
.inner-flex
{
display: flex;
flex-direction: column;
align-items: stretch;
justify-content: space-between;
padding: 0;
margin: 0;
}
p{
text-align: justify;
}
.element
{
text-align:left;
}
.politics
{
background-color: #ffeaa7;;
}
.technology
{
background-color: #81ecec;;
}
.local
{
background-color: #55efc4;;
}
.sports
{
background-color: #a29bfe;;
}
.opinion
{
background-color: #74b9ff;;
}
However you would see that on zooming in the page, the inner-flex div doesnt occupy the whole length.
Any ideas how to fix it?
This is because you have a different structure of elements.
In the original example the parent flex row (<section class="row">) has set align-items: stretch; css property. This is responsible for the stretching.
Original:
<section class="row">
<article class="story quarter">
<!-- content //-->
</article>
<ul class="story three-quarter other-sections">
<!-- links //-->
</ul>
</section>
This is actually working in your code, but it is applied to the extra container div (<div class="blk s75">) only and it does not apply to the contents of that container. So your .inner-flex will not be stretched but rather gets the height to fit its contents.
Your code:
<div class="flex">
<div class="blk s25 cust">
<!-- content //-->
</div>
<div class="blk s75">
<div class="inner-flex">
<!-- links //-->
</div>
</div>
</div>
You can fix this by fixing the structure and eliminating that extra container or (as already suggested in the comments) by applying the css property height: 100%; to the class .inner-flex.
You can also apply the css property flex-grow: 1; to the .element class to close the gaps between the boxes (this was technically also suggested in the comments, as flex: 1; is a shortcut property that sets flex-grow among others).

3 columns overlapping the footer on mobile browser

Footer is on right place but the columns in section are overlapping the footer
.columns {
float:left;
width: 22%;
height: 30%;
margin-left:8%;
}
Instead of float:left; I have used display:inline-block; but issue
not resolved this problem is occurring when website displayed on
mobile. When viewed on desktop it's working fine.
Try adding this to your CSS
box-sizing: border-box;
.container {
background: #f4f4f4;
padding: 5%;
margin: 5%;
}
.column1 {
background: #b40404;
padding: 5%;
color: #fff;
}
.column2 {
background: #000;
padding: 5%;
color: #fff;
}
.column3 {
background: #b40404;
padding: 5%;
color: #fff;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="column1">
This is column 1<br><br> Lorem ipsum, dolor sit amet consectetur adipisicing elit. Doloribus vero labore obcaecati illum reprehenderit incidunt consequatur quidem, id repellendus impedit, quaerat, mollitia ea culpa sint? Totam sunt omnis quis
eaque.
</div>
</div>
<div class="col-md-4">
<div class="column2">
This is column 2<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Laudantium mollitia, incidunt accusantium iure eius suscipit fugit tempore veniam deleniti, nulla dolore repudiandae voluptas, eaque architecto ratione recusandae
consectetur officia. Saepe.
</div>
</div>
<div class="col-md-4">
<div class="column3">
This is column 3<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quis vitae nulla, beatae tenetur ea eaque obcaecati perspiciatis, architecto nemo culpa id non facilis distinctio aliquam. Accusamus voluptatum mollitia perferendis
libero.
</div>
</div>
</div>
</div>
you can use Bootstrap. Use the class container then row and define columns inside it. Like this:

Remove gap between <h1> and <p>?

How would I remove a gap between a h1 and p element? I've tried removing the padding and margins with no luck. I'm using the default bootstrap css. Any ideas?
.section1{
background-color: bisque;
}
p, h1 {
margin: 0px;
padding: 0px;
}
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
I've attached a screenshot to this post as it appears correctly when I run the code using stackoverflows 'run snippet' feature.
The page-header bootstrap class is causing the space reset it using:
h1.page-header {
margin: 0;
padding: 0;
}
See demo below:
.section1 {
background-color: bisque;
}
p,
h1 {
margin: 0px;
padding: 0px;
}
h1.page-header {
margin: 0;
padding: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
Add line-height to h1 class in your CSS. If font size is 26px, just ad 26px line height.
like:
h1.page-header{
font-size:26px;
line-height:26px;
}
Try line-height to it
.section1 {
background-color: bisque;
line-height: 15px;
}
p,
h1 {
margin: 0px;
padding: 0px;
}
.page-header{
margin:0 !important;
padding:0 !important;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="section1">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1 class="page-header">About</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, explicabo dolores ipsam aliquam inventore corrupti eveniet quisquam quod totam laudantium repudiandae obcaecati ea consectetur debitis velit facere nisi expedita vel?</p>
</div>
</div>
</div>
</div>
You need to reset css first. Because Browser has format CSS itself
{
margin: 0px;
padding: 0px;}
Add this above your css file

How to create a vertical line with a circles above it? (with example image)

I just wonder what is the idea by HTML and CSS?
You only need a css, a markup like that
<div class="circle-border">
<div class="circle-image">
<img ....>
</div>
</div>
and in css
.circle-border{
overflow:hidden;
border-radius:50%;
position:relative;
width: 200px; //for example
height:200px; //for example
}
.circle-image{
position:absolute;
top:0;
left:0;
border-radius:50%;
border:8px rbba(255,255,255,.6);
}
.circle-border img{
width:100%;
object-fit:cover;
}
With this you create the form, only need adjust the desing. Other and maybe simplest way is use a library like iHover, that provide you the design with awesome effects, probably helpfully for what you need.
For the vertical line, is no problem. you only need make "relative" the div where you have the images and the content, after, envolve the image markup in other div and set these div with absolute position and set the "top": 50% and margin-top: with the - pixels that the size of your circle image, set the left position with the same value. The HTML may be like that:
<article>
<section class="container-image">
<div class="circle-border">
<div class="circle-image">
<img ....>
</div>
</div>
<section class="content">
<!-- your content here-->
</section>
Oh! I know this one, I did this example myself some time ago. Probably not the best solution, but i used .class:after (so a vertical line that goes after a circle).
Then you write the usual stuff: content:''; background-color:#______; height; width.
To put it in the center you can use the position:relative, position:absolute, left:50%.
You could also use css animation to do that but since it is 1 or 2 px it wouldn't make a difference.
Hope it helps.
You can use CSS Flexbox. Have a look at my snippet:
.timeline-holder {
position: relative;
}
.timeline-holder:before {
content: '';
position: absolute;
top: 75px;
left: 50%;
transform: translateX(-50%);
width: 1px;
height: calc(100% - 75px);
background: #ccc;
z-index: -1;
}
.box {
display: flex;
align-items: center;
margin: 60px 0;
}
.box .text {
flex: 1;
padding: 0 20px;
}
.box img {
border-radius: 50%;
}
.box:nth-child(even) {
margin-right: calc(50% - 75px);
}
.box:nth-child(odd) {
flex-direction: row-reverse;
margin-left: calc(50% - 75px);
}
<div class="timeline-holder">
<div class="box">
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero amet explicabo quis expedita fuga magnam consequatur perferendis aliquam ipsum odio magni illum aperiam, quod eaque, debitis consectetur, dolorem provident quidem.</div>
<img src="http://placehold.it/150x150" alt="" />
</div>
<div class="box">
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero amet explicabo quis expedita fuga magnam consequatur perferendis aliquam ipsum odio magni illum aperiam, quod eaque, debitis consectetur, dolorem provident quidem.</div>
<img src="http://placehold.it/150x150" alt="" />
</div>
<div class="box">
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero amet explicabo quis expedita fuga magnam consequatur perferendis aliquam ipsum odio magni illum aperiam, quod eaque, debitis consectetur, dolorem provident quidem.</div>
<img src="http://placehold.it/150x150" alt="" />
</div>
<div class="box">
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero amet explicabo quis expedita fuga magnam consequatur perferendis aliquam ipsum odio magni illum aperiam, quod eaque, debitis consectetur, dolorem provident quidem.</div>
<img src="http://placehold.it/150x150" alt="" />
</div>
<div class="box">
<div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero amet explicabo quis expedita fuga magnam consequatur perferendis aliquam ipsum odio magni illum aperiam, quod eaque, debitis consectetur, dolorem provident quidem.</div>
<img src="http://placehold.it/150x150" alt="" />
</div>
</div>
Hope this helps!

Div height follow smaller div height

I have two divs, one beside the other. The left one will have a lot of content, so i want to put scrollbar on it. The right div will have less content so left div should follow height of right div.
Content of right div is dynamic so I can't set max-height of left div. I tried with display:table-cell but unsuccessfully.
.container {
display: table;
border: 2px solid red;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
width: 30px;
border: 2px solid blue;
}
<div class="container">
<div class="row">
<div class="cell">CELL1: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus a facilis saepe. Commodi exercitationem, provident nemo ea distinctio dolor ullam ab facere blanditiis inventore debitis nobis vitae maxime suscipit accusantium.</div>
<div class="cell">CELL2: lorem lorem lorem lorem</div>
</div>
</div>
JSFIDDLE DEMO
You can do this by wrapping the first cell (I call it with first class here) and calling it absolute.
<div class="cell first">
<div>
CELL1: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus a facilis saepe. Commodi exercitationem, provident nemo ea distinctio dolor ullam ab facere blanditiis inventore debitis nobis vitae maxime suscipit accusantium.
</div>
</div>
and apply this:
.cell.first div{
position: absolute;
top: 0;
left: 0;
width: 100%;
}
and overflow-y: auto for each cell.
Maybe you have to adjust the widths. See example below:
.container {
display: table;
border: 2px solid red;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
width: 30px;
border: 2px solid blue;
position: relative;
overflow-y: auto;
}
.cell.first div{
position: absolute;
top: 0;
left: 0;
width: 100%;
}
<div class="container">
<div class="row">
<div class="cell first">
<div>
CELL1: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus a facilis saepe. Commodi exercitationem, provident nemo ea distinctio dolor ullam ab facere blanditiis inventore debitis nobis vitae maxime suscipit accusantium.
</div>
</div>
<div class="cell">CELL2: lorem lorem lorem lorem</div>
</div>
</div>
Cheers! Let me know your feedback on this. Thanks!
try this,
HTML
<div class="container">
<div class="row">
<div class="cell">
<div class="cell-content">
CELL1: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus a facilis saepe. Commodi exercitationem, provident nemo ea distinctio dolor ullam ab facere blanditiis inventore debitis nobis vitae maxime suscipit accusantium.
</div>
</div>
<div class="cell">
<div class="cell-content">CELL2: lorem lorem lorem lorem </div>
</div>
</div>
</div>
CSS
.container {
display: table;
border: 2px solid red;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
width: 30px;
border: 2px solid blue;
}
.cell-content{
max-height:200px; /* as per your requirement */
overflow:auto;
}