Image container not aligning bottom to other grid container - html

Hello,
As you can see from the photo above, I am trying to achieve a grid system. First grid is 3 images, second grid is a column, and third grid is a large image floated to the right of the 2nd grid. You can see this photo on my portfolio website: http://www.irwinlitvak.com
I have three images in the first grid that have a width of 31.33% and the first and second img have a margin-right of 3.005% to full up the container width.
In the next grid (grid-2), I have a two of my images floated left in a column and (grid-2-of-3) is floated right with a width of 65.556%.
I would like the top and bottom of the larger image to take up the full height of the grid, so the bottom of the big image aligns with the self-destructing box.
Here is the HTML & CSS:
.projects-grid {
margin: 100px auto 0;
width: 90%;
}
.projects-grid .title {
margin-bottom: 20px;
text-align: center;
}
.projects-grid h1 {
display: inline-block;
font-family: "Montserrat";
}
.grid-1 {
margin-bottom: 4%;
}
.grid-1-of-3 {
position: relative;
width: 31.33%;
float: left;
overflow: hidden;
}
.grid-2-of-3 {
position: relative;
width: 65.556%;
float: right;
}
.grid-1-of-3:first-child,
.grid-1-of-3:nth-child(2) {
margin-right: 3.005%;
}
.grid-3 {
position: relative;
display: inline-block;
width: 33%;
margin-bottom: 60px;
vertical-align: bottom;
}
.grid-5 {
position: relative;
display: inline-block;
width: 20%;
margin-bottom: 60px;
vertical-align: bottom;
}
.box-1 {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.grid-1-of-3:first-child {
margin-left: 0;
}
.grid-1-of-3:last-child {
margin-right: 0;
}
.big-box {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.grid-2 {
width: 31.33%;
float: left;
}
.grid-2 .box-cont {
width: 100%;
}
.grid-2 .box-cont:first-child {
margin-bottom: 4%;
}
.grid-2 .box-cont {
position: relative;
}
<section class="projects-grid clearfix">
<div class="row title">
<h2>Projects</h2>
</div>
<div class="grid-1 clearfix">
<div class="grid-1-of-3">
<div class="box-1">
<a href="">
<img class="bdgt-app" src="assets/budget-app-x-ps.jpg" alt="budget-app pic">
</a>
<a href="https://budget-app-x.herokuapp.com/" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>Budget-App-X</h3>
<p>Manage your incomes and expenses in a fun and easy app.</p>
</div>
</div>
</a>
</div>
<h3>
Budget-App-X
</h3>
</div>
<div class="grid-1-of-3">
<div class="box-1">
<a href="">
<img src="/assets/dice-game-x-ps.jpg" alt="dice-game">
</a>
<a href="https://dice-game-x.herokuapp.com/" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>Dice-Game</h3>
<p>Roll the dice. Test your luck and see who racks the most points.</p>
</div>
</div>
</a>
</div>
<h3>
Dice-Game
</h3>
</div>
<div class="grid-1-of-3">
<div class="box-1">
<a href="">
<img src="/assets/pomodoro-timer-x-ps.jpg" alt="pomodoro-app-timer">
</a>
<a href="http://pomodoro-app-timer.herokuapp.com" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>Pomodoro-Timer</h3>
<p>A quick and easy solution to being productive. Set the time and get things done.</p>
</div>
</div>
</a>
</div>
<h3>
Pomodoro-Timer
</h3>
</div>
</div>
<div class="grid-2 clearfix">
<div class="box-cont">
<div class="box-1">
<a href="">
<img src="/assets/cucumberme-x-ps.jpg" alt="cucumber me">
</a>
<a href="http://www.cucumberme.com" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>CucumberMe</h3>
<p>CucumberMe is your way of anonymously sending cucumbers to a friend, ex or anyone you want.<br><br> Go and send one today! </p>
</div>
</div>
</a>
</div>
<h3>
CucumberMe
</h3>
</div>
<div class="box-cont">
<div class="box-1">
<a href="#">
<img src="/assets/self-destruct-x-ps.jpg" alt="to do list">
</a>
<a href="http://todos-irwin.herokuapp.com/" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>Self Destructing To-Do-List</h3>
<p>A to-do-list that will delete itself within 10 seconds. How many chores can you list within that time? </p>
</div>
</div>
</a>
</div>
<h3>
<a href="http://todos-irwin.herokuapp.com/" target="_blank">
Self Destructing To-Do-List
</a>
</h3>
</div>
</div>
<div class="grid-2-of-3 clearfix">
<div class="box-cont">
<div class="big-box">
<a href="#">
<img src="/assets/omnifood-x-ps.jpg" alt="omnifood">
</a>
<a href="http://con.staging.thegateny.net/con/Omnifood/v1/" target="_blank">
<div class="box-overlay big-overlay">
<div class="text-overlay">
<h3>Omnifood</h3>
<p>My version of the food app Blue Apron. Take a look! </p>
</div>
</div>
</a>
</div>
<h3>
<a href="http://con.staging.thegateny.net/con/Omnifood/v1/" target="_blank">
Omnifood
</a>
</h3>
</div>
</div>
</section>

What you can do is as I show in the snippet below. You have a container for all your divs you want at the same height, which you give a set height. You then give the items on the left a container (with height: 100%) and make a div for the right item (height: 100%).
By doing this, you have a container for the items on the left, so you can make them, say, 50% each, and you have a right item that's the same height as the container on the left.
In order to make an image fit a div, either use background-size: cover or something similar. height:100%; width: auto also works for responsive images.
Hope it helps.
.outer {
background: blue;
width: 600px;
height: 200px;
}
.leftwrap {
width: 30%;
float: left;
height: 100%;
}
.left1 {
background: purple;
width: 100%;
height: 50%;
}
.left2 {
background: orange;
width: 100%;
height: 50%;
}
.right {
background: teal;
height: 100%;
width: 70%;
float: left;
}
/** New code **/
.image {
height: 80%;
width: auto;
border: 1px solid black;
}
.imagetext {
color: white;
text-align: center;
border: 1px solid black;
}
.left {
box-sizing: border-box;
padding-bottom: 30px;
}
<div class='outer'>
<div class='leftwrap'>
<div class='left left1'>
<div class="image">My image here</div>
<div class="imagetext">Some text</div>
</div>
<div class='left left2'>
<div class="image">My image here</div>
<div class="imagetext">Some text</div>
</div>
</div>
<div class='right'>3</div>
</div>

Related

How to make a clickable responsive square box with centered content?

I have a set of columns each containing a square box that fills to the column width and maintains a square height ratio.
The entire box needs to be clickable, with the content inside that also centered within the box. I can't figure out a way of getting the inner <a> element to fill out the space inside the parent div and have its own content centered.
Here is an editable Fiddle
The entire square should be red, entirely clickable, and with a centered download button within.
I've reviewed a bunch of similar questions about making square boxes with CSS but didn't find anything about the inner elements filling out the box like this.
Thanks
.block {
width: 100%;
height: 0;
padding-bottom: 100%;
border: 2px solid #600;
}
.block a {
display: flex;
justify-content: center;
align-items: center;
background: #C00;
text-decoration: none;
}
.block span {
padding: 1em;
border: 2px solid #FFF;
text-align: center;
color: #FFF;
}
/* Demo only */
.row {
display: flex;
justify-content: space-between;
}
.column {
width: 20%;
}
<div class="row">
<div class="column">
<div class="block">
<a href="#">
<span>Download</span>
</a>
</div>
</div>
<div class="column">
<div class="block">
<a href="#">
<span>Download</span>
</a>
</div>
</div>
<div class="column">
<div class="block">
<a href="#">
<span>Download</span>
</a>
</div>
</div>
<div class="column">
<div class="block">
<a href="#">
<span>Download</span>
</a>
</div>
</div>
</div>
Setting the parent .block to position: relative allows us to set .block > a to position: absolute, with dimensions that fill its parent; I only added 3 css rules, they're commented so you know which ones:
.block {
position: relative; /* change #1 */
width: 100%;
height: 0;
padding-bottom: 100%;
border: 2px solid #600;
}
.block a {
position: absolute; /* change #2 */
left: 0; right: 0; top: 0; bottom: 0; /* change #3 */
display: flex;
justify-content: center;
align-items: center;
background: #C00;
text-decoration: none;
}
.block span {
padding: 1em;
border: 2px solid #FFF;
text-align: center;
color: #FFF;
}
/* Demo only */
.row {
display: flex;
justify-content: space-between;
}
.column {
width: 20%;
}
<div class="row">
<div class="column">
<div class="block">
<a href="#">
<span>Download</span>
</a>
</div>
</div>
<div class="column">
<div class="block">
<a href="#">
<span>Download</span>
</a>
</div>
</div>
<div class="column">
<div class="block">
<a href="#">
<span>Download</span>
</a>
</div>
</div>
<div class="column">
<div class="block">
<a href="#">
<span>Download</span>
</a>
</div>
</div>
</div>

Inline-block top align issue; blocks seemingly randomly aligned [duplicate]

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 2 years ago.
I'm trying to align multiple inline-blocks at the top of my page, but for reasons that are baffling to me, it's not working. The CSS could hardly be cleaner or less, but the top isn't aligning properly. I thought it could be a floating issue, but even after applying a clear:both it doesn't fix this.
Please see the program here:
https://jsfiddle.net/yezwocta/
#page {
text-align: center;
}
.article {
width: 350px;
height: 150px;
margin: 5px;
display: inline-block;
background-color: #fafafa;
}
.article img {
float: left;
width: 150px;
height: 130px;
margin-top: 10px;
}
.content {
position: relative;
display: inline-block;
width: 170px;
height: 130px;
margin-top: 10px;
margin-left: 10px;
text-align: left;
}
.title {
font-size: 1.2rem;
}
.source {
font-size: 0.8rem;
position: absolute;
bottom: 0;
left: 0;
}
<div id="page">
<div class="article">
<a href="https://cnn.com" target="_blank">
<img alt="News" src="https://loremflickr.com/150/130/news?random=1">
<div class="content">
<span class="title">Cable News Network</span>
<span class="source">CNN</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.mozilla.org/en-US/firefox/new/" target="_blank">
<img alt="Firefox browser" src="https://loremflickr.com/150/130/browser?random=2">
<div class="content">
<span class="title">Get the Latest Firefox Browser</span>
<span class="source">Mozilla</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.kproxy.com/" target="_blank">
<img alt="kproxy" src="https://loremflickr.com/150/130/proxy?random=3">
<div class="content">
<span class="title">Surf the web anonymously and bypass filters</span>
<span class="source">kproxy</span>
</div>
</a>
</div>
</div>
Add vertical-align: top; to your .article CSS (the default is baseline):
#page {
text-align: center;
}
.article {
width: 350px;
height: 150px;
margin: 5px;
display: inline-block;
background-color: #fafafa;
vertical-align:top;
}
.article img {
float: left;
width: 150px;
height: 130px;
margin-top: 10px;
}
.content {
position: relative;
display: inline-block;
width: 170px;
height: 130px;
margin-top: 10px;
margin-left: 10px;
text-align: left;
}
.title {
font-size: 1.2rem;
}
.source {
font-size: 0.8rem;
position: absolute;
bottom: 0;
left: 0;
}
<div id="page">
<div class="article">
<a href="https://cnn.com" target="_blank">
<img alt="News" src="https://loremflickr.com/150/130/news?random=1">
<div class="content">
<span class="title">Cable News Network</span>
<span class="source">CNN</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.mozilla.org/en-US/firefox/new/" target="_blank">
<img alt="Firefox browser" src="https://loremflickr.com/150/130/browser?random=2">
<div class="content">
<span class="title">Get the Latest Firefox Browser</span>
<span class="source">Mozilla</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.kproxy.com/" target="_blank">
<img alt="kproxy" src="https://loremflickr.com/150/130/proxy?random=3">
<div class="content">
<span class="title">Surf the web anonymously and bypass filters</span>
<span class="source">kproxy</span>
</div>
</a>
</div>
</div>

