CSS DIV web page positioning

Joshua Davis
Joshua Davis used Ask the Experts™
on
Hi Everyone,

I am currently working on a small web page challenge as a test for a junior web developer.

I am to build a basic web page (based on the attached mock up). I understand the concept, however it has been along time since i have written in CSS\HTML and last time i did it was common practice to use tables for positioning. I have since learnt that this is no longer correct and I am struggling to get 2 of my components to line up.



The section is an image gallery, which I have already got working and fully interactive, however i cannot get the main image and the sample images to line up as required.

Below is the code I have written, if anyone could help me with the positioning it would be greatly appreciated. (Also if there is anything in there that is bad practice please flag it up)

Thank you,
Josh

<!doctype html>
<html class="no-js" lang="">
    <html>
    <head>
    <link rel="stylesheet"
                href="https://fonts.googleapis.com/css?family=Merriweather">
    <link rel="stylesheet"
                href="https://fonts.googleapis.com/css?family=Baskerville">
    </head>
    </html>

    <body>
<!--[if lte IE 9]>
    <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
  <![endif]--> 

<!-- Add your site or application content here --> 
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>

.content {
    max-width: 600;
    margin: auto;
    background: white;
    padding: 10px;
}

  .topnav {
    overflow: hidden;
    background-color: #ffffff;
  }
  
  .topnav a {
    float: left;
    color: #000000;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    font-family: Merriweather;
	font-size:10px;
	max-width: 500px;
    margin: auto;
  }
  
  .topnav a:hover {
    background-color: #ddd;
    color: black;
  }
  
  .topnav a.active {
    background-color: #ddd;
    color: black;
  }
  
  .topnav-right {
    float: right;
  }



  
  code {
  background: #ddd;
  border-radius: 6px;
  color: #000000;
  display: block;
  font: 14px/24px "Source Code Pro", Inconsolata, "Lucida Console", Terminal, "Courier New", Courier;
  padding: 24px 15px;
  text-align: center;
}



header,
section,
aside,
footer {
  margin: 0 1.5% 24px 1.5%;
}
section {
    /*float: left;*/
    display: inline-block;
  width: 63%;
}
aside {
  /*float: right;*/
  display: inline-block;
  width: 30%;
}
footer {
  clear: both;
  margin-bottom: 0;
}




.content {
    max-width: 1000px;
    margin: auto;
    background: white;
    padding: 10px;
}
.container {
  position: relative;
}

/* Hide the images by default */
.mySlides {
  display: none;
}
 

.row:after {
  content: "";
  display: table;
  clear: both;
}





.sampleimages {
  float: down;
  width: 25%;
}

.activesample,
.demo:hover {
border: 3px solid #FAEA20; 
} 

.square{
    width: 600px;
    height: 700px;
    padding-top: 30px;
    padding-left: 50px;
    Background-color: #FAEA20;
}



  </style>
