I have this code that will display image carousel.
For desktops, I want to display 3 thumbnails per row;
For mobiles, just one or two thumbnail per row horizontally.
The code in working fine in desktopview but in mobileview how do i display in horizontally with only one or two image and use the indicator to see next image ?
i tried using this..but is not working
<div class="col-sm-6 col-md-4">
html
<div class="container">
<div class="row">
<h2>Media Slider Carousel BS3</h2>
</div>
<div class='row'>
<div class='col-md-8'>
<div class="carousel slide media-carousel" id="media">
<div class="carousel-inner">
<div class="item active">
<div class="row">
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
</div>
</div>
<div class="item">
<div class="row">
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
</div>
</div>
<div class="item">
<div class="row">
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
<div class="col-md-4">
<a class="thumbnail" href="#"><img alt="" src="http://placehold.it/150x150"></a>
</div>
</div>
</div>
</div>
<a data-slide="prev" href="#media" class="left carousel-control">‹</a>
<a data-slide="next" href="#media" class="right carousel-control">›</a>
</div>
</div>
</div>
</div>
CSS
/* carousel */
.media-carousel
{
margin-bottom: 0;
padding: 0 40px 30px 40px;
margin-top: 30px;
}
/* Previous button */
.media-carousel .carousel-control.left
{
left: -12px;
background-image: none;
background: none repeat scroll 0 0 #222222;
border: 4px solid #FFFFFF;
border-radius: 23px 23px 23px 23px;
height: 40px;
width : 40px;
margin-top: 30px
}
/* Next button */
.media-carousel .carousel-control.right
{
right: -12px !important;
background-image: none;
background: none repeat scroll 0 0 #222222;
border: 4px solid #FFFFFF;
border-radius: 23px 23px 23px 23px;
height: 40px;
width : 40px;
margin-top: 30px
}
/* Changes the position of the indicators */
.media-carousel .carousel-indicators
{
right: 50%;
top: auto;
bottom: 0px;
margin-right: -19px;
}
/* Changes the colour of the indicators */
.media-carousel .carousel-indicators li
{
background: #c0c0c0;
}
.media-carousel .carousel-indicators .active
{
background: #333333;
}
.media-carousel img
{
width: 250px;
height: 100px
}
/* End carousel */
js
$(document).ready(function() {
$('#media').carousel({
pause: true,
interval: false,
});
});
Related
I am trying to get a grid of cards with a text and an image where the image cover all card spare space. But I can't get the text to show, the text is scrolled off the card which has an overflow: hidden. (https://jsfiddle.net/s8gxuza0/)
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(275px, 1fr));
gap: 24px;
}
.cell {
position: relative;
overflow: hidden;
border-radius: 6px;
padding-top: 100%;
background: red;
}
.link {
text-decoration: none;
color: inherit;
}
.content {
position: absolute;
top: 0px;
width: 100%;
height: 100%;
}
.image {
width: 100%;
height: 100%;
object-fit: cover;
}
.text {
padding: 16px;
}
<div class="grid">
<div class="cell">
<a class="link" href="https://stackoverflow.com/questions/65760464/grid-aspect-ratio-with-text-and-image-covering-all-spare-space" target="_blank">
<div class="content">
<img class="image" src="https://images.unsplash.com/photo-1499492568083-9115ab12d0d2?auto=format%2Ccompress&fit=crop&w=400" />
<div class="text">
text 1
</div>
</div>
</a>
</div>
<div class="cell">
<a class="link" href="https://stackoverflow.com/questions/65760464/grid-aspect-ratio-with-text-and-image-covering-all-spare-space" target="_blank">
<div class="content">
<img class="image" src="https://images.unsplash.com/photo-1533743409942-b91130480a7a?auto=format%2Ccompress&fit=crop&w=400" />
<div class="text">
text 2<br>
more text
</div>
</div>
</a>
</div>
<div class="cell">
<a class="link" href="https://stackoverflow.com/questions/65760464/grid-aspect-ratio-with-text-and-image-covering-all-spare-space" target="_blank">
<div class="content">
<img class="image" src="https://images.unsplash.com/photo-1505569127510-bde1536937bc?auto=format%2Ccompress&fit=crop&w=400" />
<div class="text">
text 3
</div>
</div>
</a>
</div>
<div class="cell">
<a class="link" href="https://stackoverflow.com/questions/65760464/grid-aspect-ratio-with-text-and-image-covering-all-spare-space" target="_blank">
<div class="content">
<img class="image" src="https://images.unsplash.com/photo-1531852855896-94f2949b34fe?auto=format%2Ccompress&fit=crop&w=400" />
<div class="text">
text 4<br>
more text
</div>
</div>
</a>
</div>
</div>
I too tryed with display: flex and flex: 1 1 auto but i didn't get it to work either.
Something like this, but keeping the aspect ratio of the whole card (image + text = aspect-ratio 1/1):
For example, as a diagram:
AND THIS FINAL VERSION
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(275px, 1fr));
gap: 24px;
}
.cell {
position: relative;
overflow: hidden;
border-radius: 6px;
padding-top: 100%;
background: red;
}
.link {
text-decoration: none;
color: inherit;
}
.content {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
display: flex;
flex-direction: column;
}
.image {
width: 100%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.text {
padding: 16px;
height: fit-content;
box-sizing: border-box;
}
<div class="grid">
<div class="cell">
<a class="link" href="https://stackoverflow.com/questions/65760464/grid-aspect-ratio-with-text-and-image-covering-all-spare-space" target="_blank">
<div class="content">
<div class="image" style="background-image: url(https://images.unsplash.com/photo-1499492568083-9115ab12d0d2?auto=format%2Ccompress&fit=crop&w=400);"></div>
<div class="text">
text 1
</div>
</div>
</a>
</div>
<div class="cell">
<a class="link" href="https://stackoverflow.com/questions/65760464/grid-aspect-ratio-with-text-and-image-covering-all-spare-space" target="_blank">
<div class="content">
<div class="image" style="background-image: url(https://images.unsplash.com/photo-1533743409942-b91130480a7a?auto=format%2Ccompress&fit=crop&w=400);"></div>
<div class="text">
text 2<br> more text
</div>
</div>
</a>
</div>
<div class="cell">
<a class="link" href="https://stackoverflow.com/questions/65760464/grid-aspect-ratio-with-text-and-image-covering-all-spare-space" target="_blank">
<div class="content">
<div class="image" style="background-image: url(https://images.unsplash.com/photo-1505569127510-bde1536937bc?auto=format%2Ccompress&fit=crop&w=400);"></div>
<div class="text">
text 3
</div>
</div>
</a>
</div>
<div class="cell">
<a class="link" href="https://stackoverflow.com/questions/65760464/grid-aspect-ratio-with-text-and-image-covering-all-spare-space" target="_blank">
<div class="content">
<div class="image" style="background-image: url(https://images.unsplash.com/photo-1531852855896-94f2949b34fe?auto=format%2Ccompress&fit=crop&w=400);"></div>
<div class="text">
text 4<br> more text
</div>
</div>
</a>
</div>
</div>
I have a bootstrap 4 header and I'm using flex in it for some custom layout.
Here is the html:
<nav class="navbar">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="logo.png" alt="">
</a>
<div class="box">
<div class="title">TITLE HERE</div>
<div class="flex-inline-container">
<div class="icon"><img src="icon1.png" alt="" /></div>
<div class="icon"><img src="icon2.png" alt="" /></div>
<div class="icon"><img src="icon3.png" alt="" /></div>
<div class="icon"><img src="icon4.png" alt="" /></div>
<div class="icon"><img src="icon5.png" alt="" /></div>
</div>
</div>
</div>
</nav>
And the CSS:
.box {
display: flex;
border-right: 2px solid #bfbfbf;
width: min-content;
flex-direction: column;
}
.box .flex-inline-container {
display: inline-flex;
}
.box .icon {
margin-right: 20px;
cursor: pointer;
}
.box .title {
position: relative;
left: 7px;
font-size: 1.40rem;
font-weight:300;
color: #727272 !important;
}
My issue is that the "flex-inline-container" div is going all the way to the right and I need it to be on the left.
How can I make it go to the left?
The .container-fluid class of bootstrap has a Justify-content:space-between property. Which distributes items evenly (The first item is flush with the start,
the last is flush with the end).
In your case the <a class="navbar-brand"><a> will be moved to first and elements inside <div class="box"></div> moved to last.
If you want to override Justify-content property of .Container-fluid and move to left, Then add a .justify-content-start along with .Container-fluid.
.box {
display: flex;
border-right: 2px solid #bfbfbf;
width: min-content;
flex-direction: column;
}
.box .flex-inline-container {
display: inline-flex;
}
.box .icon {
margin-right: 20px;
cursor: pointer;
}
.box .title {
position: relative;
left: 7px;
font-size: 1.40rem;
font-weight:300;
color: #727272 !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<nav class="navbar">
<div class="container-fluid flex-row-reverse">
<a class="navbar-brand" href="#">
<img src="logo.png" alt="">
</a>
<div class="box">
<div class="title">TITLE HERE</div>
<div class="flex-inline-container">
<div class="icon"><img src="icon1.png" alt="" /></div>
<div class="icon"><img src="icon2.png" alt="" /></div>
<div class="icon"><img src="icon3.png" alt="" /></div>
<div class="icon"><img src="icon4.png" alt="" /></div>
<div class="icon"><img src="icon5.png" alt="" /></div>
</div>
</div>
</div>
</nav>
I have created a calendar that displays each day in a column, and each day has multiple rows. I also added scroll snap to the grid. So the user can swipe horizontally to view each day. However due to the number of rows under the days, swiping (mobile) moves in both directions (vertically and horizontally). I'd like it to lock the swipe to go one direction at a time. So when the user swipes horizontally, the days move, once the day grid snaps in place, they can scroll vertically, or horizontally if they like. Here is my demo: https://codepen.io/starkana/pen/YzzBgPN
CSS & HTML
*,
:after,
:before {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html {
font-size: 62.5%;
}
body {
color: #384ad2;
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-size: 1.6rem;
height: 100%;
font-family: arial;
}
a {
text-decoration: none;
color: inherit;
}
body {
background: #ccc;
}
.calendar {
max-height: 100vh;
max-width: 100vh;
display: grid;
grid-template-columns: repeat(9, 80vw);
grid-column-gap: 20px;
scroll-snap-type: x mandatory;
padding-left: 5vw;
transition: transform 0.2s ease-in-out;
overflow-x: scroll;
justify-content: left;
}
.day {
margin-bottom: 100px;
min-width: 0;
scroll-snap-align: center;
}
.day h2 {
font-size: 1.5rem;
font-weight: 900;
letter-spacing: 0.1rem;
text-align: left;
text-transform: uppercase;
margin: 1rem 0;
}
.cards {
display: grid;
grid-row-gap: 6px;
grid-column-gap: 24px;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
justify-content: center;
min-width: 0;
}
.card {
background: #fff;
border-radius: 5px;
box-shadow: 0 4px 6px rgba(49, 54, 68, 0.05),
0 5px 20px rgba(49, 54, 68, 0.08);
max-height: 65px;
margin-bottom: 24px;
position: relative;
transition: box-shadow 0.6s ease, color 0.2s ease,
transform 0.2s ease-in-out;
}
.card:hover {
box-shadow: 0 4px 6px rgba(138, 155, 198, 0.05),
0 5px 25px rgba(82, 112, 194, 0.15);
}
.card:hover .highlighter {
opacity: 1;
}
.card a {
display: grid;
grid-template-columns: 50px auto;
}
.content {
padding: 10px 14px;
position: relative;
border: 1px solid red;
min-width: 0;
}
.title {
font-size: 1.4rem;
font-weight: 800;
overflow: hidden;
padding-bottom: 3px;
text-overflow: ellipsis;
white-space: nowrap;
}
.airing {
font-size: 1.3rem;
font-weight: 600;
opacity: 0.9;
}
.next,
.now {
background: blue;
border-radius: 4px;
top: -14px;
color: white;
font-size: 1.1rem;
font-weight: 800;
padding: 3px 8px;
position: absolute;
right: -12px;
}
.image {
border-radius: 4px 0 0 4px;
height: 100%;
max-height: 65px;
object-fit: cover;
object-position: center;
transition: opacity 0.3s;
width: 100%;
}
<div class="calendar">
<div class="day">
<h2>Monday</h2>
<div class="cards">
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
</div>
</div>
<div class="day">
<h2>Monday</h2>
<div class="cards">
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
</div>
</div>
<div class="day">
<h2>Monday</h2>
<div class="cards">
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
</div>
</div>
<div class="day">
<h2>Monday</h2>
<div class="cards">
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
</div>
</div>
<div class="day">
<h2>Monday</h2>
<div class="cards">
<div class="card">
<a href="#">
<img
src="/app/static/img/covers/large/12903-RSbXdLBGyI.jpg"
class="image"
/>
<div class="content">
<div class="title">Title</div>
<div class="airing">Subtitle</div>
</div>
</a>
</div>
</div>
</div>
</div>
Say I am creating a navigation bar using the header element:
header {
border: 1px solid #a2a2a2;
width: 100vw;
height: 150px;
position: fixed;
top: 0;
z-index: 1;
}
Now when the user scrolls down, the navigation bar obviously covers 150px of content. Is there a way to tell all the elements below this fixed navigation bar to "clear" it or something like that? So that the navigation bar remains fixed but does not cover content?
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
h2,
h3,
a {
color: #34495e;
}
a {
text-decoration: none;
}
.logo {
margin: 0;
font-size: 1.45em;
}
.main-nav {
margin-top: 5px;
}
.logo a,
.main-nav a {
padding: 10px 15px;
text-transform: uppercase;
text-align: center;
display: block;
}
.main-nav a {
color: #34495e;
font-size: .99em;
}
.main-nav a:hover {
color: #718daa;
}
.header {
height: 150px;
padding-top: .5em;
padding-bottom: .5em;
border: 1px solid #a2a2a2;
background-color: #f4f4f4;
-webkit-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
width: 100vw;
position: fixed;
top: 0;
z-index: 1;
}
/* =================================
Media Queries
==================================== */
#media (min-width: 769px) {
.header,
.main-nav {
display: flex;
}
.header {
flex-direction: column;
align-items: center;
.header {
width: 80%;
margin: 0 auto;
max-width: 1150px;
}
}
}
#media (min-width: 1025px) {
.header {
flex-direction: row;
justify-content: space-between;
}
}
.parallex {
background: url("https://scontent-lga3-1.xx.fbcdn.net/v/t31.0-8/277233_456825154330649_1101536084_o.jpg?_nc_cat=106&_nc_ht=scontent-lga3-1.xx&oh=a23cf28b01ae96e2585b36164a747906&oe=5D567AAB") no-repeat center bottom /cover;
background-attachment: fixed;
height: 100vh;
}
.text-in-parallex {
position: relative;
top: 70vh;
left: 28vw;
color: white;
font-size: 45px;
}
body {
background-color: #EEEEEE;
/* #EE2324 */
}
.menu-grid {
display: grid;
grid-template-columns: 1fr 3fr;
width: 80%;
margin: 20px auto 100px auto;
padding-bottom: 100px;
border: 1px solid lightgray;
background-color: white;
border-radius: 3px;
/* Shadow */
-moz-box-shadow: 0px 3px 30px 1px #ccc;
-webkit-box-shadow: 0px 3px 30px 1px #ccc;
box-shadow: 10px 15px 30px 15px #ccc;
font-family: 'Alice', serif;
}
.table-of-contents {
padding: 20px;
position: sticky;
top: 0;
height: 100vh;
}
.table-of-contents>h2 {
text-align: center;
margin-bottom: 10px;
}
.inner-menu-grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
background-color: white;
padding: 20px 20px 25px 20px;
border-radius: 3px;
}
.menu-item {
display: flex;
justify-content: space-between;
}
.price {
font-size: 20px;
}
.menu-section {
font-family: "Open Sans", Arial, sans-serif;
font-size: 20.9368px;
font-weight: 400;
margin-bottom: 10px;
}
.menu-section>a {
text-decoration: none;
color: #999999;
padding-left: 7px;
}
.menu-section>a:hover {
border-left: 1px solid blue;
color: #1f5ea9;
text-decoration: underline;
}
.name-of-food {
font-size: 20px;
}
.food-description {
color: grey;
font-style: italic;
}
.food-section {
grid-column: 1 / 3;
text-align: center;
padding-top: 20px;
font-size: 2em;
}
.food-section:nth-child(1) {
padding-top: 0;
}
.restaurant-info {
grid-column: 1 / 3;
text-align: center;
border: 1px solid lightgray;
padding: 20px 0px;
}
#search-form {
border-radius: 3px;
text-align: center;
margin-bottom: 10px;
}
#search-input {
width: 80%;
}
.fab {
padding: 10px;
font-size: 30px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 3px;
}
.fab:hover {
opacity: 0.7;
cursor: pointer;
}
.fa-facebook-square {
background: #3B5998;
color: white;
}
<header class="header">
<h1 class="logo">Flexbox</h1>
<ul class="main-nav">
<li>Menu</li>
<li>Contact</li>
</ul>
</header>
<div class="menu-grid">
<div class="restaurant-info">
<h1>Example Pizzeria</h1>
</div>
<div class="table-of-contents">
<h2>Menu</h2>
<form id="search-form">
<input id="search-input" type="search" placeholder="Or search for an item..." />
</form>
<h3 class="menu-section"><a id="appetizers-link" href="#appetizers">Appetizers</a></h3>
<h3 class="menu-section"><a id="rolls-calzones-link" href="#rolls-calzones">Rolls & Calzones</a></h3>
<h3 class="menu-section"><a id="pizza-link" href="#pizza">Pizza</a></h3>
<h3 class="menu-section"><a id="salads-link" href="#salads">Salads</a></h3>
<h3 class="menu-section"><a id="pasta-link" href="#pasta">Pasta</a></h3>
<h3 class="menu-section"><a id="sandwiches-link" href="#sandwiches">Sandwiches</a></h3>
</div>
<div class="inner-menu-grid">
<h2 id="appetizers" class="food-section">Appetizers</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Zucchini Sticks</span>
<p class="food-description">Served with marinara sauce</p>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Stuffed Mushrooms</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food"> Mozzarella Sticks (5)</span>
<p class="food-description">Served with marinara sauce</p>
</div>
<div class="price">
$7.50
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Baked Clams</span>
</div>
<div class="price">
$8.96
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Mozarella Caprese</span>
<p class="food-description">Fresh mozzarella, tomatores, basil, olive oil & balsamic vinegar</p>
</div>
<div class="price">
$7.50
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Mozzarella Sticks (5)</span>
</div>
<div class="price">
$7.50
</div>
</div>
<h2 id="rolls-calzones" class="food-section">Rolls and Calzones</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Buffalo Chcicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Spinahc Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Sausage Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken and Broccoli Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<h2 id="pizza" class="food-section">Pizza</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Zucchini Sticks</span>
<p class="food-description">Served with marinara sauce</p>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Stuffed Mushrooms</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food"> Mozzarella Sticks (5)</span>
<p class="food-description">Served with marinara sauce</p>
</div>
<div class="price">
$7.50
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Baked Clams</span>
</div>
<div class="price">
$8.96
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Mozarella Caprese</span>
<p class="food-description">Fresh mozzarella, tomatores, basil, olive oil & balsamic vinegar</p>
</div>
<div class="price">
$7.50
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Mozzarella Sticks (5)</span>
</div>
<div class="price">
$7.50
</div>
</div>
<h2 id="salads" class="food-section">Salads</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Buffalo Chcicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Spinahc Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Sausage Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken and Broccoli Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<h2 id="pasta" class="food-section">Pasta</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Pasta item</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Buffalo Chcicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Spinahc Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Sausage Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken and Broccoli Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<h2 id="sandwiches" class="food-section">Sandwiches</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Buffalo Chcicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Spinahc Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Sausage Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken and Broccoli Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
</div>
<!--close .inner-menu-grid-->
</div>
<!--close .menu-grid-->
View on JSFiddle
Create a grid with two rows, put the navigation bar in the top row, and put your content in your second row, and make sure that the first row starts at the top and finishes 150px from the top.
You might find position:sticky helpful.
It seems you are already using it for the "Table of Contents" section.
A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block. -- position.
Also note browser compatibility for position:sticky.
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
h2,
h3,
a {
color: #34495e;
}
a {
text-decoration: none;
}
.logo {
margin: 0;
font-size: 1.45em;
}
.main-nav {
margin-top: 5px;
}
.logo a,
.main-nav a {
padding: 10px 15px;
text-transform: uppercase;
text-align: center;
display: block;
}
.main-nav a {
color: #34495e;
font-size: .99em;
}
.main-nav a:hover {
color: #718daa;
}
.header {
height: 150px;
padding-top: .5em;
padding-bottom: .5em;
border: 1px solid #a2a2a2;
background-color: #f4f4f4;
-webkit-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
width: 100vw;
position: sticky;
top: 0;
z-index: 1;
}
/* =================================
Media Queries
==================================== */
#media (min-width: 769px) {
.header,
.main-nav {
display: flex;
}
.header {
flex-direction: column;
align-items: center;
.header {
width: 80%;
margin: 0 auto;
max-width: 1150px;
}
}
}
#media (min-width: 1025px) {
.header {
flex-direction: row;
justify-content: space-between;
}
}
.parallex {
background: url("https://scontent-lga3-1.xx.fbcdn.net/v/t31.0-8/277233_456825154330649_1101536084_o.jpg?_nc_cat=106&_nc_ht=scontent-lga3-1.xx&oh=a23cf28b01ae96e2585b36164a747906&oe=5D567AAB") no-repeat center bottom /cover;
background-attachment: fixed;
height: 100vh;
}
.text-in-parallex {
position: relative;
top: 70vh;
left: 28vw;
color: white;
font-size: 45px;
}
body {
background-color: #EEEEEE;
/* #EE2324 */
}
.menu-grid {
display: grid;
grid-template-columns: 1fr 3fr;
width: 80%;
margin: 20px auto 100px auto;
padding-bottom: 100px;
border: 1px solid lightgray;
background-color: white;
border-radius: 3px;
/* Shadow */
-moz-box-shadow: 0px 3px 30px 1px #ccc;
-webkit-box-shadow: 0px 3px 30px 1px #ccc;
box-shadow: 10px 15px 30px 15px #ccc;
font-family: 'Alice', serif;
}
.table-of-contents {
padding: 20px;
position: sticky;
top: 0;
height: 100vh;
}
.table-of-contents>h2 {
text-align: center;
margin-bottom: 10px;
}
.inner-menu-grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px;
background-color: white;
padding: 20px 20px 25px 20px;
border-radius: 3px;
}
.menu-item {
display: flex;
justify-content: space-between;
}
.price {
font-size: 20px;
}
.menu-section {
font-family: "Open Sans", Arial, sans-serif;
font-size: 20.9368px;
font-weight: 400;
margin-bottom: 10px;
}
.menu-section>a {
text-decoration: none;
color: #999999;
padding-left: 7px;
}
.menu-section>a:hover {
border-left: 1px solid blue;
color: #1f5ea9;
text-decoration: underline;
}
.name-of-food {
font-size: 20px;
}
.food-description {
color: grey;
font-style: italic;
}
.food-section {
grid-column: 1 / 3;
text-align: center;
padding-top: 20px;
font-size: 2em;
}
.food-section:nth-child(1) {
padding-top: 0;
}
.restaurant-info {
grid-column: 1 / 3;
text-align: center;
border: 1px solid lightgray;
padding: 20px 0px;
}
#search-form {
border-radius: 3px;
text-align: center;
margin-bottom: 10px;
}
#search-input {
width: 80%;
}
.fab {
padding: 10px;
font-size: 30px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 3px;
}
.fab:hover {
opacity: 0.7;
cursor: pointer;
}
.fa-facebook-square {
background: #3B5998;
color: white;
}
<header class="header">
<h1 class="logo">Flexbox</h1>
<ul class="main-nav">
<li>Menu</li>
<li>Contact</li>
</ul>
</header>
<div class="menu-grid">
<div class="restaurant-info">
<h1>Example Pizzeria</h1>
</div>
<div class="table-of-contents">
<h2>Menu</h2>
<form id="search-form">
<input id="search-input" type="search" placeholder="Or search for an item..." />
</form>
<h3 class="menu-section"><a id="appetizers-link" href="#appetizers">Appetizers</a></h3>
<h3 class="menu-section"><a id="rolls-calzones-link" href="#rolls-calzones">Rolls & Calzones</a></h3>
<h3 class="menu-section"><a id="pizza-link" href="#pizza">Pizza</a></h3>
<h3 class="menu-section"><a id="salads-link" href="#salads">Salads</a></h3>
<h3 class="menu-section"><a id="pasta-link" href="#pasta">Pasta</a></h3>
<h3 class="menu-section"><a id="sandwiches-link" href="#sandwiches">Sandwiches</a></h3>
</div>
<div class="inner-menu-grid">
<h2 id="appetizers" class="food-section">Appetizers</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Zucchini Sticks</span>
<p class="food-description">Served with marinara sauce</p>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Stuffed Mushrooms</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food"> Mozzarella Sticks (5)</span>
<p class="food-description">Served with marinara sauce</p>
</div>
<div class="price">
$7.50
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Baked Clams</span>
</div>
<div class="price">
$8.96
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Mozarella Caprese</span>
<p class="food-description">Fresh mozzarella, tomatores, basil, olive oil & balsamic vinegar</p>
</div>
<div class="price">
$7.50
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Mozzarella Sticks (5)</span>
</div>
<div class="price">
$7.50
</div>
</div>
<h2 id="rolls-calzones" class="food-section">Rolls and Calzones</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Buffalo Chcicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Spinahc Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Sausage Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken and Broccoli Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<h2 id="pizza" class="food-section">Pizza</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Zucchini Sticks</span>
<p class="food-description">Served with marinara sauce</p>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Stuffed Mushrooms</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food"> Mozzarella Sticks (5)</span>
<p class="food-description">Served with marinara sauce</p>
</div>
<div class="price">
$7.50
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Baked Clams</span>
</div>
<div class="price">
$8.96
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Mozarella Caprese</span>
<p class="food-description">Fresh mozzarella, tomatores, basil, olive oil & balsamic vinegar</p>
</div>
<div class="price">
$7.50
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Mozzarella Sticks (5)</span>
</div>
<div class="price">
$7.50
</div>
</div>
<h2 id="salads" class="food-section">Salads</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Buffalo Chcicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Spinahc Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Sausage Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken and Broccoli Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<h2 id="pasta" class="food-section">Pasta</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Pasta item</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Buffalo Chcicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Spinahc Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Sausage Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken and Broccoli Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<h2 id="sandwiches" class="food-section">Sandwiches</h2>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Buffalo Chcicken Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Spinahc Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Sausage Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
<div class="menu-item">
<div class="food-item">
<span class="name-of-food">Chicken and Broccoli Roll</span>
</div>
<div class="price">
$6.95
</div>
</div>
</div>
<!--close .inner-menu-grid-->
</div>
<!--close .menu-grid-->
I'd suggest that if you don't want content to be occluded by the header, position: fixed may not be the best solution. Another approach would be to layout the page so that the header has a fixed height, then the content below takes up the rest of the page height, with overflow set to auto, so that it will scroll but the header won't.
Quick example:
<main>
<header>...</header>
<div class="content">...</div>
</main>
body, html {
height: 100%;
}
main {
display: flex;
flex-direction: column;
height: 100%;
}
header {
height: 200px;
flex: 0 0 auto;
}
.content {
flex: 1;
overflow: auto;
}
I would like the content of the .container to be centered.
I am using the float:left property to create the gallery. It is also part of the code to resize and crop the thumbnails.
Any way to do this at all?
CSS:
.grid-item {
float: left;
width: 175px;
height: 120px;
overflow: hidden;
}
.grid-item img {
display: block;
max-width: 100%;
border: 2px solid #fff;
border-radius: 5px;
margin: 0 auto;
}
HTML:
<div class="container text-center">
<div id="links">
<a href="img.jpg" title="" class="grid-item" data-gallery>
<img src="img.jpg" alt="" class="img-rounded">
</a>
<a href="img.jpg" title="" class="grid-item" data-gallery>
<img src="img.jpg" alt="" class="img-rounded">
</a>
<a href="img.jpg" title="" class="grid-item" data-gallery>
<img src="img.jpg" alt="" class="img-rounded">
</a>
</div>
</div>
You should use flexbox to align your contents and you can read the comments in the CSS as to why which property is meant for. Hope, it helps.
#links{
display: flex; /*Generates a flexbox layout with default flex direction as row */
width: 100%; /* Not really required */
align-items: center; /*Aligns contents vertically */
justify-content: space-around; /*Aligns contents horizontally */
text-align: center; /*Aligns further text in the center */
flex-direction:row; /*By default its row, you can change to column for vertical alignment */
flex-flow:row wrap; /*To wrap items in other row when no more can be fit in the same row*/
}
.grid-item {
/* flex:1; If you need them to grow or shrink flexibly */
width: 175px;
height: 120px;
overflow: hidden;
}
.grid-item img {
display: block;
max-width: 100%;
border: 2px solid #fff;
border-radius: 5px;
margin: 0 auto;
}
<div class="container text-center">
<div id="links">
<a href="http://via.placeholder.com/400x400" title="" class="grid-item" data-gallery>
<img src="http://via.placeholder.com/400x400" alt="" class="img-rounded">
</a>
<a href="http://via.placeholder.com/400x400" title="" class="grid-item" data-gallery>
<img src="http://via.placeholder.com/400x400" alt="" class="img-rounded">
</a>
<a href="http://via.placeholder.com/400x400" title="" class="grid-item" data-gallery>
<img src="http://via.placeholder.com/400x400" alt="" class="img-rounded">
</a>
</div>
</div>
Usually when I run into this situation I will nest everything in the container in a sub-container and tweak that to my liking:
.container .center {
/*
This is just a way of centering the element,
you can use whatever technique.
*/
position:absolute;
top:50%;
left:50%;
transform:translateX(-50%) translateY(-50%);
}
<div class="container text-center">
<div class="center">
<div id="links">
<a href="img.jpg" title="" class="grid-item" data-gallery>
<img src="img.jpg" alt="" class="img-rounded">
</a>
<a href="img.jpg" title="" class="grid-item" data-gallery>
<img src="img.jpg" alt="" class="img-rounded">
</a>
<a href="img.jpg" title="" class="grid-item" data-gallery>
<img src="img.jpg" alt="" class="img-rounded">
</a>
</div>
</div>
</div>