Im unable to use position relative - html

Expected result - the third blue box should be a little towards the right
i am unable to use left functon after doing position relative in the userated div . im trying to say that instead of moving right, it is just increasing in size . Below is a picture to help you understand what i am saying . after that i wrote all the html and css code.
Code Snippet:
* {
margin: 0px;
padding: 0px;
}
ul.navlist {
list-style: none;
display: flex;
padding: 0px;
margin: 0px auto;
width: 100%;
top: 30px;
align-items: center
}
.bar {
height: 100px;
width: 100%;
justify-content: left;
box-shadow: 0px 2px 5px;
display: grid;
grid-template-columns: 100px auto 80px;
}
.link1 {
margin-left: 30px;
text-decoration: none;
color: black;
font-size: 20px
}
.signin {
background: linear-gradient(to right, blue, rgb(20, 196, 255));
height: 38px;
width: 120px;
position: relative;
text-align: center;
font-size: 18px;
border-radius: 20%;
;
left: 200px;
top: -10px
}
.sign {
top: 15%;
position: relative;
color: white;
text-decoration: none
}
.introbox {
width: 700px;
height: 200px;
background-image: url('wal.jpg');
opacity: 0.75;
left: 25%;
position: relative;
background-position: center;
top: 10px;
border-radius: 5px;
font-weight: 600;
box-shadow: 0px 2px 5px;
}
.new {
font-size: 30px;
left: 6%;
position: relative;
font-weight: 400
}
.box1 {
height: 250px;
width: 200px;
background: green;
position: relative;
top: 2%;
display: grid;
font-size: 20px;
font-weight: 600
}
.box2 {
height: 250px;
width: 200px;
background: green;
position: relative;
top: 1%;
display: grid;
font-size: 20px;
font-weight: 600;
}
.lnlink {
text-decoration: none;
color: black;
}
.lightnovel1 {
display: flex;
flex-direction: row;
position: relative;
height: 580px;
width: 900px;
background: red;
left: 5%;
}
.ww {
margin: 20px;
height: 260px;
width: 180px;
font-size: 20px;
font-weight: 600
}
.pic2 {
height: 80%;
width: 100%
}
.ranki {
font-size: 15px
}
.ranktitle {
position: relative;
left: 5%;
font-size: 30px;
font-weight: 400
}
.ranking {
height: 580px;
width: 900px;
background: yellow;
display: flex;
flex-direction: row;
position: relative;
left: 5%;
}
.topview {
display: flex;
flex-direction: column;
height: 400px;
width: 200px;
background: blue;
}
.li {
float: left;
}
.newtrends {
display: flex;
flex-direction: column;
height: 400px;
width: 250px;
background: blue;
position: relative;
left: 5%
}
.userrated {
display: flex;
flex-direction: column;
height: 400px;
width: 250px;
background: blue;
position: relative;
left: -5%
}
<div class="bar">
<! me might not come for 2 month here or disc>
<nav>
<ul class="navlist">
<li><img src="background.png"></li>
<li>Search</li>
<li>Browse</li>
<li>Tags</li>
<li>Filter</li>
<li>Dev</li>
<li>
<div class="signin"><a href="#" class='sign'>Sign In</a></div>
</li>
</ul>
</nav>
</div>
<div class="introbox">
<h1>Read Light Novel & Web Novel Translations Online For FREE!</h1>
<p2>Your fictional stories hub</p2>
<br>
<p3>Looking for a great place to read Light Novels? Light Novel Pub is a very special platform where you can read the translated versions of world famous Japanese, Chinese and Korean light novels in English. Every new chapters published by the author is
updated instantly on the Light Novel Pub and notification service is provided to the readers.
</p3>
Start reading now to explore this mysterious fantasy world.
</div>
<br>
<br>
<div class="release">
<div class="title1">
<h3 class="new">New Ongoing Release</h3>
</div>
<div class="lightnovel1">
<div class="ww">
<img src="martialart.jpg" class="pic2">
Martial Art System
<div class="ranki">
<p2> Rank 1 </p2>
</div>
</div>
<div class="ww">
<img src="martialart.jpg" class="pic2">
Martial Art System
<div class="ranki">
<p2> Rank 1 </p2>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="ranktitle"> Ranking </div>
<div class="ranking">
<div class="misc">
<h2>Trending</h2>
<div class="topview" id="topviewid">
</div>
</div>
<div class="misc1">
<h2>most viewed</h2>
<div class="newtrends">
</div>
</div>
<div class="misc2">
<h2>User Rated</h2>
<div class="userrated">
</div>
</div>
</div>
float: right or left is causing this result

Your .userrated and .newtrends classes are both positioned in relation to their normal position. If you move the second div by 5% it overlaps with the third. If you now move the third by 5% you would moved them both by the same distance so they won't show a gap.
If you want the same gap between the second and the third div you need to set the third's left value to 10%.

Related

How to make side cart not go past footer?

I have an online shop I created. The way I did the cart function was have it display on my home,about us and online shop pages. But I have run into an issue.
The issue is that, if the cart goes to far down it over laps the footer and the footer moves up the more the cart moves down.
I think the overflow:scroll can work, but I think its also has to do with the way I did the CSS of the footer.
I have also attached the screenshot of the issue
/*Online Cart*/
.product-container {
position: absolute;
background-color: var(--dark-sienna-color);
display: grid;
z-index: 5;
width: 20%;
margin-left: 95.18rem;
display: none;
margin-top: -3rem;
overflow: scroll;
}
.cart-hide {
display: block !important;
}
.products {
color: var(--camel-color);
margin: 0 3rem;
}
.remove {
margin-top: 1rem;
}
.item-name {
display: grid;
margin-top: 1rem;
text-align: center;
}
.item-name img {
max-width: 100%;
}
.product svg {
width: 10%;
filter: invert(43%) sepia(32%) saturate(310%) hue-rotate(347deg) brightness(90%) contrast(88%);
}
.basketTotalContainer {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 8rem;
width: 100%;
padding: 10px 0;
border-top: 1px solid var(--camel-color);
margin-top: 1rem;
}
.basketTotalTitle,
.basketTotal {
font-size: 20px;
}
/*Online Cart*/
.footer {
background-color: var(--dark-sienna-color);
height: 100px;
}
.container-footer {
display: flex;
flex-direction: row;
margin-left: 30rem;
}
.collection h3,
.blog h3,
.contact h3 {
color: var(--camel-color);
text-decoration: underline;
padding-top: 0.5rem;
padding-left: 10rem;
font-size: 15px;
}
.list-group {
list-style-type: none;
text-align: justify;
color: var(--camel-color);
margin-left: 10rem;
width: 10rem;
}
.list-group li {
font-size: 10px;
}
.coll-hl {
border-left: 1px solid var(--camel-color);
height: 4rem;
position: absolute;
margin-top: 1rem;
margin-left: 27rem;
}
.blog-hl {
border-left: 1px solid var(--camel-color);
height: 4rem;
position: absolute;
margin-top: 1rem;
margin-left: 45rem;
}
<!--Cart span-->
<div class="product-container">
<div class="product-header">
<h5 class="product-title"></h5>
<h5 class="price"></h5>
<h5 class="quantity"></h5>
<h5 class="total"></h5>
</div>
<div class="products">
</div>
</div>
<!--Cart span-->
<footer>
<div class="footer">
<div class="container-footer">
<div class="collection">
<h3>COLLECTION</h3>
<ul class="list-group">
<li>SOFA'S</li>
<li>BEDS</li>
<li>BED SIDE TABLES</li>
<li>COFFEE TABLES</li>
</ul>
</div>
<div class="coll-hl"></div>
<div class="blog">
<h3>BLOG</h3>
<ul class="list-group">
<li>SUPERBLOG</li>
<li>CATABLOG</li>
</ul>
</div>
<div class="blog-hl"></div>
<div class="contact">
<h3>CONTACT US</h3>
<ul class="list-group">
<li>TEL: 021 568 7523</li>
<li>44 Harrington St, Zonnebloem, Cape Town, 8001
</li>
</ul>
</div>
</div>
</div>
</footer>
Add max-height: 100vh; to .product-container besides setting overflow-y: auto;.
Like this:
.product-container {
max-height: 100vh; /* Added */
overflow-y: auto; /* Changed */
position: absolute;
background-color: var(--dark-sienna-color);
display: grid;
z-index: 5;
width: 20%;
margin-left: 95.18rem;
display: none;
margin-top: -3rem;
}
Note: You can set max-height to whatever you want (e.g., 600px).

Flexbox alignment

I'm trying to align the Modern Art Gallery and the text using flexbox but when I do that the whole container moves left and right. Even more so I want to change the width of the h1 but I'm not sure how to do that.
Some code may be missing as I'm working on multiple devices but I only need help with the desktop version which is what's shown.
Here's what I want it to look like:
.container-content {
border: 2px solid blue;
position: relative;
display: flex;
justify-content: space-between;
gap: 2rem;
}
.container-content h1 {
font-size: 96px;
padding: 0;
}
#tablet-img {
display: none;
}
#desktop-img {
display: block;
background-color: grey;
padding-left: 450px;
}
.desktop-text-button {
border: 2px solid red;
position: absolute;
margin-left: 1%;
}
}
<div class="container-flex">
<img id="desktop-img" src="../art-gallery-website/starter-code/assets/desktop/image-hero.jpg" alt="desktop-image">
<div class="container">
<div class="container-content">
<h1>MODERN ART GALLERY</h1>
<div class="desktop-text-button">
<p>The arts in the collection of the Modern Art Gallery all started from a spark of inspiration. Will these pieces inspire you? Visit us and find out.</p>
<div class="button-1">
<button>Our Location</button>
<span class="right-arrow"></span>
</div>
</div>
</div>
</div>
</div>
Your code was messy so I just recoded it. Is this what you want?
.wrapper {
display: flex;
flex-direction: row;
width: 100%;
height: 90vh;
}
.wrapper .left {
width: 70%;
height: 100%;
background-image: url('https://wallpaperaccess.com/full/4707236.jpg');
background-size: cover;
border: 1.2px solid #000000;
}
.wrapper .left p {
font-size: 6vw;
font-weight: 700;
margin-top: 15%;
margin-left: 10%;
color: #ffffff;
}
.wrapper .left p span {
color: #000000;
}
.wrapper .right {
display: flex;
flex-direction: column;
column-gap: 2vh;
position: relative;
right: 7%;
width: 30%;
height: 40%;
margin-top: 10%;
}
.wrapper .right p {
font-size: 2vw;
}
.wrapper .right button {
font-size: 1.6vw;
width: 45%;
margin-left: auto;
margin-right: auto;
}
<div class="wrapper">
<div class="left">
<p>MODERN <br /> ART GAL<span>LERY</span></p>
</div>
<div class="right">
<p>The arts in the collection of the Modern Art Gallery all started from a spark of inspiration. Will these pieces inspire you? Visit us and find out.</p>
<button>OUR LOCATION</button>
</div>
</div>

aliginment and position issues when using display grid

I have 2 parent containers in my code below. The first one is just for reference for what I want my second container to look like. The difference between the two is the first one I used absolute positioning and flex display but the second one is grid display. What I'm stuck on is understanding how to center class .item1 and position class .item2 all the way to the right just how it's like on the first parent container i.e class .topAdCon. My specific questions are 1) how to center .item1
2) how to set .item2's position all the way to the right (right: 0%)
3) on the first parent container I just set top: 0% to align it all the way to the top because it has absolute positioning how can I set the positioning of the second parent container where ever I want currently I'm using margin-top for top positioning is that the way to go or what is the right way?
4) Lastly how do I set the height for the second container because height isn't responding as it does on the first container?
Note: I commented out things I tried in order to achieve these things but they aren't working.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.topAdCon {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0%;
width: 100%;
height: 18%;
background-color: pink;
}
.topAdCon .adCon {
width: 40%;
height: 100%;
}
.topAdCon .adCon img {
width: 100%;
height: 100%;
}
.topAdCon .sideInfo {
display: flex;
text-align: center;
width: 17%;
height: 100%;
position: absolute;
right: 0%;
border: 1.5px solid #000000;
}
.topAdCon .sideInfo p {
font-size: 0.9vw;
margin: auto;
}
.wrapper {
display: grid;
align-items: center;
justify-content: center;
/*position: relative;
top: 20%;*/
margin-top: 20%;
grid-template-columns: 40% 17%;
width: 100%;
height: 18%;
/*height not responding*/
background-color: gold;
}
.item1 {
/*align-self: center;*/
width: 100%;
height: 100%;
}
.item1 img {
width: 100%;
height: 100%;
}
.item2 {
display: flex;
text-align: center;
/*align-self: flex-end*/
width: 100%;
height: 100%;
border: 1.5px solid #000000;
}
.item2 p {
font-size: 1.5vw;
margin: auto;
}
<div class="topAdCon">
<div class="adCon">
<img src="https://images.pexels.com/photos/356830/pexels-photo-356830.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" />
</div>
<div class="sideInfo">
<p>this is test statement 1</p>
</div>
</div>
<div class="wrapper">
<div class="item1">
<img src="https://images.pexels.com/photos/356830/pexels-photo-356830.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" />
</div>
<div class="item2">
<p>this is test statement 2</p>
</div>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.topAdCon {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0%;
width: 100%;
height: 18%;
background-color: pink;
}
.topAdCon .adCon {
width: 40%;
height: 100%;
}
.topAdCon .adCon img {
width: 100%;
height: 100%;
}
.topAdCon .sideInfo {
display: flex;
text-align: center;
width: 17%;
height: 100%;
position: absolute;
right: 0%;
border: 1.5px solid #000000;
}
.topAdCon .sideInfo p {
font-size: 0.9vw;
margin: auto;
}
.wrapper {
display: grid;
margin-top: 20%;
grid-template-columns: 30% 40% 12% 18%;
grid-template-areas: 'item item1 item2 item3';
width: 100%;
height: 18vh;
background-color: gold;
}
.item1 {
width: 100%;
height: inherit;
}
.item1 img {
width: 100%;
height: 100%;
}
.item3 {
display: flex;
text-align: center;
justify-content: end;
width: 100%;
height: inherit;
border: 1.5px solid #000000;
}
.item3 p {
font-size: 1.5vw;
margin: auto;
}
<div class="topAdCon">
<div class="adCon">
<img src="https://images.pexels.com/photos/356830/pexels-photo-356830.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" />
</div>
<div class="sideInfo">
<p>this is test statement 1</p>
</div>
</div>
<div class="wrapper">
<div class="item"></div>
<div class="item1">
<img src="https://images.pexels.com/photos/356830/pexels-photo-356830.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" />
</div>
<div class="item2"></div>
<div class="item3">
<p>this is test statement 2</p>
</div>
</div>

Aligning CSS objects above <hr> tags

Here's my code for my small project (I'm very new to this):
body {
background-color: #242424;
}
.page-wrap {
width: 90%;
margin: 0 auto;
height: 98vh;
}
.buildings-wrap {
width: 95%;
margin: 0 auto;
height: 100%;
text-align: middle;
}
.rectangle {
height: 650px;
background-color: lightblue;
width: 215px;
}
.add_btn {
border-radius: 50%;
background-color: lightcyan;
text-align: center;
line-height: 150px;
height: 150px;
width: 150px;
margin: 0 auto;
font-size: 100px;
font-weight: 900;
position: fixed;
top: 85%;
}
<div class="page-wrap">
<div class="buildings-wrap">
<br/>
<div class="rectangle"></div>
<hr style="position: fixed;top: 80%;color: white;width: 84%;" />
<button class="add_btn">+</button>
</div>
</div>
Here's what it looks like. The arrow show where I would like them to be.
I can't figure out how to do this:
In order to align the rectangle above the hr tag, you can simply give it a display of block and a margin of auto. This will center the rectangle relative to the container.
As for aligning the add button to the center while keeping it fixed, you can wrap the button in a div, give that div a position of fixed and a width of 100%. Then give it a display of flex and justify-content of center. This will center align any children that are in the div.
Depending on how low you want the add button, you can set the bottom property for the newly create div. At the moment I have it at -125px. It's also better to use bottom and pixels as the units because the other elements have fixed sizes.
body{
background-color: #242424;
}
.page-wrap {
width: 90%;
margin: 0 auto;
height: 98vh;
}
.buildings-wrap{
width: 95%;
margin: 0 auto;
height: 100%;
text-align: middle;
}
.rectangle{
height: 650px;
background-color: lightblue;
width: 215px;
display: block;
margin:auto;
}
.add_btn{
border-radius: 50%;
background-color: lightcyan;
text-align: center;
line-height: 150px;
height: 150px;
width: 150px;
margin: 0 auto;
font-size: 100px;
font-weight: 900;
}
hr{
margin: 0 auto 0 auto;
}
<div class="page-wrap">
<div class="buildings-wrap">
<br/>
<div style="display: flex; margin: auto;"><div class="rectangle"></div></div>
<hr/>
<div style="width: 100%; display:flex; justify-content: center;position: fixed; bottom: -125px; left: 0;"><button class="add_btn">+</button></div>
</div>
</div>
Please view in full-page view
Hope this helps
body {
background-color: #242424;
}
.page-wrap {
width: 90%;
margin: 0 auto;
height: 98vh;
}
.buildings-wrap {
width: 95%;
margin: 0 auto;
height: 100%;
text-align: center;
display: flex;
justify-content: center;
}
.rectangle {
height: 81vh;
background-color: lightblue;
width: 200px;
}
.add_btn {
border-radius: 50%;
background-color: lightcyan;
text-align: center;
line-height: 50px;
height: 16vh;
width: 120px;
margin: 0 auto;
font-size: 100px;
font-weight: 600;
position: fixed;
top: 84%;
}
<div class="page-wrap">
<div class="buildings-wrap">
<br/>
<div class="rectangle"></div>
<hr style="position: fixed;top: 80%;color: white;width: 84%;" />
<button class="add_btn">+</button>
</div>
</div>

Trouble with making my website responsive

I am currently attempting to make my website responsive i.e. images scale up and down with page resizing, content stacks above each other, etc. I was under the impression that I had taken the appropriate steps, but the elements are still stretching in size when resizing and the contents are not staying in their original positions.
How can I achieve this result while keeping all of my elements intact?
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-image: url(img/food-background.jpg);
background-attachment: fixed;
height: 100%;
}
.main-content {
display: flex;
flex-wrap: wrap;
}
.container {
margin-left: auto;
margin-right: auto;
width: 1140px;
}
.Navbar {
text-align: center;
display: block;
margin-top: 2%;
}
#center-logo {
width: 100%;
max-width: 200px;
height: auto;
text-align: center;
}
#Navbar_Link-Toggle {
display: none;
}
img {
width: 40%;
}
.links {
text-decoration: none;
font-size: 13px;
color: black;
font-weight: bold;
padding: 25px;
}
.links:hover {
color: #f58300
}
a:visited {
color: black;
}
.header {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
margin-top: 3%;
height: auto;
background-color: yellow;
}
#food {
height: 65vh;
width: 100%
}
.footer {
margin-top: 100%;
bottom: 0;
width: 100%;
text-align: center;
font-size: 10px;
margin-left: auto;
margin-right: auto;
background-color: #f7f7f7;
}
.top {
float: left;
width: 100%;
}
#olive-green {
margin-top: 5%;
position: absolute;
right: 50px;
max-width: 450px;
}
#coral {
max-width: 450px;
position: absolute;
left: 50px;
margin-top: 5%;
}
#teal {
max-width: 450px;
position: absolute;
left: 50px;
margin-top: 50%;
}
#honey {
margin-top: 50%;
position: absolute;
right: 50px;
max-width: 450px;
}
.images {
content: "";
clear: both;
display: table;
}
#media screen and (max-width: 900px) {
.top {
width: 100%;
}
.bottom {
width: 100%;
}
}
<div class='main-content'></div>
<div id='Navbar_Link-Toggle' style='font-size: 20px'>
<i id='main' class='fas fa-bars'></i>
</div>
<div class='container'>
<div class='Navbar'>
<a class='links' href=''>FOOD</a>
<a class='links' href=''>FUN</a>
<img id='center-logo' src='img/SAMO.png'>
<a class='links' href=''>HISTORY</a>
<a class='links' href=''>LOCATION</a>
</div>
</div>
<div class='header'>
<img id='food' src='img/food.jpg'>
</div>
<div class='images'>
<div class='top'>
<img id='coral' src='img/coral.png'>
<img id='olive-green' src='img/olive-green.jpg'>
</div>
<div class='middle'>
<img id='teal' src='img/teal.jpg'>
<img id='honey' src='img/honey.jpg'>
</div>
</div>
</div>
<div class='footer'>
<p>200 Santa Monica Pier, Suite A Santa Monica, CA 90401</p><br>
<p>Questions? Drop us a message at: info#santamonicapier.org or 310-458-8900</p><br>
<p>All Rights Reserved © 2019 Santa Monica Pier</p>
</div>
You have an extra closing div on the first line of your HTML. So your .main-content element is actually being closed right away instead of wrapping around the rest of the elements.