I am trying to implement a contact us page. the heading here takes only the intended space but the div takes up extra vertical space. Where did I go wrong?
section {
display: flex;
flex-wrap: wrap;
width: 99vw;
height: 96vh;
padding-top: 4vh;
}
#heading {
width: 100%;
line-height: 0.7em;
}
h1 {
display: inline;
height: 100%;
font-size: 1rem;
}
<section>
<div id="heading">
<h1>Contact Us</h1>
</div>
<div id="media_container">
<img class="soc_med" src="fb.png" alt="fb">
<img class="soc_med" src="instagram.png" alt="insta">
<img class="soc_med" src="linkedin.png" alt="LinkedIn">
<img class="soc_med" src="email.png" alt="email">
</div>
</section>
Just remove the height from the section
section{
display: flex;
flex-wrap: wrap;
width: 99vw;
padding-top: 4vh;
}
#heading{
width: 100%;
line-height: 0.7em;
}
h1{
display: inline;
height: 100%;
font-size: 1rem;
}
<section>
<div id = "heading">
<h1>Contact Us</h1>
</div>
<div id = "media_container">
<img class="soc_med" src="fb.png" alt="fb">
<img class="soc_med" src="instagram.png" alt="insta">
<img class="soc_med" src="linkedin.png" alt="LinkedIn">
<img class="soc_med" src="email.png" alt="email">
</div>
</section>
Just add margin: 0; to html, body to avoid the default margins on these elements which are the cause for your problem:
html,
body {
margin: 0;
}
section {
display: flex;
flex-wrap: wrap;
width: 99vw;
height: 96vh;
padding-top: 4vh;
}
#heading {
width: 100%;
line-height: 0.7em;
}
h1 {
display: inline;
height: 100%;
font-size: 1rem;
}
<section>
<div id="heading">
<h1>Contact Us</h1>
</div>
<div id="media_container">
<img class="soc_med" src="fb.png" alt="fb">
<img class="soc_med" src="instagram.png" alt="insta">
<img class="soc_med" src="linkedin.png" alt="LinkedIn">
<img class="soc_med" src="email.png" alt="email">
</div>
</section>
Related
Im new to code,
I gave the image element(the bee), position: absolute and bottom: 0px, in order to make the element stick to the bottom of the body i.e. the bottom of the page. However, if I dont give the body position: relative, it doesnt work! Based on what I learnt, if there is no any parent that has position that is not static it automatically set itself in relation to the body, so it doesnt work in that case?
HTML
<body>
<img src="https://media.npr.org/assets/img/2018/06/07/gettyimages-200415242-001_slide-d26f3af782b697f15ceebe2f7c380c0e545dd47b.jpg" alt="" class="test-bee">
<div class="container">
<div class="main">
<div class="info">
<h1>10,000+ of our users love our products.</h1>
<p>We only provide great products combined with excellent customer service.
See what our satisfied customers are saying about our services.</p>
</div>
<div class="rates">
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in Reviews</p>
</div>
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in Report Guru</p>
</div>
<div class="rate-container">
<div class="star-container">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
<img src="./images/icon-star.svg" alt="">
</div>
<p class="review">Rated 5 Stars in BestTech</p>
</div>
</div>
</div>
<section class="testemonies">
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-colton.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">colton smith </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">"We needed the same printed design as the one we had ordered a week prior.
Not only did they find the original order, but we also received it in time.
Excellent!"</p>
</div>
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-irene.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">irene roberts </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">
"Customer service is always excellent and very quick turn around. Completely
delighted with the simplicity of the purchase and the speed of delivery."</p>
</div>
<div class="testemony-card">
<div class="user-info">
<div class="img-container">
<img src="./images/image-anne.jpg" alt="">
</div>
<div class="user-name-status">
<p class="user-name">anne wallace </p>
<p class="status"><span>verified buyer</span></p>
</div>
</div>
<p class="testimony">
"Put an order with this company and can only praise them for the very high
standard. Will definitely use them again and recommend them to everyone!"</p>
</div>
</section>
</div>
</body>
CSS
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
:root {
--Very-Dark-Magenta: hsl(300, 43%, 22%);
--Soft-Pink: hsl(333, 80%, 67%);
--Dark-Grayish-Magenta: hsl(303, 10%, 53%);
--Light-Grayish-Magenta: hsl(300, 24%, 96%);
--White: hsl(0, 0%, 100%);
}
body {
width: 100%;
min-height: 100vh;
font-family: 'League Spartan', sans-serif;
font-size: 15px;
display: flex;
align-items: center;
justify-content: center;
/* border: 5px solid red; */
padding: 1em;
position: relative; /*why do i need this relative? the bottom image should stick to the bottom by default cause the body is the first one that had position relative, but without it it doesnt stick*/
}
.pattern {
display: none;
}
.test-bee {
width: 200px;
position: absolute;
bottom: 0px;
}
.bottom-mobile, .top-mobile {
display: block;
position: absolute;
}
.top-mobile {
top:0px;
}
.bottom-mobile {
bottom: 0px;
}
.container {
height: 100%;
/* border: 5px solid green; */
margin: 3em 0px;
}
.main {
text-align: center;
margin-bottom: 3em;
}
.info h1 {
margin: 0px auto;
line-height: 0.8em;
margin-bottom: 1em;
margin: 1em 2em;
color: var(--Very-Dark-Magenta)
}
.info {
line-height: 1.3em;
margin-bottom: 2.5em;
}
.rate-container {
background-color: var(--Light-Grayish-Magenta);
padding: 1em 2em;
margin-bottom: 1em;
border-radius: 0.4em;
display: flex;
flex-direction: column;
gap: 0.5em;
color: var(--Very-Dark-Magenta);
font-weight: bold;
}
.testemonies {
display: flex;
flex-direction: column;
gap: 1em;
}
.testemony-card {
background-color: var(--Very-Dark-Magenta);
border-radius: 0.4em;
color: white;
padding: 2em;
line-height: 1.2em;
}
.img-container {
width: 30px;
height: 30px;
border-radius: 50px;
overflow: hidden;
}
.img-container img {
height: 100%;
width: 100%;
}
.user-info {
display: flex;
align-items: center;
gap: 1em;
text-transform: capitalize;
margin-bottom: 1em;
}
.user-name-status p span{
color:var(--Soft-Pink)
}
I fix it by adding the body position: relative, but it should go like that
I'm learning CSS and I have a problem with CSS flexbox and grid.
I wanted to make a grid as shown above but I couldn't. The first and last containers are in different sizes and the others are the same.
Here is my code:
.second-section {
width: 80%;
margin: 10px auto;
display: flex;
flex-direction: row;
position: relative;
flex-wrap: wrap;
}
.category-devider {
width: 80%;
margin: 0 auto;
}
.category-devider p {
font-size: 16px;
}
.category-devider span {
font-size: 18px;
color: #757575;
}
.image-containers {
position: relative;
width: 45%;
margin: 50px auto;
height: 434px;
background-color: #494949;
display: block;
text-align: center;
}
.image-containers h3 {
font-size: 18px;
}
.second-section #img-container img {
height: 100%;
width: 100%;
object-fit: cover;
}
.img1 img {
height: 612px;
}
<div class="second-section">
<div class="image-containers img1">
<img src="/img/apple-watch.jpg" alt="Apple Watch" />
<h3>Rule ratio</h3>
<p>Product design</p>
</div>
<div class="image-containers img2">
<img src="/img/circle.jpg" alt="Situation" />
<h3>Situation</h3>
<p>Visual identity</p>
</div>
<div class="image-containers img3">
<img src="/img/cards.jpg" alt="Cards" />
<h3>Dry air</h3>
<p>User research</p>
</div>
<div class="image-containers img4">
<img src="/img/orange-phone.jpeg" alt="Phone" />
<h3>Vertical</h3>
<p>Product design</p>
</div>
<div class="image-containers img5">
<img src="/img/phone.jpg" alt="Phone" />
<h3>Variable compose</h3>
<p>Product design</p>
</div>
<div class="image-containers img6">
<img src="/img/phone1.jpg" alt="Phone" />
<h3>Scope shift</h3>
<p>Product design</p>
</div>
</div>
You can make array of objects:
{
name: 'name',
title: 'title',
text: 'text'
}
and write:
<div class="second-section">
{array.map((picture, index) => {
<div class={`image-containers img${index}`}>
<img src={`/img/${name}.jpg`} alt="Phone" />
<h3>{picture.title}</h3>
<p>{picture.text}</p>
</div>
})}
</div>
I want to be able to scroll vertically in the .contacts-wrapper area, but the scroll bar doesn't show up. I tried different solutions to the problem, but nothing worked out. Can someone please help me?
HTML:
<div class="right-side">
<div class="sponsorship">
<p class="sponsored">Спонсорирано</p>
<div class="sponsor">
<img src="../imgs/coke.jpg" alt="">
<div class="info">
<p class="main">Купи Кока Кола в Маркет Церовище (евтинко)</p>
coca-cola.com
</div>
</div>
<div class="sponsor">
<img src="../imgs/audi.jpg" alt="">
<div class="info">
<p class="main">Новото Ауди на изгодна цена (чипосано, да са знай)</p>
audi.com
</div>
</div>
</div>
<div class="contacts-wrapper">
<div class="tools-wrapper">
<p>Контакти</p>
<div class="tools">
<i class="fas fa-video"></i>
<i class="fas fa-search"></i>
<i class="fas fa-ellipsis-h"></i>
</div>
</div>
<div class="contacts">
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
<div class="person">
<img src="../imgs/guy1.jpg" alt="">
<p>Aishe Buzgova</p>
</div>
</div>
</div>
</div>
CSS:
.right-side {
position: fixed;
right: 0;
top: 10vh;
z-index: 1;
height: 90vh;
width: 20%;
background-color: #f0f2f5;
}
.sponsor {
height: 20vh;
padding: 1em;
display: flex;
align-items: center;
border-radius: 10px;
cursor: pointer;
}
.sponsor:hover {
background-color: #d8dadf;
}
.sponsor img {
width: 50%;
height: 100%;
object-fit: cover;
object-position: center;
border-radius: 10px;
}
.info {
width: 50%;
padding: 1em;
}
.main {
font-size: 1.2rem;
font-weight: 600;
margin: 0 0 10px;
}
.website {
text-decoration: none;
font-size: 1.2rem;
color: #7c7f82;
}
.sponsored {
font-size: 1.8rem;
margin: 1em 0 1em 1em;
color: #75767b;
font-weight: 600;
}
.contacts-wrapper {
width: 100%;
}
.tools-wrapper {
display: flex;
justify-content: space-between;
padding: 1.5em 1em;
border-top: 1px solid #ced0d4;
}
.tools-wrapper p {
font-size: 1.6rem;
color: #65676b;
font-weight: 600;
}
.tools {
width: 30%;
display: flex;
justify-content: space-between;
}
.tools i {
font-size: 1.6rem;
color: #606770;
}
.contacts {
width: 100%;
}
.person {
padding: 0.5em 1em;
width: 100%;
display: flex;
align-items: center;
}
.person img {
height: 5vh;
width: 5vh;
object-fit: cover;
object-position: center;
border-radius: 50%;
margin: 0 10px 0 0;
}
.person p {
font-size: 1.4rem;
}
Just swap these classes in. I think this is what you want
.right-side {
position: absolute;
right: 0;
top: 10vh;
z-index: 1;
height: 90vh;
width: 20%;
background-color: #f0f2f5;
overflow: hidden; // <-- remove this if you want the full sidebar to be scrollable
}
.contacts-wrapper {
width: 100%;
height: 100%;
overflow: auto;
}
Whenever I'm trying to change .tea to display: block; all the images change their position from being horizontal, to being vertical
How to position it the correct way so the images keep being horizontally aligned and the text will be underneath
.tea {
display: inline-flex;
margin-left: 225px;
padding: 20px;
justify-content: center;
}
.tea h4 {
display: inline-block;
position: relative;
text-align: center;
}
.tea2 {
display: inline-flex;
margin-left: 385px;
}
.tea img {
width: 300px;
height: 200px;
padding: 25px;
border-radius: 15px;
}
.tea2 img {
width: 300px;
height: 200px;
padding: 30px;
}
<div class="tea">
<img class="1" src="https://via.placeholder.com/150">
<h4>Myrtle Ave</h4>
<img class="2" src="https://via.placeholder.com/150">
<h4>Spiced rum</h4>
<img class="3" src="https://via.placeholder.com/150">
<h4>Berry Blitz</h4>
</div>
<div class="tea2">
<img class="1" src="https://via.placeholder.com/150">
<img class="2" src="https://via.placeholder.com/150">
</div>
You should do it like this
* {
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
}
#gallery {
display: flex;
flex-wrap: wrap;
}
#gallery .image-container {
width: 25%;
background-color: lightgreen;
border-radius: 5px;
padding: 5px;
box-shadow: 1px 1px 2px #000, -1px -1px 2px #000;
}
#gallery img {
width: 100%;
}
#gallery .title {
font: bold 24px monospace;
text-align: center;
color: white;
margin: 2%;
}
<div id="gallery">
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 1</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 2</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 3</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 4</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 5</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 6</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 7</p>
</div>
<div class="image-container">
<img src="https://openclipart.org/image/800px/svg_to_png/321159/hotwork-sign-arvin61r58.png">
<p class="title">Image 8</p>
</div>
</div>
You need to change you HTML to support what you want. Use a container wrapper around the image and image text.
Example: https://jsfiddle.net/Lqupmf5s/
<div class="tea">
<div class="img-container">
<img class="1" src="32131">
<h4>Myrtle Ave</h4>
</div>
<div class="img-container">
<img class="2" src="3213">
<h4>Spiced rum</h4>
</div>
<div class="img-container">
<img class="3" src="3213">
<h4>Berry Blitz</h4>
</div>
</div>
.tea {
display: inline-flex;
/* margin-left: 225px; */
padding: 20px;
justify-content: center; }
.tea h4{
display: inline-block;
position: relative;
text-align: center; }
.tea2 {
display: inline-flex;
margin-left: 385px; }
.tea img {
width: 300px;
height: 200px;
/* padding: 25px; */
border-radius: 15px; }
.tea2 img {
width: 300px;
height: 200px;
padding: 30px; }
There is a white space before the image in the second row. I don’t know why this is happening.
Margin and padding are fine.
All images are of the same size, but there is white space on the second row before the image. 2 more images can fit in there.
Upon inspecting it's just showing white space from the body.
No excess margin or padding is there from any of the images.
Used – "float: left;"
The images on the third row and further are fine.
Can someone figure out the issue, why is this happening?
Click to see image
HTML File:
<!DOCTYPE html>
<html>
<head>
<title>Photo Gallery</title>
<link rel="stylesheet" type="text/css" href="gallery.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,800&display=swap" rel="stylesheet">
</head>
<body>
<p>Photo Gallery</p>
<img src="a (1).jpg">
<img src="a (2).jpg">
<img src="a (3).jpg">
<img src="a (4).jpg">
<img src="a (5).jpg">
<img src="a (6).jpg">
<img src="a (7).jpg">
<img src="a (8).jpg">
<img src="a (9).jpg">
</body>
</html>
CSS File:
img{
width: 30%;
float: left;
margin: 1.66%;
padding: 0;
}
p{
font-family: Raleway;
margin-left: 1.66%;
font-size: 30px;
font-weight: 800;
border-bottom: 3px solid #f1f1f1;
width:30%;
padding-bottom: 30px;
}
This is happening because the images are of different height. The best solution with display block layout will be using a width to the image and setting the display: inline-block
img{
width: 30%;
/* margin: 1.66%; */
padding: 0;
display: inline-block;
vertical-align: middle;
}
p{
font-family: Raleway;
margin-left: 1.66%;
font-size: 30px;
font-weight: 800;
border-bottom: 3px solid #f1f1f1;
width:30%;
padding-bottom: 30px;
}
<p>Photo Gallery</p>
<div class="image-container">
<img src="https://www.w3schools.com/html/img_girl.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
</div
Or else you can go for flex display. This will ensure that the child elemets are of same height, without explicitly mentioning the height.
.image-item {
display: flex;
flex-direction: column;
width: 30%;
margin: 1.66%;
padding: 0;
justify-content: center;
}
img{
width: 100%;
}
.image-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
p {
font-family: Raleway;
margin-left: 1.66%;
font-size: 30px;
font-weight: 800;
border-bottom: 3px solid #f1f1f1;
width: 30%;
padding-bottom: 30px;
}
<p>Photo Gallery</p>
<div class="image-container">
<div class="image-item">
<img src="https://www.w3schools.com/html/img_girl.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
</div>
It's the margin property.
img{
width: 30%;
float: left;
margin: 0 1.66%;
padding: 0;
}
p{
font-family: Raleway;
margin-left: 1.66%;
font-size: 30px;
font-weight: 800;
border-bottom: 3px solid #f1f1f1;
width:30%;
padding-bottom: 30px;
}
<p>Photo Gallery</p>
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">