<div class="content">
      <header>
    <div class="topnav"> <a class="active" href="#home">Home</a> <a href="#men">Men</a> <a href="#women">Women</a> <a href="#Style_Accessories">Style & Accessories</a> <a  href="#logo_home"><img src="Images/Logo.png" width="57" height="57" alt="Logo"></a>
          <div class="topnav-right"> <a href="#myaccount">My Account</a> <a href="#saveditems">Saved Items</a> <a href="#mybasket"><img src="Images/BasketImage.png" width="69" height="57" alt="Basket"></a> </div>
        </div>
  </header>
      <section>
    <div class="mySlides">
          <div class="square"> <img src="Images/Prod1_1.png" style="width:120%;"> </div>
        </div>
    <div class="mySlides">
          <div class="square"> <img src="Images/Prod1_2.png" style="width:120%"> </div>
        </div>
    <div class="mySlides">
          <div class="square"> <img src="Images/Prod1_3.png" style="width:120%"> </div>
        </div>
    <div class="mySlides">
          <div class="square"> <img src="Images/Prod1_4.png" style="width:120%;"> </div>
        </div>
    <div class="mySlides">
          <div class="square"> <img src="Images/Prod1_5.png" style="width:120%"> </div>
        </div>
    <div class="mySlides">
          <div class="square"> <img src="Images/Prod1_6.png" style="width:120%"> </div>
        </div>
  </section>
      <aside>
    <div class="sampleimages"> <img class="demo cursor" src="Images/Prod1_1.png" style="width:100%" onclick="currentSlide(1)" > </div>
    <div class="sampleimages"> <img class="demo cursor" src="Images/Prod1_2.png" style="width:100%" onclick="currentSlide(2)" > </div>
    <div class="sampleimages"> <img class="demo cursor" src="Images/Prod1_3.png" style="width:100%" onclick="currentSlide(3)" > </div>
    <div class="sampleimages"> <img class="demo cursor" src="Images/Prod1_4.png" style="width:100%" onclick="currentSlide(4)" > </div>
    <div class="sampleimages"> <img class="demo cursor" src="Images/Prod1_5.png" style="width:100%" onclick="currentSlide(5)" > </div>
    <div class="sampleimages"> <img class="demo cursor" src="Images/Prod1_6.png" style="width:100%" onclick="currentSlide(6)" > </div>
  </aside>
      <footer> <code>&#60;footer&#62;</code> </footer>
    </div>
</body>
    </html><script>

    var slideIndex = 1;
    showSlides(slideIndex);
    
    function currentSlide(n) {
      showSlides(slideIndex = n);
    }
    
    function showSlides(n) {
      var i;
      var slides = document.getElementsByClassName("mySlides");
      var dots = document.getElementsByClassName("sampleimages");
      if (n > slides.length) {slideIndex = 1}
      if (n < 1) {slideIndex = slides.length}
      for (i = 0; i < slides.length; i++) {
          slides[i].style.display = "none";
      }
      for (i = 0; i < dots.length; i++) {
          dots[i].className = dots[i].className.replace(" activesample", "");
      }
      slides[slideIndex-1].style.display = "block";
      dots[slideIndex-1].className += " activesample";
      captionText.innerHTML = dots[slideIndex-1].alt;
    }
    </script>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Here is a version using Bootstrap 4 and flex
<!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>Title</title>
<style>
.yellow-block {
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	width: 70%;
	background: yellow;
	z-index: -1;
}
.container {
	width: 800px;
	overflow: hidden;
}
.image-container {
	margin-top: 35px;
	margin-bottom: 35px;
}
</style>
</head>
<body>
<br>
<div class="container" style="position: relative">
	<div class="yellow-block"></div>
	<div class="image-container d-flex justify-content-end" style="z-index: 100">
		<div class="pr-5"><img src="t3391/main.jpg"></div>
		<div class="d-flex flex-column align-items-start justify-content-between">
			<div><img src="t3391/top.jpg"></div>
			<div><img src="t3391/second.jpg"></div>
			<div><img src="t3391/third.jpg"></div>
			<div><img src="t3391/fourth.jpg"></div>
			<div><img src="t3391/last.jpg"></div>
		</div>
</div>
</body>
</html>

Open in new window


Working sample here
Joshua DavisIT Technician

Author

Commented:
Thanks for your help! It took a bit of playing around but I got it to work.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Joshua DavisIT Technician

Author

Commented:
Hi,

I have continued to work on this and its a bit further along, but i have come to a similar issue with positioning.
I am just trying to get my head round how the different positioning and flex methods work.

The section I am currently working on is the order form on the page. I have attached all of my code this time.Web-Challenge-Site---Copy.zip

If you could offer any advise it would be appreciated.

Thank you again,
Josh
Joshua DavisIT Technician

Author

Commented:
Hi,

I have continued to work on this and its a bit further along, but i have come to a similar issue with positioning.
I am just trying to get my head round how the different positioning and flex methods work.

The section I am currently working on is the order form on the page. I have attached all of my code this time.

If you could offer any advise it would be appreciated.

Thank you again,
Josh
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Best to open another question for this. Refer to this one and post the link to the new question here.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial