I'm running into an issue with flex-wrap. Where I need flex-wrap: wrap to take care that images wrap and don't run out of the container. I don't need wrap for a link. See my issue below, also my code is included in the post.
JSFiddle
HTML
<div class="box">
<div class="image">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
</div>
<div class="tools">
View details
</div>
</div>
<div class="box">
<div class="image">
<img src="https://dummyimage.com/80x80/000/fff">
Lorem ipsum dolor sit amet, consectetur adipisicing dolor sit amet, consectetur.
</div>
<div class="tools">
View details
</div>
</div>
SCSS
.box {
border: 1px solid gray;
width: 100%;
display: flex;
margin-bottom: 15px;
&:after {
content: "";
display: table;
clear: both;
}
.image {
float: left;
width: 60%;
border-right: 1px solid gray;
display: flex;
align-items: center;
flex-wrap: wrap;
padding: 5px;
a {
text-decoration: none;
&:not(:last-of-type) {
margin-right: 5px;
}
}
}
.tools {
float: left;
width: 40%;
padding: 5px;
}
}
You can achieve this by adding
.box .image a:last-of-type {
flex: 1 1 0;
}
.box {
border: 1px solid gray;
width: 100%;
display: flex;
margin-bottom: 15px;
}
.box:after {
content: "";
display: table;
clear: both;
}
.box .image {
float: left;
width: 60%;
border-right: 1px solid gray;
display: flex;
align-items: center;
flex-wrap: wrap;
padding: 5px;
}
.box .image a {
text-decoration: none;
}
.box .image a:last-of-type {
flex: 1 1 0;
}
.box .image a:not(:last-of-type) {
margin-right: 5px;
}
.box .tools {
float: left;
width: 40%;
padding: 5px;
}
<div class="box">
<div class="image">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
</div>
<div class="tools">
View details
</div>
</div>
<div class="box">
<div class="image">
<img src="https://dummyimage.com/80x80/000/fff">
Lorem ipsum dolor sit amet, consectetur adipisicing dolor sit amet, consectetur.
</div>
<div class="tools">
View details
</div>
</div>
Min Width & Overflow Hidden
If you use min-width of 80px which is your image box size and add overflow:hidden, everything fits in fine and there's nothing falling out.
To make the demo better, I made the other columns a min-width of 80px and total min-width 160px (2x80px) and gave all containers overflow:hidden.
The Working Demo
See it working here
The Code
SCSS
.box {
border: 1px solid gray;
width: 100%;
display: flex;
margin-bottom: 15px;
min-width:160px;
overflow:hidden;
&:after {
content: "";
display: table;
clear: both;
}
.image {
float: left;
width: 60%;
min-width:80px;
overflow:hidden;
border-right: 1px solid gray;
display: flex;
align-items: center;
flex-wrap: wrap;
padding: 5px;
a {
text-decoration: none;
&:not(:last-of-type) {
margin-right: 5px;
}
}
}
.tools {
float: left;
width: 40%;
padding: 5px;
overflow:hidden;
flex-wrap: wrap;
min-width:80px;
}
}
HTML
<div class="box">
<div class="image">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
</div>
<div class="tools">
View details
</div>
</div>
<div class="box">
<div class="image">
<img src="https://dummyimage.com/80x80/000/fff">
Lorem ipsum dolor sit amet, consectetur adipisicing dolor sit amet, consectetur.
</div>
<div class="tools">
View details
</div>
</div>
You can add an extra container around the single box and the text. Define it as a flexbox and it will scale according to your desires.
* {
box-sizing: border-box;
}
.box {
border: 1px solid gray;
width: 100%;
display: flex;
margin-bottom: 15px;
}
.box:after {
content: "";
display: table;
clear: both;
}
.image {
width: 60%;
border-right: 1px solid gray;
display: flex;
align-items: center;
flex-wrap: wrap;
padding: 5px;
}
.image a {
text-decoration: none;
}
.image a:not(:last-of-type) {
margin-right: 5px;
}
.tools {
width: 40%;
padding: 5px;
}
<div class="box">
<div class="image">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
<img src="https://dummyimage.com/80x80/000/fff">
</div>
<div class="tools">
View details
</div>
</div>
<div class="box">
<div class="image">
<div style="display:flex; align-items: center;">
<img src="https://dummyimage.com/80x80/000/fff">
Lorem ipsum dolor sit amet, consectetur adipisicing dolor sit amet, consectetur.
</div>
</div>
<div class="tools">
View details
</div>
</div>
Please check my fiddle where I added my solution https://jsfiddle.net/Lazzaro/vkrh48tn/
I added new class
.image2 {
width: 60%;
border-right: 1px solid gray;
display: flex;
align-items: center;
flex-wrap: nowrap;
padding: 5px;
a {
text-decoration: none;
&:not(:last-of-type) {
margin-right: 5px;
}
}
}
and it works
Related
I'm trying to make a sidebar and top of the page not move when you scroll (like Twitter, Facebook, etc.).
I'm only using CSS and Html.
I managed to make the side bars stay there, but the "Home" part does not work.
I tried with Position: Sticky, set overflow-x to auto for the parent, tried wrapping it into another div and self-align: flex-start, but nothing seems to be working.
Now that I put it into a smaller screen, it also looks to overlap the Side bar with the Feed, and hide the Widgets.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
--twitter-color: #50b7f5;
--twitter-background: #e6ecf0;
}
/* Sidebar Styling Starts */
.sidebarOption {
display: flex;
align-items: center;
cursor: pointer;
}
.sidebarOption .material-icons,
.fa-twitter {
padding: 20px;
}
.sidebarOption h2 {
font-weight: 800;
font-size: 20px;
margin-right: 20px;
}
.sidebarOption:hover {
background-color: var(--twitter-background);
border-radius: 30px;
color: var(--twitter-color);
transition: color 100ms ease-out;
}
.sidebarOption.active {
color: var(--twitter-color);
}
.sidebar_tweet {
width: 100%;
background-color: var(--twitter-color);
border: none;
color: white;
font-weight: 900;
border-radius: 30px;
height: 50px;
margin-top: 20px;
}
body {
display: flex;
height: 100%;
max-width: 1300px;
margin-left: auto;
margin-right: auto;
padding: 0 10px;
overflow-x: auto;
}
.sidebar {
border-right: 1px solid var(--twitter-background);
flex: 0.2;
min-width: 250px;
margin-top: 20px;
padding-left: 20px;
padding-right: 20px;
left: 0;
align-self: flex-start;
position: sticky;
top: 0;
overflow-x: auto;
}
.fa-twitter {
color: var(--twitter-color);
font-size: 30px;
}
/* Sidebar Styling Ends */
/* Feed Styling Starts */
.feed {
flex: 0.5;
border-right: 1px solid var(--twitter-background);
min-width: fit-content;
overflow-x: auto;
align-self: flex-start;
}
.feed-header {
border: 1px solid var(--twitter-background);
padding: 15px 20px;
/* I DONT KNOW HOW TO MAKE THIS STICK */
}
.feed-header h2 {
font-size: 20px;
font-weight: 800;
}
.feed::-webkit-scrollbar {
display: none;
}
.feed {
-ms-overflow-style: none;
scrollbar-width: none;
}
/* Styling Tweetbox Starts */
.tweetbox__input img {
border-radius: 50%;
height: 40px;
}
.tweetBox {
padding-bottom: 10px;
border-bottom: 8px solid var(--twitter-background);
padding-right: 10px;
}
.tweetBox form {
display: flex;
flex-direction: column;
}
.tweetbox__input {
display: flex;
padding: 20px;
}
.tweetbox__input input {
display: flex;
margin-left: 20px;
font-size: 20px;
border: none;
outline: none;
}
.tweetBox__tweetButton {
background-color: var(--twitter-color);
border: none;
color: white;
font-weight: 900;
border-radius: 30px;
width: 80px;
height: 40px;
margin-top: 20px;
margin-left: auto;
}
/* Styling Tweetbox Ends */
/* Feed Styling Ends */
/* Post Styling Starts */
.post__avatar img {
border-radius: 50%;
height: 40px;
}
.post {
display: flex;
align-items: flex-start;
border-bottom: 1px solid var(--twitter-background);
padding-bottom: 10px;
}
.post__body img {
width: 450px;
object-fit: contain;
border-radius: 20px;
}
.post__footer {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
.post__badge {
font-size: 14px !important;
color: var(--twitter-color);
margin-right: 5px;
}
.post__headerSpecial {
font-weight: 600;
font-size: 12px;
color: gray;
}
.post__headerText {
font-size: 15px;
margin-bottom: 5px;
}
.post__headerDescription {
margin-bottom: 10px;
font-size: 15px;
}
.post__body {
flex: 1;
padding: 10px;
}
.post__avatar {
padding: 20px;
}
/* Post Styling Ends */
/* Widgets Styling Starts */
.widgets {
flex: 0.3;
right: 0;
right: 0;
align-self: flex-start;
position: sticky;
top: 0;
overflow-x: auto;
}
.widgest__input {
display: flex;
align-items: center;
background-color: var(--twitter-background);
padding: 10px;
border-radius: 20px;
margin-top: 10px;
margin-left: 20px;
}
.widgest__input input {
border: none;
background-color: var(--twitter-background);
outline: none;
}
.widgets__searchIcon {
color: gray;
}
.widgets__widgetContainer {
display: flex;
flex-direction: column;
margin-top: 10px;
margin-left: 20px;
padding: 20px;
background-color: #f5f8fa;
border-radius: 20px;
}
.widgets__widgetContainer h2 {
font-size: 18px;
font-weight: 800;
}
.card_container {
display: flex;
flex-direction: column;
align-items: center;
}
.card {
display: flex;
flex-direction: column;
align-items: flex-start;
width: 18rem;
}
.card img {
border-radius: 20px;
width: 18rem;
}
/* Widgets Styling Ends */
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Twiter Clone</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- Sidebar Start -->
<div class="sidebar">
<i class="fab fa-twitter "></i>
<div class="sidebarOption active ">
<span class="material-icons ">home</span>
<h2>Home</h2>
</div>
<div class="sidebarOption">
<span class="material-icons ">search</span>
<h2>Explore</h2>
</div>
<div class="sidebarOption">
<span class="material-icons ">notifications_none</span>
<h2>Notifications</h2>
</div>
<div class="sidebarOption">
<span class="material-icons ">mail_outline</span>
<h2>Message</h2>
</div>
<div class="sidebarOption">
<span class="material-icons ">bookmark_border</span>
<h2>Bookmarks</h2>
</div>
<div class="sidebarOption">
<span class="material-icons">list_alt</span>
<h2>Lists</h2>
</div>
<div class="sidebarOption">
<span class="material-icons">perm_identity</span>
<h2>Profile</h2>
</div>
<div class="sidebarOption">
<span class="material-icons">more_horiz</span>
<h2>More</h2>
</div>
<button class="sidebar_tweet">Tweet</button>
</div>
<!-- Sidebar End -->
<!-- Feed Starts -->
<div class="feed">
<div class="feed_header">
<h2>Home</h2>
</div>
<!-- Tweetbox Starts -->
<div class="tweetBox">
<form>
<div class="tweetbox__input">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
<input type="text" placeholder="What's happening">
</div>
<button class="tweetBox__tweetButton">Tweet</button>
</form>
</div>
<!-- Tweetbox Ends -->
<!-- Post Starts -->
<div class="post">
<div class="post__avatar">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
</div>
<div class="post__body">
<div class="post__header">
<div class="post__headerText">
<h3>My Name
<span class="post_headerSpecial">
<span class="material-icons post__badge"> verified </span>#myname
</span>
</h3>
</div>
<div class="post_headerDescription">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
<img src="https://i.ytimg.com/vi/bepwr1-CNRU/maxresdefault.jpg" alt="">
<div class="post__footer">
<span class="material-icons">repeat</span>
<span class="material-icons">favorite_border</span>
<span class="material-icons">publish</span>
</div>
</div>
</div>
<!-- Post Ends -->
<!-- Post Starts -->
<div class="post">
<div class="post__avatar">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
</div>
<div class="post__body">
<div class="post__header">
<div class="post__headerText">
<h3>My Name
<span class="post_headerSpecial">
<span class="material-icons post__badge"> verified </span>#myname
</span>
</h3>
</div>
<div class="post_headerDescription">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
<img src="https://i.ytimg.com/vi/bepwr1-CNRU/maxresdefault.jpg" alt="">
<div class="post__footer">
<span class="material-icons">repeat</span>
<span class="material-icons">favorite_border</span>
<span class="material-icons">publish</span>
</div>
</div>
</div>
<!-- Post Ends -->
<!-- Post Starts -->
<div class="post">
<div class="post__avatar">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
</div>
<div class="post__body">
<div class="post__header">
<div class="post__headerText">
<h3>My Name
<span class="post_headerSpecial">
<span class="material-icons post__badge"> verified </span>#myname
</span>
</h3>
</div>
<div class="post_headerDescription">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
<img src="https://i.ytimg.com/vi/bepwr1-CNRU/maxresdefault.jpg" alt="">
<div class="post__footer">
<span class="material-icons">repeat</span>
<span class="material-icons">favorite_border</span>
<span class="material-icons">publish</span>
</div>
</div>
</div>
<!-- Post Ends -->
<!-- Post Starts -->
<div class="post">
<div class="post__avatar">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
</div>
<div class="post__body">
<div class="post__header">
<div class="post__headerText">
<h3>My Name
<span class="post_headerSpecial">
<span class="material-icons post__badge"> verified </span>#myname
</span>
</h3>
</div>
<div class="post_headerDescription">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
<img src="https://i.ytimg.com/vi/bepwr1-CNRU/maxresdefault.jpg" alt="">
<div class="post__footer">
<span class="material-icons">repeat</span>
<span class="material-icons">favorite_border</span>
<span class="material-icons">publish</span>
</div>
</div>
</div>
<!-- Post Ends -->
</div>
<!-- Feed Ends -->
<!-- Widget Starts -->
<div class="widgets">
<div class="widgest__input">
<span class="material-icons widgets__searchIcon"> search </span>
<input type="text" placeholder="search Twitter">
</div>
<div class="widgets__widgetContainer">
<h2>What's happening</h2>
<div class="card_container">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://neilpatel.com/wp-content/uploads/2021/03/source-code_featured-image.png" alt="Card image cap">
<div class="card-body">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
</div>
<div class="widgets__widgetContainer">
<h2>What's happening</h2>
<div class="card_container">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://neilpatel.com/wp-content/uploads/2021/03/source-code_featured-image.png" alt="Card image cap">
<div class="card-body">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
</div>
</div>
<!-- Widget Ends -->
</body>
</html>
In your code if you remove overflow-x: auto from .feed and add
.feed_header {
position: sticky;
top: 0;
}
the 'Home' heading sticks to the top as you scroll.
Another way is to use
.feed_header {
position: fixed;
top: 0;
}
.feed {
margin-top: 16px;
}
This fixes the feed_header to the top of the screen as you scroll. The feed container then needs a bit of spacing at the top to ensure the feed_header isn't overlapping.
Remove overflow-x: auto; from .feed and add this to your css:
.feed_header, .tweetBox {
position: sticky;
top: 0;
}
Please insert the following code and make changes to your classes as well.
change from .feed-header to .feed_header
.feed_header {
border: 1px solid var(--twitter-background);
padding: 15px 20px;
/* I DONT KNOW HOW TO MAKE THIS STICK */
position: fixed; /*Code to add*/
top: 0; /*Code to add*/
}
Adding on to #John's answer - sometimes you may need to specify z-index:1 to have the element always on top while scrolling. Like this:
position: -webkit-sticky; /* Safari & IE */
position: sticky;
top: 0;
z-index: 1;
Just add position: fixed for sidebar and feed header.
.feed_header, .sidebar {
position: fixed;
top: 0;
}
I have a task that supports older browsers such as IE9, so I cannot use flexbox or CSS Grid.
I'm struggling with making the .second and .third have equal height as the .first div.
Here is my attempt.
https://codepen.io/abccba_123/pen/QWKMwpK
img {
width: 100%;
height: auto;
}
.first img {
background-color: gold;
}
.second img {
background-color: cyan;
}
.third img {
background-color: grey;
}
.container {
width: 1000px;
margin: 0 auto;
}
.container article {
position: relative;
}
.wrap {
position: absolute;
bottom: 0;
}
.first {
float: left;
width: 50%;
}
.second {
float: left;
width: 30%;
}
.third {
float: left;
width: 30%;
}
<div class="container">
<article class="first">
<img width="1920" height="1080">
<div class="wrap">
<h3>Lorem ipsum dolor sit amet.<h3>
</div>
</article>
<article class="second">
<img width="1920" height="1080">
<div class="wrap">
<h3>Lorem ipsum dolor sit amet.<h3>
</div>
</article>
<article class="third">
<img width="1920" height="1080">
<div class="wrap">
<h3>Lorem ipsum dolor sit amet.<h3>
</div>
</article>
</div>
What I want.
Thank you!!
You may also use a display:table reset ;) Understood by every browsers and IE8+
(.wrap div removed , but you can use it)
img {
width: 100%;
height: auto;
}
.first {
background-color: gold;
}
.second {
background-color: cyan;
margin-bottom: 5px;
}
.third {
background-color: grey;
}
.container {
width: 100%;/* for demo */
/* width:1000px; */
margin: 0 auto;
display: table;
/* IE8 + */
table-layout: fixed;
/* IE8 + */
border-spacing: 5px;
border: solid;
}
.container article {
border: solid;
margin: -left:5px;
}
h3 {
padding: 1em;
}
.img {
vertical-align: top;
}
.first {
display: table-cell;
/* IE8 + */
width: 50%;
vertical-align: top;
}
<div class="container">
<article class="first">
<img src="https://picsum.photos/id/118/536/354.jpg" width="1920" height="1080">
<h3>Lorem ipsum dolor sit amet. </h3>
</article>
<article class="second">
<img src="https://picsum.photos/id/1015/536/354.jpg" width="1920" height="1080">
<h3>Lorem ipsum dolor sit amet. </h3>
</article>
<article class="third">
<img src="https://picsum.photos/id/1016/536/354.jpg" width="1920" height="1080">
<h3>Lorem ipsum dolor sit amet. </h3>
</article>
</div>
A simple table layout:
img {
display:block;
}
.first img {
background-color: gold;
}
.second img {
background-color: cyan;
}
.third img {
background-color: grey;
}
.container {
margin: 0 auto;
}
.container td {
position: relative;
}
.container td h3 {
position:absolute;
bottom:0;
left:0;
right:0;
}
<table class="container">
<tr>
<td class="first" rowspan="2">
<img width="300" height="400">
<h3>Lorem ipsum dolor sit amet.</h3>
</td>
<td class="second">
<img width="300" height="200">
<h3>Lorem ipsum dolor sit amet.</h3>
</td>
</tr>
<tr>
<td class="third">
<img width="300" height="200">
<h3>Lorem ipsum dolor sit amet.</h3>
</td>
</tr>
</table>
.cont {
width: 1000px;
margin: 0 auto;
}
img {
width: 100%;
height: 100%;
}
article {
position: relative;
}
.first {
float: left;
width: 500px;
height: 300px;
background-color: gold;
}
.second, .third {
float: left;
width: 500px;
height: 150px;
overflow: hidden;
}
.second {
background-color: lime;
}
.third {
background-color: cyan;
}
.info {
color: white;
padding: 10px 10px 0 10px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
<div class="cont">
<article class="first">
<img src="https://picsum.photos/1920/1080" width="1920" height="1080">
<div class="info">
<h3>Lorem ipsum dolor sit amet.</h3>
</div>
</article>
<article class="second">
<img src="https://picsum.photos/1920/1080" width="1920" height="1080">
<div class="info">
<h3>Lorem ipsum dolor sit amet.</h3>
</div>
</article>
<article class="third">
<img src="https://picsum.photos/1920/1080" width="1920" height="1080">
<div class="info">
<h3>Lorem ipsum dolor sit amet.</h3>
</div>
</article>
</div>
I've partially solved my own problem.
I set the top navigation bar as being sticky on top, but it's acting weird in some places.
Here's the fiddle link https://jsfiddle.net/benjaminana77/pugek2f8/30/ and I reproduced code below.
I'm having problems in three places
In the hero image section, top nav background is incorrectly being transparent. I set the background color as white, not transparent.
The top nav bar incorrectly shows BEHIND a slider, not above the slider.
When you hover over an item in the grid layout, the item shows above the top nav bar.
normal state:
when you hover over an image:
Many thanks in advance!
HTML:
<div class="boxA">
<div class="box1">
<div class="site">
<img src="img/logo.png">
</div>
</div>
<div class="box2">
<nav class="menu">
<ul>
<li>menu1</li>
<li>menu2</li>
<li>menu3</li>
<li>menu4</li>
</ul>
</nav>
</div>
</div>
<div class="body-part">
<section class="conA">
<div id="container">
<div id="heroText">
<p>Lorem ipsum Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercit</p>
<div id="text"></div>
</div>
<div id="images"></div>
</div>
</section>
<ul class="slider" style="padding:0px !important;">
<li><img src="img/sample.png">
<div class="caption1">caption 1</div>
</li>
<li> <img src="img/Group 3.png">
<div class="caption2"></div>
<div class="caption3">caption 2</div>
<div class="caption5">caption 3</div>
<div class="caption4">caption 4</div>
</li>
</ul>
<section id="conD">
<div class="container">
<div class="grid menu-content" id="menu1-content">
<article>
<a href="#">
<div class="photo" style="background-image: url(https://www.gravatar.com/avatar/a235706e3d81b614acaec3368edfea4b?s=96&d=identicon&r=PG);"></div>
<div class="text">
<h3>Title </h3>
<p>Lorem ipsum dolor </p>
</div>
</a>
</article>
<article>
<a href="#">
<div class="photo" style="background-image: url(img/sample.jpg);"></div>
<div class="text">
<h3>Headingg</h3>
<p>Lorem ipsum dolor </p>
</div>
</a>
</article>
<article>
<a href="#">
<div class="photo" style="background-image: url(img/sample.jpg);"></div>
<div class="text">
<h3>Headingg</h3>
<p>Lorem ipsum dolor </p>
</div>
</a>
</article>
</div>
</div>
</section>
CSS:
.boxA:after {
content:"";
display: block;
clear: both;
}
.boxA {
height: 90px;
position: fixed;
border-bottom: 1px solid #E0DCDC;
top: 0;
width: 100%;
background-color: white;
max-width: 1440px;
}
.boxA img {
position: absolute;
top: 50%;
left: 3%;
transform: translate(0, -50%);
}
.box2 ul {
position: absolute;
top: 50%;
transform: translate(0, -50%);
right: 10px;
}
.box1 {
float: left;
width: auto;
}
.box2 {
float: right;
width: auto;
}
.box2 ul {
margin: 0;
padding: 0;
list-style: none;
}
.box2 li a {
display: block;
padding: 0px 50px;
color: inherit;
text-decoration: none;
font-size: 12px;
}
.box2 li a:hover {
text-decoration: underline;
}
.box2 ul:after {
content: "";
display: block;
clear: both;
}
.box2 li {
float: left;
width: auto;
font-family: 'Gotham';
letter-spacing: 2.5px;
}
.box1 img {
position: absolute;
width: 20%;
height: auto;
}
#top-logo {
margin-top: 40px;
}
#top-logo img {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
height: auto;
}
body {
font-family: gotham;
margin: 0px !important;
color: #827F88;
letter-spacing: 0.4px;
line-height: 1.9;
}
.conA {
height: 100vh;
display: flex;
position: relative;
}
.conA #container {
margin: 0;
display: flex;
align-items: flex-start;
position: absolute;
top: 50%;
left: 10%;
transform: translate(0%, -50%);
}
#heroText {
font-size: 37px;
color: #56525E;
line-height: 1 !important;
}
.conA #heroText {
height: 400px;
padding-top: 100px;
}
#conD ul {
margin: 0 0 30px -30px;
padding: 0;
list-style: none;
}
#conD li {
padding: 35px;
display: block;
text-decoration: none;
font-size: 15.5px;
letter-spacing: 2px;
color: inherit;
}
#conD li {
float: left;
width: auto;
}
#conD ul:after {
content:"";
display: block;
clear: both;
}
#conD .menu {
margin-bottom: 20px
}
.grid {
display: grid;
justify-content: start;
margin-top: -20px;
}
.grid .photo {
width: 100%;
background-size: contain;
background-position: center;
}
.grid .photo:after {
content: "";
display: block;
padding-bottom: 100%;
}
.grid a {
display: block;
text-decoration: none;
color: inherit;
}
.grid a:hover {
opacity: 0.8;
}
JQUERY:
$(document).ready(function(){
$('.slider').bxSlider({
auto: true,
pause: 3000,
mode: 'fade',
speed: 1200,
pager: false
});
});
(function ($) {
$(document).ready(function(){
// hide .navbar first
$(".boxA").hide();
// fade in .navbar
$(function () {
$(window).scroll(function () {
// set distance user needs to scroll before we start fadeIn
if ($(this).scrollTop() > 50) {
$('.boxA').fadeIn();
$('#top-logo').fadeOut();
} else {
$('.boxA').fadeOut();
$('#top-logo').fadeIn();
}
});
});
});
}(jQuery));
Add z-index:2 on .boxA
.boxA {
height: 90px;
position: fixed;
border-bottom: 1px solid #E0DCDC;
top: 0;
width: 100%;
background-color: white;
max-width: 1440px;
z-index: 2;
}
.body-part{
position: relative;
z-index: 1;
}
https://jsfiddle.net/lalji1051/24rm0yvt/
updated link - https://jsfiddle.net/lalji1051/24rm0yvt/3/
I am creating a demo page and it is almost ready.
Here is the codepen link of it. https://codepen.io/kamalpancholi/full/wvGMgEK?editors=1100
But I am facing two issues.
[1] When I click on the navbar link, the page scrolls a little below the actual element. Results in some of the actual content goes below header. I am using sticky header.
[2] I don't understand why I need to use so many !important in CSS media queries ? Am I doing something wrong in media queries ? The value provided in media query was never updated until I used !important with it.
Below is the code
#import url('https://fonts.googleapis.com/css2?family=Oswald&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Ubuntu&display=swap');
* {margin: 0; padding: 0;}
body{ font-family: 'oswald', sans-serif}
.text-center { text-align: center; }
.text-left { text-align: center; }
.block { display: block; }
.inline { display: inline; }
.bold { font-weight: bold; }
.no-decor-link {
text-decoration: none;
color: black;
}
.no-bullets { list-style-type: none; }
.orangered { color: orangered; }
.ubuntu { font-family: 'Ubuntu', sans-serif }
.oswald { font-family: 'Oswald', sans-serif }
#header {
background-color: #FFDEAD;
position: sticky;
top: 0;
z-index: 2;
}
#logoNtitle {
display: inline-block;
}
#header-img {
width: 80px;
height: auto;
margin: 1em auto 0.7em 10vw;
}
#header-text{
position: relative;
top: -14px;
font-size: 2em;
margin-left: 0.8em;
}
#nav-bar {
float: right;
position: relative;
top: 2.3em;
right: 2em;
font-family: 'Ubuntu', sans-serif;
}
#nav-bar a{
padding: 1em 0.5em 1em 0.5em;
}
#main {
width: 1020px;
margin: auto;
background-color: #e6e6e6;
padding: 0.05px; /* to avoid margin collapsing */
}
#main p {
margin: 1em;
}
#media(max-width: 1020px) {
#main { width: 800px; }
#video {
width: 500px !important;
height: 281.25px !important;
}
#demo {
margin: 1em auto 3em !important;
}
}
#media(max-width: 800px) {
#main { width: 100%; }
#features-1 .ico { display: none !important; }
#features-1 { width: 80% !important; }
#nav-bar {
float: none;
position: initial;
text-align: center;
padding-bottom: 1em;
}
#logoNtitle {
display: block;
width: 320px;
margin: auto;
}
#header-img {
margin-left: auto;
}
#demo {
margin-top: 1em !important;
margin-bottom: 1em !important;
}
#pricing { margin-bottom: 1.2em; }
#pricing-content {
display: initial !important;
padding: 0.05px;
margin: 1em auto !important;
}
.card {
width: 300px;
margin: 1em auto 0.5em;
}
}
#media(max-width: 550px) {
#video {
width: 90vw !important;
height: 50.625vw !important;
}
}
#email {
display: block;
margin: 1em auto 1em auto;
border-radius: 3px;
border: 2px solid black;
padding: 0.3em 7px 0.3em 7px;
color: #1b2b34;
min-width: 15em;
}
#submit {
display: block;
margin: auto auto 1em auto;
background-color: #5fce6a;
border: none;/*1px solid grey;*/
padding: 0.5em 1em;
font-size: 1em;
}
#features-1{
width: 50%;
margin: 3em auto 2em;
}
.flex {
display: flex;
flex-direction: row;
}
#features-1 .ico {
display: flex;
height: 100px;
width: 90px;
justify-content: center;
align-items: center;
color: orangered;
}
#features-1 .content {
display: flex;
flex-direction: column;
justify-content: center;
height: 100px;
width: 75vw;
padding-left: 30px;
padding-right: 10px;
}
#features-2 {
margin: auto;
display: flex;
flex-direction: column;
}
#features-2 ul {
list-style-type: none;
line-height: 2em;
margin: auto;
}
#features-2 .feature-title {
font-size: 1.2em;
margin: 1% auto;
}
#features ul li:before {
content: '\2713';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
#demo {
margin: 2em auto 3em;
}
#video-title {
text-align: center;
padding: 1em;
font-family: 'ubuntu', sans-serif;
}
#video {
display: block;
width: 729px;
height: 410px;
margin: auto;
}
#pricing-content {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 1.3em;
width: 95%;
margin: 2em auto;
}
.card {
border: 2px solid black;
text-align: center;
}
.card h3 {
background-color: #BDBBBB;
padding: 0.5em 1em;
}
.card h2 {
font-weight: bold;
line-height: 2em;
}
.card ul {
line-height: 2em;
font-family: 'ubuntu';
}
.card button {
padding: 0.5em 2.3em;
margin: 1em auto;
background-color: orangered;
border: none;
font-family: 'ubuntu';
font-weight: bold;
}
.true:before {
content: '\2713';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
.false:before {
content: '\2717';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
footer div {
background-color: #BDBBBB;
font-family: 'ubuntu';
padding: 0.05px;
}
footer ul {
padding-top: 1.3em;
padding-bottom: 0.5em;
}
footer li {
display: inline;
padding-left: 1em;
padding-right: 1em;
}
.footer-content p {
margin-top: 0px !important;
font-size: 13px;
}
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>CodePen - Product page</title>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css'><link rel="stylesheet" href="./style.css">
</head>
<body>
<!-- partial:index.partial.html -->
<header id="header">
<div id="logoNtitle">
<img src="https://www.freepnglogos.com/uploads/eagles-png-logo/eagle-sports-png-logos--0.png" alt="product logo" id="header-img" class="inline">
<span id="header-text">The Lorem Ipsum</span>
</div>
<nav id="nav-bar">
<div id="links">
<span>Features</span>
<span>Demo</span>
<span>Pricing</span>
<span>Contact Us!</span>
</div>
</nav>
</header>
<div id="main">
<p class="text-center ubuntu pclass"> Provide your email for more information about product </p>
<form id="form" action="https://www.freecodecamp.com/email-submit">
<label for="email">
<input type="email" id="email" name="email" placeholder="Enter your email address">
</label>
<input type="submit" value="Submit" id="submit">
</form>
<div id="features" class="ubuntu">
<div id="features-1">
<div class="flex">
<div class="ico"><i class="fas fa-air-freshener fa-2x"></i></div>
<div class="content">
<h3>Premium quality material</h3>
<span>Lorem ipsum dolor sit amat, consecite adispicing elit, ipsum dolor sit amat, consecite adispicing elit</span>
</div>
</div>
<div class="flex">
<div class="ico"><i class="fas fa-shipping-fast fa-2x"></i></div>
<div class="content">
<h3>Fast shipping</h3>
<span>Lorem ipsum amat, dolorem ipsum</span>
</div>
</div>
<div class="flex">
<div class="ico"><i class="fas fa-user-clock fa-2x"></i></div>
<div class="content">
<h3>Timely maintenance updates</h3>
<span>Lorem ipsum dolor sit amat, consecite adispicing elit</span>
</div>
</div>
</div>
<div id="features-2">
<p class="bold feature-title">Why to choose us ?</p>
<ul> <!-- use css list-style-type: none; to remove bullets
use list-style-image: url(img.png) to use an image as bullet -->
<li>Lorem ipsum dolor</li>
<li>sit amet, consectetur adipiscing elit</li>
<li>Nunc tempor</li>
<li>dolorem ipsum quia</li>
<li>Lorem ipsum dolor</li>
<li>sit amet, consectetur adipiscing elit</li>
<li>Nunc tempor</li>
<li>dolorem ipsum quia</li>
</ul>
</div>
</div>
<div id="demo">
<h2 id="video-title">Here is how it works !!!</h2>
<div class="video-container">
<iframe width="729" height="410" id="video" src="https://www.youtube.com/embed/CmzKQ3PSrow" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
<div id="pricing">
<div id="pricing-content">
<div class="card">
<h3>Basic Package</h3>
<h2>$500</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="false">Dolor sit, amat</li>
<li class="false">Nunc tempor</li>
<li class="false">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
<div class="card">
<h3>Premium Package</h3>
<h2>$600</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="true">Dolor sit, amat</li>
<li class="false">Nunc tempor</li>
<li class="false">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
<div class="card">
<h3>Pro Package</h3>
<h2>$800</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="true">Dolor sit, amat</li>
<li class="true">Nunc tempor</li>
<li class="true">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
</div>
</div>
<footer id="contact">
<div class="footer-content">
<ul class="no-bullets">
<li>Privacy</li>
<li>Terms</li>
<li>Contact</li>
</ul>
<p>©The Lorem Ipsum</p>
</div>
</footer>
</div>
<!-- partial -->
<script src='https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js'></script>
</body>
</html>
I've added padding-top: 75px; and padding-top: 40px; to the page anchors to give it the buffer you are looking for.
#import url('https://fonts.googleapis.com/css2?family=Oswald&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Ubuntu&display=swap');
* {
margin: 0;
padding: 0;
}
body {
font-family: 'oswald', sans-serif
}
.text-center,
.text-left {
text-align: center;
}
.block {
display: block;
}
.inline {
display: inline;
}
.bold {
font-weight: bold;
}
.no-decor-link {
text-decoration: none;
color: black;
}
.no-bullets {
list-style-type: none;
}
.orangered {
color: orangered;
}
.ubuntu {
font-family: 'Ubuntu', sans-serif;
}
#features {
padding-top: 40px;
}
#demo {
padding-top: 75px;
}
.oswald {
font-family: 'Oswald', sans-serif
}
#header {
background-color: #FFDEAD;
position: sticky;
top: 0;
z-index: 2;
}
#logoNtitle {
display: inline-block;
}
#header-img {
width: 80px;
height: auto;
margin: 1em auto 0.7em 10vw;
}
#header-text {
position: relative;
top: -14px;
font-size: 2em;
margin-left: 0.8em;
}
#nav-bar {
float: right;
position: relative;
top: 2.3em;
right: 2em;
font-family: 'Ubuntu', sans-serif;
}
#nav-bar a {
padding: 1em 0.5em 1em 0.5em;
}
#main {
width: 1020px;
margin: auto;
background-color: #e6e6e6;
padding: 0.05px;
/* to avoid margin collapsing */
}
#main p {
margin: 1em;
}
#media(max-width: 1020px) {
#main {
width: 800px;
}
#video {
width: 500px !important;
height: 281.25px !important;
}
#demo {
margin: 1em auto 3em !important;
}
}
#media(max-width: 800px) {
#main {
width: 100%;
}
#features-1 .ico {
display: none !important;
}
#features-1 {
width: 80% !important;
}
#nav-bar {
float: none;
position: initial;
text-align: center;
padding-bottom: 1em;
}
#logoNtitle {
display: block;
width: 320px;
margin: auto;
}
#header-img {
margin-left: auto;
}
#demo {
margin-top: 1em !important;
margin-bottom: 1em !important;
}
#pricing {
margin-bottom: 1.2em;
}
#pricing-content {
display: initial !important;
padding: 0.05px;
margin: 1em auto !important;
}
.card {
width: 300px;
margin: 1em auto 0.5em;
}
}
#media(max-width: 550px) {
#video {
width: 90vw !important;
height: 50.625vw !important;
}
}
#email {
display: block;
margin: 1em auto 1em auto;
border-radius: 3px;
border: 2px solid black;
padding: 0.3em 7px 0.3em 7px;
color: #1b2b34;
min-width: 15em;
}
#submit {
display: block;
margin: auto auto 1em auto;
background-color: #5fce6a;
border: none;
/*1px solid grey;*/
padding: 0.5em 1em;
font-size: 1em;
}
#features-1 {
width: 50%;
margin: 3em auto 2em;
}
.flex {
display: flex;
flex-direction: row;
}
#features-1 .ico {
display: flex;
height: 100px;
width: 90px;
justify-content: center;
align-items: center;
color: orangered;
}
#features-1 .content {
display: flex;
flex-direction: column;
justify-content: center;
height: 100px;
width: 75vw;
padding-left: 30px;
padding-right: 10px;
}
#features-2 {
margin: auto;
display: flex;
flex-direction: column;
}
#features-2 ul {
list-style-type: none;
line-height: 2em;
margin: auto;
}
#features-2 .feature-title {
font-size: 1.2em;
margin: 1% auto;
}
#features ul li:before {
content: '\2713';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
#demo {
margin: 2em auto 3em;
padding-top: 75px;
}
#video-title {
text-align: center;
padding: 1em;
font-family: 'ubuntu', sans-serif;
}
#video {
display: block;
width: 729px;
height: 410px;
margin: auto;
}
#pricing-content {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 1.3em;
width: 95%;
margin: 2em auto;
}
.card {
border: 2px solid black;
text-align: center;
}
.card h3 {
background-color: #BDBBBB;
padding: 0.5em 1em;
}
.card h2 {
font-weight: bold;
line-height: 2em;
}
.card ul {
line-height: 2em;
font-family: 'ubuntu';
}
.card button {
padding: 0.5em 2.3em;
margin: 1em auto;
background-color: orangered;
border: none;
font-family: 'ubuntu';
font-weight: bold;
}
.true:before {
content: '\2713';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
.false:before {
content: '\2717';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
footer div {
background-color: #BDBBBB;
font-family: 'ubuntu';
padding: 0.05px;
}
footer ul {
padding-top: 1.3em;
padding-bottom: 0.5em;
}
footer li {
display: inline;
padding-left: 1em;
padding-right: 1em;
}
.footer-content p {
margin-top: 0px !important;
font-size: 13px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CodePen - Product page</title>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css'>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<!-- partial:index.partial.html -->
<header id="header">
<div id="logoNtitle">
<img src="https://www.freepnglogos.com/uploads/eagles-png-logo/eagle-sports-png-logos--0.png" alt="product logo" id="header-img" class="inline">
<span id="header-text">The Lorem Ipsum</span>
</div>
<nav id="nav-bar">
<div id="links">
<span>Features</span>
<span>Demo</span>
<span>Pricing</span>
<span>Contact Us!</span>
</div>
</nav>
</header>
<div id="main">
<p class="text-center ubuntu pclass"> Provide your email for more information about product </p>
<form id="form" action="https://www.freecodecamp.com/email-submit">
<label for="email">
<input type="email" id="email" name="email" placeholder="Enter your email address">
</label>
<input type="submit" value="Submit" id="submit">
</form>
<div id="features" class="ubuntu">
<div id="features-1">
<div class="flex">
<div class="ico"><i class="fas fa-air-freshener fa-2x"></i></div>
<div class="content">
<h3>Premium quality material</h3>
<span>Lorem ipsum dolor sit amat, consecite adispicing elit, ipsum dolor sit amat, consecite adispicing elit</span>
</div>
</div>
<div class="flex">
<div class="ico"><i class="fas fa-shipping-fast fa-2x"></i></div>
<div class="content">
<h3>Fast shipping</h3>
<span>Lorem ipsum amat, dolorem ipsum</span>
</div>
</div>
<div class="flex">
<div class="ico"><i class="fas fa-user-clock fa-2x"></i></div>
<div class="content">
<h3>Timely maintenance updates</h3>
<span>Lorem ipsum dolor sit amat, consecite adispicing elit</span>
</div>
</div>
</div>
<div id="features-2">
<p class="bold feature-title">Why to choose us ?</p>
<ul>
<!-- use css list-style-type: none; to remove bullets
use list-style-image: url(img.png) to use an image as bullet -->
<li>Lorem ipsum dolor</li>
<li>sit amet, consectetur adipiscing elit</li>
<li>Nunc tempor</li>
<li>dolorem ipsum quia</li>
<li>Lorem ipsum dolor</li>
<li>sit amet, consectetur adipiscing elit</li>
<li>Nunc tempor</li>
<li>dolorem ipsum quia</li>
</ul>
</div>
</div>
<div id="demo">
<h2 id="video-title">Here is how it works !!!</h2>
<div class="video-container">
<iframe width="729" height="410" id="video" src="https://www.youtube.com/embed/CmzKQ3PSrow" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
<div id="pricing">
<div id="pricing-content">
<div class="card">
<h3>Basic Package</h3>
<h2>$500</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="false">Dolor sit, amat</li>
<li class="false">Nunc tempor</li>
<li class="false">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
<div class="card">
<h3>Premium Package</h3>
<h2>$600</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="true">Dolor sit, amat</li>
<li class="false">Nunc tempor</li>
<li class="false">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
<div class="card">
<h3>Pro Package</h3>
<h2>$800</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="true">Dolor sit, amat</li>
<li class="true">Nunc tempor</li>
<li class="true">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
</div>
</div>
<footer id="contact">
<div class="footer-content">
<ul class="no-bullets">
<li>Privacy</li>
<li>Terms</li>
<li>Contact</li>
</ul>
<p>©The Lorem Ipsum</p>
</div>
</footer>
</div>
<script src='https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js'></script>
</body>
</html>
1. Anchors behind fixed nav
To prevent the anchors starting at the top of the page and therefore being hidden behind your fixed nav, you can add padding to them so that the padding is hidden under the nav instead. Of course this means that you will also have a bigger space in the page itself that you may not want.
To counteract that, you can add a negative value for the margin to pull the top of the element back up.
#features, #demo, #pricing, #contact {
margin-top: -100px;
padding-top: 100px;
}
2. Use of !important in all media queries
The reason you found that you had to use !important in your media queries is because you have included the media queries before the default CSS for those elements -this means that the rules in your media queries are being overridden by the CSS underneath them. Just move your media queries to the end and you can remove the !importants.
Working Example:
See example below with both of these changes made:
#import url('https://fonts.googleapis.com/css2?family=Oswald&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Ubuntu&display=swap');
* {margin: 0; padding: 0;}
body{ font-family: 'oswald', sans-serif}
.text-center { text-align: center; }
.text-left { text-align: center; }
.block { display: block; }
.inline { display: inline; }
.bold { font-weight: bold; }
.no-decor-link {
text-decoration: none;
color: black;
}
.no-bullets { list-style-type: none; }
.orangered { color: orangered; }
.ubuntu { font-family: 'Ubuntu', sans-serif }
.oswald { font-family: 'Oswald', sans-serif }
#header {
background-color: #FFDEAD;
position: sticky;
top: 0;
z-index: 2;
}
#logoNtitle {
display: inline-block;
}
#header-img {
width: 80px;
height: auto;
margin: 1em auto 0.7em 10vw;
}
#header-text{
position: relative;
top: -14px;
font-size: 2em;
margin-left: 0.8em;
}
#nav-bar {
float: right;
position: relative;
top: 2.3em;
right: 2em;
font-family: 'Ubuntu', sans-serif;
}
#nav-bar a{
padding: 1em 0.5em 1em 0.5em;
}
#main {
width: 1020px;
margin: auto;
background-color: #e6e6e6;
padding: 0.05px; /* to avoid margin collapsing */
}
#main p {
margin: 1em;
}
#email {
display: block;
margin: 1em auto 1em auto;
border-radius: 3px;
border: 2px solid black;
padding: 0.3em 7px 0.3em 7px;
color: #1b2b34;
min-width: 15em;
}
#submit {
display: block;
margin: auto auto 1em auto;
background-color: #5fce6a;
border: none;/*1px solid grey;*/
padding: 0.5em 1em;
font-size: 1em;
}
#features-1{
width: 50%;
margin: 3em auto 2em;
}
.flex {
display: flex;
flex-direction: row;
}
#features-1 .ico {
display: flex;
height: 100px;
width: 90px;
justify-content: center;
align-items: center;
color: orangered;
}
#features-1 .content {
display: flex;
flex-direction: column;
justify-content: center;
height: 100px;
width: 75vw;
padding-left: 30px;
padding-right: 10px;
}
#features-2 {
margin: auto;
display: flex;
flex-direction: column;
}
#features-2 ul {
list-style-type: none;
line-height: 2em;
margin: auto;
}
#features-2 .feature-title {
font-size: 1.2em;
margin: 1% auto;
}
#features ul li:before {
content: '\2713';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
#demo {
margin: 2em auto 2em;
}
#video-title {
text-align: center;
padding: 1em;
font-family: 'ubuntu', sans-serif;
}
#video {
display: block;
width: 729px;
height: 410px;
margin: auto;
}
#pricing-content {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 1.3em;
width: 95%;
margin: 2em auto;
}
.card {
border: 2px solid black;
text-align: center;
}
.card h3 {
background-color: #BDBBBB;
padding: 0.5em 1em;
}
.card h2 {
font-weight: bold;
line-height: 2em;
}
.card ul {
line-height: 2em;
font-family: 'ubuntu';
}
.card button {
padding: 0.5em 2.3em;
margin: 1em auto;
background-color: orangered;
border: none;
font-family: 'ubuntu';
font-weight: bold;
}
.true:before {
content: '\2713';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
.false:before {
content: '\2717';
display: inline-block;
position: relative;
right: 6px;
font-weight: bold;
}
footer div {
background-color: #BDBBBB;
font-family: 'ubuntu';
padding: 0.05px;
}
footer ul {
padding-top: 1.3em;
padding-bottom: 0.5em;
}
footer li {
display: inline;
padding-left: 1em;
padding-right: 1em;
}
.footer-content p {
margin-top: 0px;
font-size: 13px;
}
#media(max-width: 1020px) {
#main { width: 800px; }
#video {
width: 500px;
height: 281.25px;
}
#demo {
margin: 1em auto 3em;
}
}
#media(max-width: 800px) {
#main { width: 100%; }
#features-1 .ico { display: none; }
#features-1 { width: 80%; }
#nav-bar {
float: none;
position: initial;
text-align: center;
padding-bottom: 1em;
}
#logoNtitle {
display: block;
width: 320px;
margin: auto;
}
#header-img {
margin-left: auto;
}
#demo {
margin-top: 1em;
margin-bottom: 1em;
}
#pricing { margin-bottom: 1.2em; }
#pricing-content {
display: initial;
padding: 0.05px;
margin: 1em auto;
}
.card {
width: 300px;
margin: 1em auto 0.5em;
}
}
#media(max-width: 550px) {
#video {
width: 90vw;
height: 50.625vw;
}
}
#features,
#demo,
#pricing,
#contact{ margin-top:-100px; padding-top:100px;}
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css'><link rel="stylesheet" href="./style.css">
<header id="header">
<div id="logoNtitle">
<img src="https://www.freepnglogos.com/uploads/eagles-png-logo/eagle-sports-png-logos--0.png" alt="product logo" id="header-img" class="inline">
<span id="header-text">The Lorem Ipsum</span>
</div>
<nav id="nav-bar">
<div id="links">
<span>Features</span>
<span>Demo</span>
<span>Pricing</span>
<span>Contact Us!</span>
</div>
</nav>
</header>
<div id="main">
<p class="text-center ubuntu pclass"> Provide your email for more information about product </p>
<form id="form" action="https://www.freecodecamp.com/email-submit">
<label for="email">
<input type="email" id="email" name="email" placeholder="Enter your email address">
</label>
<input type="submit" value="Submit" id="submit">
</form>
<div id="features" class="ubuntu">
<div id="features-1">
<div class="flex">
<div class="ico"><i class="fas fa-air-freshener fa-2x"></i></div>
<div class="content">
<h3>Premium quality material</h3>
<span>Lorem ipsum dolor sit amat, consecite adispicing elit, ipsum dolor sit amat, consecite adispicing elit</span>
</div>
</div>
<div class="flex">
<div class="ico"><i class="fas fa-shipping-fast fa-2x"></i></div>
<div class="content">
<h3>Fast shipping</h3>
<span>Lorem ipsum amat, dolorem ipsum</span>
</div>
</div>
<div class="flex">
<div class="ico"><i class="fas fa-user-clock fa-2x"></i></div>
<div class="content">
<h3>Timely maintenance updates</h3>
<span>Lorem ipsum dolor sit amat, consecite adispicing elit</span>
</div>
</div>
</div>
<div id="features-2">
<p class="bold feature-title">Why to choose us ?</p>
<ul> <!-- use css list-style-type: none; to remove bullets
use list-style-image: url(img.png) to use an image as bullet -->
<li>Lorem ipsum dolor</li>
<li>sit amet, consectetur adipiscing elit</li>
<li>Nunc tempor</li>
<li>dolorem ipsum quia</li>
<li>Lorem ipsum dolor</li>
<li>sit amet, consectetur adipiscing elit</li>
<li>Nunc tempor</li>
<li>dolorem ipsum quia</li>
</ul>
</div>
</div>
<div id="demo">
<h2 id="video-title">Here is how it works !!!</h2>
<div class="video-container">
<iframe width="729" height="410" id="video" src="https://www.youtube.com/embed/CmzKQ3PSrow" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</div>
<div id="pricing">
<div id="pricing-content">
<div class="card">
<h3>Basic Package</h3>
<h2>$500</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="false">Dolor sit, amat</li>
<li class="false">Nunc tempor</li>
<li class="false">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
<div class="card">
<h3>Premium Package</h3>
<h2>$600</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="true">Dolor sit, amat</li>
<li class="false">Nunc tempor</li>
<li class="false">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
<div class="card">
<h3>Pro Package</h3>
<h2>$800</h2>
<ul class="no-bullets">
<li class="true">Lorem ipsum</li>
<li class="true">Dolor sit, amat</li>
<li class="true">Nunc tempor</li>
<li class="true">dolorem ipsum quia</li>
</ul>
<button type="button">Select</button>
</div>
</div>
</div>
<footer id="contact">
<div class="footer-content">
<ul class="no-bullets">
<li>Privacy</li>
<li>Terms</li>
<li>Contact</li>
</ul>
<p>©The Lorem Ipsum</p>
</div>
</footer>
</div>
I am having trouble getting my code to look like the one provided by the link.
http://prntscr.com/pqrax8 If anyone could help me to do that, that would be greatly appreciated and helpful. Thank you in advance. Thank you in advance.
.testimonials {
font-family: 'Roboto Slab', serif;
max-width: 250px;
border-radius: 40px;
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
padding: 20px;
margin: 20px 0 0 0;
position: relative;
top: 20em;
left: 100px;
background-color: #fff;
}
.ellipse {
position: static;
max-width: 4em;
vertical-align: middle;
padding-right: 1em;
}
.test {
padding-right: 1em;
vertical-align: middle;
line-height: 20px;
text-align: right;
}
h2 {
color: #60AF64;
text-align: right;
}
<body>
<div class="greensidebox">
<div class="testimonials">
<h2>Judith Cooper</h2>
<img class="ellipse" src="images/Ellipse.png" alt="testimonialpic1">
<div class="test">Lorem ipsum dolor sit amet.Sagittis convallis ligula metus.</div>
</div>
<div class="testimonials">
<h2>Julie Howard</h2>
<img class="ellipse" src="images/Ellipse-1.png" alt="testimonialpic1">
<div class="test">Lorem ipsum dolor sit amet. Sagittis convallis ligula metus.</div>
</div>
<div class="testimonials">
<h2>Kevin Adams</h2>
<img class="ellipse" src="images/Ellipse-2.png" alt="testimonialpic1">
<div>Lorem ipsum dolor sit amet. Sagittis convallis ligula metus.</div>
</div>
</div>
</body>
Flexbox...I put that shhh on everything.
* {
padding: 0;
margin: 0;
line-height: 1;
}
.wrapper {
background-color: lime;
padding: 1rem;
width: 320px;
}
.box {
display: flex;
background-color: #FFF;
border-radius: 32px;
padding: 1.5rem 0.5rem;
margin: 1.5rem 0;
box-shadow: 0 8px 4px rgba(0, 0, 0, 0.2)
}
.box img {
border-radius: 50%;
margin-right: 1rem;
}
.box strong {
font-size: 1.25rem;
display: block;
margin-bottom: 0.25rem;
}
<div class="wrapper">
<div class="box">
<img src="https://via.placeholder.com/80">
<div>
<strong>Judas Priest</strong>
<p>I'm made of metal my circuits gleam I am perpetual I keep the country clean</p>
</div>
</div>
<div class="box">
<img src="https://via.placeholder.com/80">
<div>
<strong>Judas Priest</strong>
<p>I'm made of metal my circuits gleam I am perpetual I keep the country clean</p>
</div>
</div>
<div class="box">
<img src="https://via.placeholder.com/80">
<div>
<strong>Judas Priest</strong>
<p>I'm made of metal my circuits gleam I am perpetual I keep the country clean</p>
</div>
</div>
</div>