Why doesn't the position work properly in the section

I have a section part on the website where I want four products being displayed in the middle, right and left arrows on both sides of the screen and a title in the middle above the displayed products, I think I have all of the HTML and CSS good but the position isn't working properly, can someone have a look and help me feature it out?img of the sections I am talking about
ps: the background color doesn't feel the space that the items and buttons are in, why does it happens too?
edit: this is a pic of how i wish it would look
HTML:
<section class="one">
<div><span class="title">New products</span></div>
<br>
<button class="left">
<span class="Lmain"></span>
<span class="Lside"></span>
</button>
<div class="items">
<div class="item">
<a href="">
<img class="itemImg" src="../Images/Image1.png" alt="Picture of the product">
</a>
<div><span class="desc">Description about that specific item that is being showen to you above this text
right here</span></div>
</div>
<div class="item">
<a href="">
<img class="itemImg" src="../Images/Image2.png" alt="Picture of the product">
</a>
<div><span class="desc">Description about that specific item that is being showen to you above this text
right here</span></div>
</div>
<div class="item">
<a href="">
<img class="itemImg" src="../Images/Image3.png" alt="Picture of the product">
</a>
<div><span class="desc">Description about that specific item that is being showen to you above this text
right here</span></div>
</div>
<div class="item">
<a href="">
<img class="itemImg" src="../Images/Image4.png" alt="Picture of the product">
</a>
<div><span class="desc">Description about that specific item that is being showen to you above this text
right here</span></div>
</div>
</div>
<button class="right">
<span class="Rmain"></span>
<span class="Rside"></span>
</button>
</section>
CSS:
.title {
text-align: center;
position: absolute;
margin: auto;
border: 1px solid goldenrod;
font-size: 40px;
}
.one {
background-color: hotpink;
position: relative;
}
.two {
background-color: rgb(255, 0, 128);
}
/*items appearance*/
.items {
position: relative;
margin: auto;
}
.item {
border: 1px solid rgb(255, 170, 0);
float: left;
position: absolute;
top: 0px;
margin: 0px 8px;
left: 12%;
width: 350px;
height: auto;
}
.itemImg {
width: 100%;
height: auto;
}
/*end of item appearance*/
.right {
right: 0px;
top: 0px;
position: absolute;
}
.left {
left: 0px;
top: 0px;
position: absolute;
}
Utilize flexbox to make this layout easy:
body {
margin: 0;
background: #1a1a1a;
color: #fff;
font-family: sans-serif;
}
h1#title {
padding: 1rem;
text-align: center;
}
main {
padding: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
#products {
display: flex;
justify-content: center;
align-items: flex-start;
margin: 0;
}
.product {
padding: 2rem 1rem;
background: #fff;
color: black;
margin: .5rem;
}
<body>
<h1 id="title">Items</h1>
<main>
<div class="arrow" id="arrow-left">←</div>
<div id="products">
<div class="product">
Product
</div>
<div class="product">
Product
</div>
<div class="product">
Product
</div>
<div class="product">
Product
</div>
</div>
<div class="arrow" id="arrow-right">→</div>
</main>
</body>
Here a list of problem I see:
the .title element is position:absolute, so it doesn't fill any space and other elements will position weirdly. Solution: remove position: absolute
the .title is a <span> element witch is an inline-element who doesn't behave like a block element (<div>, <p>, <h1>, etc.), so the text-align: center doesn't take effect. Solution: remove the span and give the .title class to the parent <div>
the left and right buttons should be wrapped in a <div> with position:relative
Here is a jsfiddle with the fixed code.
I didn't fix the image positioning because i think those will be positioned by js, anyhow it dipends by the images dimensions and is a very weak method. So I strongly suggest using flexbox that is widely supported by browsers.
You can follow the #yerme example or this guide on flexbox.

Video section design not aligned

I am working to make video section look like something similar to below design
i am facing two design breaks in the right side
thumbnail doesn't fill the "vp-hqdefault-w" it shows part of image and rest of it is hidden.
second i am not able to align video title next to thumbnail as show in image
<div class="container">
<div class="row content">
<div class="col-md-7 col-sm-6">
<div class="active-iframe-wrapper video-embed-container">
<iframe id='activeIFrame' class='active-iframe' width='100%' height='324' src="http://www.youtube.com/embed/SCRUg5s389Q?showinfo=0&modestbranding=1" ></iframe>
</div>
<p>Title of the video</p>
</div>
<div class="col-md-5 col-sm-6">
<a class="" href="http://www.youtube.com/embed/SCRUg5s389Q?showinfo=0&modestbranding=1">
<div class="vp-video-img-w vp-hqdefault-w">
<img src="http://img.youtube.com/vi/SCRUg5s389Q/hqdefault.jpg" title="">
</div>
<div class="vp-video-details">
<h3 class="video-title">Mr. Bean is back on the road One</h3>
</div>
</a>
<a class="" href="http://www.youtube.com/embed/QThP5kDUJJ0?showinfo=0&modestbranding=1">
<div class="vp-video-img-w vp-hqdefault-w">
<img src="http://img.youtube.com/vi/QThP5kDUJJ0/hqdefault.jpg" title="">
</div>
<div class="vp-video-details">
<h3 class="video-title">Mr. Bean is back on the road Two</h3>
</div>
</a>
<a class="" href="http://www.youtube.com/embed/xIOP1PLjUTs?showinfo=0&modestbranding=1">
<div class="vp-video-img-w vp-hqdefault-w">
<img src="http://img.youtube.com/vi/xIOP1PLjUTs/hqdefault.jpg" title="">
</div>
<div class="vp-video-details">
<h3 class="video-title">Mr. Bean is back on the road Three</h3>
</div>
</a>
</div>
</div>
Codepen link
I am trying to make it responsive to it doesnt break
You are having this issue because you didn't add float:left property to the video thumnail div. Try this code.
.vp-video-img-w {
position: relative;
overflow: hidden;
float: left;
margin-right: 10px;
width: 30%;
}
Try below code:
.header {
padding-top: 20px;
padding-bottom: 20px;
}
.video-embed-container {
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
max-width: 100%;
margin-bottom: 0px;
}
.active-iframe-wrapper {
float: left;
width: 100%;
background-color: #f5f5f5;
}
.video-embed-container iframe, .embed-container object, .embed-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.video-item-w{
background-color:#ccc;
}
.vp-hqdefault-w {
max-height: 80px;
max-width: 120px;
overflow: hidden;
position: relative;
width:30%;
}
.vp-video-img-w {
position: relative;
width: 30%;
overflow: hidden;
float: left;
}
.vp-video-details{
width:70%;
float:left;
}
.vp-video-img-w img {
max-width: 100%;
}
.video-thumbnail:after {
content: '';
display: block;
clear:both;
}
.footer {
border-top: 1px solid #444;
padding-top: 20px;
margin-top: 20px;
color: #999
}
.p {
text-align: center;
padding-top: 120px;
}
.p a {
text-decoration: underline;
color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row content">
<div class="col-md-7 col-sm-6">
<div class="active-iframe-wrapper video-embed-container">
<iframe id='activeIFrame' class='active-iframe' width='100%' height='324' src="http://www.youtube.com/embed/SCRUg5s389Q?showinfo=0&modestbranding=1" ></iframe>
</div>
<p>Title of the video</p>
</div>
<div class="col-md-5 col-sm-6">
<a class="video-thumbnail" href="http://www.youtube.com/embed/SCRUg5s389Q?showinfo=0&modestbranding=1">
<div class="vp-video-img-w vp-hqdefault-w">
<img src="http://img.youtube.com/vi/SCRUg5s389Q/hqdefault.jpg" title="">
</div>
<div class="vp-video-details">
<h3 class="video-title">Mr. Bean is back on the road One</h3>
</div>
</a>
<a class="video-thumbnail" href="http://www.youtube.com/embed/QThP5kDUJJ0?showinfo=0&modestbranding=1">
<div class="vp-video-img-w vp-hqdefault-w">
<img src="http://img.youtube.com/vi/QThP5kDUJJ0/hqdefault.jpg" title="">
</div>
<div class="vp-video-details">
<h3 class="video-title">Mr. Bean is back on the road Two</h3>
</div>
</a>
<a class="video-thumbnail" href="http://www.youtube.com/embed/xIOP1PLjUTs?showinfo=0&modestbranding=1">
<div class="vp-video-img-w vp-hqdefault-w">
<img src="http://img.youtube.com/vi/xIOP1PLjUTs/hqdefault.jpg" title="">
</div>
<div class="vp-video-details">
<h3 class="video-title">Mr. Bean is back on the road Three</h3>
</div>
</a>
</div>
</div>
Change
.vp-video-img-w {
position: relative;
width: 100%;
overflow: hidden;
}
to
.vp-video-img-w {
position: relative;
width: 100%;
overflow: hidden;
float: left;
}

Side banner on a webpage

How would I make it so the banners along the top and bottom of this page (http://i.imgur.com/SxjbCJV.jpg) are instead at both sides of the page?
I currently have them both fixed to the top and bottom of the page:
#header {
position: fixed;
top: 0;
width: 100%;
height: 66px;
z-index: 999;
}
#footer {
position: fixed;
bottom: 0;
width: 100%;
height: 66px;
z-index: 999;
}
And the HTML:
<body>
<div id="wrapper">
<a href="project.html">
<div id="header">
<button id="next-button" href="project.html"><i class="fa fa-arrow-circle-right fa-4x"></i>
</button>
</div>
</a>
<div id="main">
<div id="splash">
<div id="name">
<h1 class="wow animated flipInX">Max Wilson</h1>
</div>
<div id="profile">
<img src="img/Logo.png" class="wow animated rollIn" data-wow-delay="1s">
</div>
<div id="subtext">
<h2 class="wow animated fadeInUp" data-wow-delay="2s">Aspiring Developer </h2>
</div>
</div>
</div>
</div>
<a href="project.html">
<div id="footer">
<button id="prev-button" href="project.html"><i class="fa fa-arrow-circle-left fa-4x"></i>
</button>
</div>
</a>
Have you tried floating the header and footer to the left?
For example:
#header {
position: relative;
float: left;
width: 50px;
height: 500px;
background-color: #44f;
}
#footer {
position: relative;
float: left;
width: 50px;
height: 500px;
background-color: #44f;
}
#wrapper{ text-align: center;
margin-left: auto;
margin-right: auto;
}
#main{ width: 800px;
float:left;
}
Here's a simple and interesting method: giving the body display: flex and the content flex-grow: 1 so it occupies all the available space and pins the other elements to either side.
<div class="side">
<h3>asdf</h3>
<h3>asdf</h3>
<h3>asdf</h3>
<h3>asdf</h3>
</div>
<div id="content">
<p>asdfasdf</p>
</div>
<div class="side">
<h3>asdf</h3>
<h3>asdf</h3>
<h3>asdf</h3>
<h3>asdf</h3>
</div>
body {
display: flex;
}
.side, #content {
padding: 10px;
}
.side {
background: blue;
}
#content {
flex-grow: 1;
background: grey;
}
https://jsfiddle.net/JackHasaKeyboard/rz86xwxh/2/