Create layout HTML with different div with different height - html

I would like to create a layout with divs with different height.
Example image:
I would like even that div can change the height based on the content.
In my code, I put a fixed height for the div so I want to modify it but I don't know how.
This is my code:
HTML
<div>
<div class="g-block-1">
<div class="block1"></div> <div class="block2"></div>
</div>
<div class="g-block-2">
<div class="block3"></div>
<div class="block4"></div>
<div class="block5"></div>
</div>
</div>
CSS
.block1 {
width: 100%;
height: 500px;
background-color: red;
}
.block2 {
width: 100%;
height: 350px;
background-color: yellow;
}
.block3 {
width: 100%;
height: 100px;
background-color: blue;
}
.block4{
width: 100%;
height: 350px;
color: black;
}
.block5 {
width: 100%;
height: 400px;
color: pink;
}
.g-block-1 {
width: 50%;
float: left;
}
.g-block-2 {
width: 50%;
float: right;
}

Something like this?
https://jsfiddle.net/scorpio777/wwwLmvfu/
<style>
pre {margin:0 padding:0;}
.block1 {
width: 100%;
height: 100%;
border:1px solid;
border-color:red;
margin:0;
padding:0;
}
.block2 {
width: 100%;
height: 100%;
border:1px solid;
border-color:orange;
margin:0;
padding:0;
}
.block3 {
width: 100%;
height: 100%;
border:1px solid;
border-color:blue;
margin:0;
padding:0;
}
.block4{
width: 100%;
height: 100%;
border:1px solid;
border-color:green;
margin:0;
padding:0;
}
.block5 {
width: 100%;
height: 100%;
border:1px solid;
border-color:pink;
margin:0;
padding:0;
}
.g-block-1 {
width: 50%;
height:100%;
float: left;
display:inline-block;
margin:0;
padding:0;
}
.g-block-2 {
width: 50%;
float: right;
height:100%;
display:inline-block;
margin:0;
padding:0;
}
}
</style>
<div>
<div class="g-block-1">
<div class="block1">
<pre>
some content
some content
some content
some content
some content
some content
some content
some content
</pre>
</div>
<div class="block2">
<pre>
some content
some content
some content
some content
some content
some content
some content
some content
some content
some content
</pre>
</div>
</div>
<div class="g-block-2">
<div class="block3">
<pre>
some content
some content
some content
some content
some content
</pre>
</div>
<div class="block4">
<pre>
some content
some content
some content
some content
some content
</pre>
</div>
<div class="block5">
<pre>
some content
some content
some content
some content
some content
</pre>
</div>
</div>
</div>

You can try this responsive solution:
* {box-sizing: border-box}
body {margin: 0}
#container {
width: 1200px;
max-width: 100%;
margin: 0 auto;
}
.items {
column-count: 3;
column-gap: 10px;
}
.item {
margin-bottom: 10px;
page-break-inside: avoid;
break-inside: avoid-column;
}
img {
display: block;
max-width: 100%;
}
#media (max-width: 1220px) {
.items {padding: 0 10px}
}
#media (max-width: 990px) {
.items {column-count: 2}
}
#media (max-width: 500px) {
.items {column-count: 1}
}
<div id="container">
<section class="items">
<div class="item">
<img src="http://www.nowphuket.com/wp-content/uploads/2014/09/layan-beach-550x400.jpg" alt="">
</div>
<div class="item">
<img src="https://www.globotreks.com/wp-content/uploads/2017/06/Redding-Nature-600x450.jpg" alt="">
</div>
<div class="item">
<img src="http://liveinlosgatosblog.com/wp-content/uploads/2015/08/Shannon-Valley-Ranch-open-space-trail-650x500.jpg" alt="">
</div>
<div class="item">
<img src="http://www.9corerealty.com/wp-content/uploads/2016/03/Collier-County-4-700x550.jpg" alt="">
</div>
<div class="item">
<img src="http://webbox.imgix.net/images/aisrvqxbdirtzdby/c141a47e-bdd2-4687-a795-61141548c195.jpg?auto=enhance,compress&fit=crop&w=750&h=600" alt="">
</div>
<div class="item">
<img src="http://colonialbrickandstone.com/colonialwp/media/manitoulin-island-view-800x650.jpg" alt="">
</div>
<div class="item">
<img src="http://all-that-is-interesting.com/wordpress/wp-content/uploads/2013/08/secret-gardens-kirstenbosch-2.jpg" alt="">
</div>
<div class="item">
<img src="http://www.thinkslovenia.com/upload/area_guides/south_top_10/kolpa.jpg" alt="">
</div>
<div class="item">
<img src="https://www.viaventure.com/wp-content/uploads/450x300-Lamanai03.jpg" alt="">
</div>
<div class="item">
<img src="http://webbox.imgix.net/images/aisrvqxbdirtzdby/c141a47e-bdd2-4687-a795-61141548c195.jpg?auto=enhance,compress&fit=crop&w=750&h=600" alt="">
</div>
<div class="item">
<img src="http://colonialbrickandstone.com/colonialwp/media/manitoulin-island-view-800x650.jpg" alt="">
</div>
<div class="item">
<img src="http://all-that-is-interesting.com/wordpress/wp-content/uploads/2013/08/secret-gardens-kirstenbosch-2.jpg" alt="">
</div>
<div class="item">
<img src="http://www.thinkslovenia.com/upload/area_guides/south_top_10/kolpa.jpg" alt="">
</div>
<div class="item">
<img src="https://www.viaventure.com/wp-content/uploads/450x300-Lamanai03.jpg" alt="">
</div>
<div class="item">
<img src="https://www.fredericanaturereserve.com/wp-content/uploads/2016/08/500x350-px-F1-10.jpg" alt="">
</div>
<div class="item">
<img src="http://www.nowphuket.com/wp-content/uploads/2014/09/layan-beach-550x400.jpg" alt="">
</div>
<div class="item">
<img src="https://www.globotreks.com/wp-content/uploads/2017/06/Redding-Nature-600x450.jpg" alt="">
</div>
<div class="item">
<img src="http://liveinlosgatosblog.com/wp-content/uploads/2015/08/Shannon-Valley-Ranch-open-space-trail-650x500.jpg" alt="">
</div>
<div class="item">
<img src="http://www.9corerealty.com/wp-content/uploads/2016/03/Collier-County-4-700x550.jpg" alt="">
</div>
</section>
</div>

Related

I don't know why my images won't show up?

I am making myself a digital cv, and I can't get my images to show up on one of the pages.
The CSS and the HTML you can copy and use. Everything is working expect the images showing up, and I cannot understand why this is happening.
function openNav() {
document.getElementById("hamburger").style.display = "block";
}
function closeNav() {
document.getElementById("hamburger").style.display = "none";
}
* {
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
padding: 20px;
font-family: Crown Title;
}
h3 {
font-size: 30px;
}
.main {
max-width: 1500px;
margin: auto;
}
h1 {
font-size: 50px;
word-break: break-all;
}
.row {
margin: 8px-16px;
}
img {
background-color: none;
}
.content {
background-color: none;
padding: 15px;
}
.column {
float: left;
width: 50%;
}
#media screen and (max-width:900px) {
.column {
width: 50%
}
}
#media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
<div id="hamburger" class="sidenav">
×
Home
My Story
Career
Education
Portfolio
Contact Us
<img alt="logo" src="https://us.123rf.com/450wm/krisdog/krisdog1709/krisdog170900122/85720771-stock-vector-lion-standing-rampant-heraldic-crest-coat-of-arms.jpg?ver=6">
</div>
<!--Burger Icon-->
<span style="font-size 30px; cursor: pointer" onclick="openNav()">☰</span>
<div class="main">
<!--Main Photo-->
<h1>See The World Through My Eyes</h1>
<div class="content">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQYOECNfDLyTYX5rEW8lFdhjTknabIrOH5amCPJYYIfWOFvNVLK&usqp=CAU" alt="happy" style="width:100%">
<h3>Wedding</h3>
</div>
<!--Table Grid smaller Photos-->
<div class="row">
<div class="column">
<div class="content">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTMejgEW9M5tYts8sPMXHj67KOW5_uzT2qR9A0gwpi660qqYVRD&usqp=CAU" alt="colors" style="width: 100%; height:50%">
<h3>Architecture</h3>
</div>
</div>
<div class="column">
<div class="content">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcR0rBotboUlDoTFx1iX0FsXpt4Z4VbvA_5E34b-jG1BSQqtJ6yO&usqp=CAU" alt="animals" style="width:100%">
<h3>Animals</h3>
</div>
</div>
<div class="column">
<div class="content">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSVA6mUCorGmSCDsSY4qwZvG_CTbmh_N0db-4a_Z1HDcd25ulZR&usqp=CAU" alt="my_love" style="width:100%, height:50%">
<h3>Portrait</h3>
</div>
</div>
<div class="column">
<div class="content">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRowQXo7erqtYGz-3pOsPVLcD-baQ4Cyz1RUH5e30tUtS0crWFY&usqp=CAU" alt="my_loves_handmande_food" style="width:100%"></img>
<h3>Bento Box(M)</h3>
</div>
</div>
</div>
<div class="content">
<img src="https://i.pinimg.com/originals/16/58/bc/1658bcc4bc5a3976845372f7f8eddd00.jpg" alt="actually_Katsu_Dragneel" style="width:100%"></img>
<h3>Next Generation</h3>
</div>

Struggling with positioning divs around page

I've been working on this for days and feel like I've tried everything. Not sure if it's just something small that I'm missing or if I'm completely off track. I need to position my divs on the page like in this image the code I've got so far is this.
HTML:
body {
margin: 0px;
padding: 0px;
width: 1024px;
height: 768px;
float: left;
}
.pagebanner {
height: 200px;
width: 1024px;
}
.header {
background-color: aqua;
height: 50px;
margin-top: 0px;
padding-left: 200px
}
.navbar {
background-color: brown;
float: left;
height: 768px;
}
.subheading {
background-color: chartreuse;
padding-left: 420px;
margin-top: 0px
}
.content {
background-color: crimson;
height:
}
.footer {
background-color: darkgreen;
padding: 20px;
margin-bottom: 0px
}
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>The Club Site</title>
</head>
<body>
<div wrapper="mainwrapper">
<div class="pagebanner"><img src="HTML Pract A/images/banner.jpg" alt="PageBanner" width="1024px" height="200px">
<div class="navbar">
<ul>
<li></li>
<li></li>
</ul>
</div>
<div class="header">
<h1 class="header">The Club Site</h1>
</div>
<div class="subheading">
<h2>Members Prices</h2>
</div>
<div class="content">
</div>
<div class="footer">
<p>blah blah blah</p>
</div>
</div>
</body>
</html>
Any help with this would be greatly appreciated. First time trying to use HTML and I'm not having much luck with it.
In this sample i try to introduction bootstrap framework to you, bootstrap can help you to make a lot of html templates with less time, try t read documentation of this framework and you will figure out how it's easy.
Good luck with it and always before you ask something search about it,
i'm sure you will get solved questions.
This sample based on bootstrap 4 framework
.nav {
background-color: #ccc;
min-height: 500px;
}
.header {
background-color: #eee;
}
.sub-header {
background-color: yellow;
margin-bottom: 15px;
}
.item {
border: solid 1px #ccc;
text-align: center;
height: 150px;
margin-bottom: 15px;
}
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>The Club Site</title>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col">
<h1>header</h1>
</div>
</div>
<div class="row">
<div class="col-4 nav">
<h3>nav</h3>
</div>
<div class="col-8">
<div class="row">
<div class="col header">
<h3>The Club Site</h3>
</div>
</div>
<div class="row">
<div class="col sub-header">
<h6>sub header</h6>
</div>
</div>
<div class="row">
<div class="col-4">
<div class="item">
<h4>item 1</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 2</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 3</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 4</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 5</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 6</h4>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<header>Header</header>
<div id="main">
<article>
<div class="my-container">
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
</div>
</article>
<nav>Nav</nav>
</div>
<footer>Footer</footer>
<style>
* {
box-sizing: border-box;
}
body {
display: flex;
min-height: 100vh;
flex-direction: column;
margin: 0;
}
#main {
display: flex;
flex: 1;
}
#main > article {
flex: 1;
order: 1;
}
#main > nav,
#main > aside {
flex: 0 0 20vw;
}
#main > nav {
background: #D7E8D4;
order: 3;
}
header, footer {
background: yellowgreen;
height: 20vh;
}
header, footer, article, nav, aside {
padding: 1em;
}
.my-container {
display: flex;
flex-flow: row wrap;
align-content: flex-start; /* pack wrapping lines to the top */
width: 100%;
height: 300px;
}
.image {
flex: 0 0 30%;
margin: 5px;
}
img {enter code here
max-width: 100%;
}
</style>
Note: try to learn instead copy & paste it, to start try to write codes again.
I change and also add some css class in your codes, so pay-attention to different between old version and new css and html files.
Description: for start modeling your style you need to separate all partsyou need; for example here we need:
Header
Header > image
main > nav
main > content
main > content > header
main > content > subheading
main > content > area
main > content > area > items
main > content > area > items > item
etc...
and then start to html them, insert your div or what you want, and last step is manage them with css.
body {
margin: 0px;
padding: 0px;
}
.mainwrapper {
width: 1024px;
margin: 0 auto;
}
.pagebanner {
height: 250px;
margin: 0;
}
.pagebanner img {
width: 100%;
height: 100%;
}
.main {
margin: 0;
}
.navbar {
background-color: brown;
min-height: 500px;
width: 20%;
float: left;
}
.navbar li {
list-style: none;
margin-bottom: 15px;
}
.navbar a {
color: #fff;
font-size: 20px;
}
.content {
width: 80%;
float: left;
padding: 0;
min-height: 500px;
}
.header {
background-color: #000;
text-align: center;
}
.header h1 {
color: #fff;
margin: 0;
}
.subheading {
background-color: #f8d631;
text-align: center;
}
.subheading h2 {
background-color: #f8d631;
margin: 0;
}
.area h3 {
margin: 0;
text-align: center;
}
.item {
width: 33.33333333333333%;
float: left;
text-align: center;
}
.item div {
padding: 0 15px;
}
.item img {
height: 150px;
width: 100%;
}
.footer {
background-color: darkgreen;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<div class="mainwrapper">
<div class="pagebanner">
<img src="https://cdn-images-1.medium.com/max/1400/1*278tqw9zNPe2WCAz29Wzdw.jpeg" alt="PageBanner">
</div>
<div class="main">
<div class="navbar">
<ul>
<li>
Information
</li>
<li>
Home
</li>
</ul>
</div>
<div class="content">
<div class="header">
<h1>The Club Site</h1>
</div>
<div class="subheading">
<h2>Members Prices</h2>
</div>
<div class="area">
<h3>discounted Items</h3>
<div class="items">
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

In-line image and h (HTML/CSS)

I want to align in-line a profile image and its username inline. Here's the code:
<div id="post">
<div class="proPic">
<img title="proPic" alt="Profile Picture" src="">
</div>
<h3>Username</h3>
<p>Text post</p>
</div>
What's the best way to do this? I'd like to see both HTML and CSS methods.
Here's a version using less code than you have already ;)
body {
font-family: arial;
}
.profile {
width: 25%;
float: right;
background: pink;
}
.profile h3 {
margin: 0;
padding: 0;
font-size: 14px;
min-height: 50px; /*Just for demo*/
}
.content {
width: 70%;
float: left;
background: #ccc;
min-height: 200px; /*Just for demo*/
}
<div class="post">
<div class="profile">
<img title="proPic" alt="Profile Picture" src="">
<h3>Username</h3>
</div>
<div class="content">
Text post
</div>
</div>

How to get 'four corner' alignment with floated divs

Ok so my project requires my divs to be floated because I would like to place text neatly to the side of them. I can get my divs to float left and right as needed, but as you see from the snippet(even though it's not what you'd get from a browser since the dimensions are off), the two divs at the bottom I need to be near the top in order to make a perfect scquare with the two left-floated divs. Below is what I'm looking for:
.clear {
clear: both;
}
#centerbar {
width: 100%;
height: calc(100vh - 150px);
background-color: black;
float: left;
}
#centerbar h1 {
text-align: center;
color: white;
}
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
font-family: courier;
font-size: 19px;
color: white;
}
#container {
min-height: 100%;
margin-bottom: -150px;
width: 100%;
}
#container:after {
content: "";
display: block;
}
#content {
display: flex;
margin: 0 auto;
width: 800px;
flex-wrap: wrap;
justify-content: center;
}
.box {
height: 200px;
}
.fltlt {
float: left;
margin-right: 50px;
}
.fltrt {
float: right;
margin-right: 50px;
}
<div class="container">
<div id="nav">
<ul>
<li>Home
</li>
<li>Works
</li>
<li>About
</li>
</ul>
</div>
<div class="clear"></div>
<div id="centerbar">
<h1>Sample Layout</h1>
<div class="box">
<img src="gold.jpg" alt="The Color Gold" class="fltlt">
<p>This is some sample text</p>
</div>
<div class="clear"></div>
<div class="box">
<img src="grey.jpg" alt="The Color Grey" class="fltlt">
<p>This is some sample text</p>
</div>
<div class="box">
<img src="orange.jpg" alt="The Color Orange" class="fltrt">
<p>This is some sample text</p>
</div>
<div class="box">
<img src="red.png" alt="The Color Red" class="fltrt">
<p>This is some sample text</p>
</div>
</div>
</div>
<div id="footer">
<div class="wrap">
<div class="sub">Lorem Ipsum</div>
<div class="sub">Lorem Ipsum</div>
<div class="sub">Lorem Ipsum</div>
</div>
</div>
I recommend to not use float for layout, and since you started out with flex, use it all the way.
Bonus: A clean, simple and readable structure of both CSS and markup.
.container .row {
display: flex;
flex-wrap: wrap;
}
.row .box {
width: 50%;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 10px;
}
.box img {
width: 100px;
margin-right: 10px;
}
<div class="container">
<div class="row">
<div class="box">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSr2zmmalj8xwazqph9jB97VW8MgfrfJ_ThJt9iTGKGMNl-7dp7mKnfvg4" alt="">
<p>Some paragraph here</p>
</div>
<div class="box">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSr2zmmalj8xwazqph9jB97VW8MgfrfJ_ThJt9iTGKGMNl-7dp7mKnfvg4" alt="">
<p>Some paragraph here</p>
</div>
<div class="box">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSr2zmmalj8xwazqph9jB97VW8MgfrfJ_ThJt9iTGKGMNl-7dp7mKnfvg4" alt="">
<p>Some paragraph here</p>
</div>
<div class="box">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSr2zmmalj8xwazqph9jB97VW8MgfrfJ_ThJt9iTGKGMNl-7dp7mKnfvg4" alt="">
<p>Some paragraph here</p>
</div>
</div>
</div>
Here is what you are looking for(I made it from the start):
.box {
float: left;
position: relative;
width: 50%;
margin-bottom: 10px;
}
.container .flex {
display: flex;
align-items: center;
}
.container p {
margin-left: 5px;
}
<div class="container">
<div class="row">
<div class="box">
<div class="flex">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSr2zmmalj8xwazqph9jB97VW8MgfrfJ_ThJt9iTGKGMNl-7dp7mKnfvg4" alt="" width="100">
<p>Some paragraph here</p>
</div>
</div>
<div class="box">
<div class="flex">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSr2zmmalj8xwazqph9jB97VW8MgfrfJ_ThJt9iTGKGMNl-7dp7mKnfvg4" alt="" width="100">
<p>Some paragraph here</p>
</div>
</div>
<div class="box">
<div class="flex">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSr2zmmalj8xwazqph9jB97VW8MgfrfJ_ThJt9iTGKGMNl-7dp7mKnfvg4" alt="" width="100">
<p>Some paragraph here</p>
</div>
</div>
<div class="box">
<div class="flex">
<img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSr2zmmalj8xwazqph9jB97VW8MgfrfJ_ThJt9iTGKGMNl-7dp7mKnfvg4" alt="" width="100">
<p>Some paragraph here</p>
</div>
</div>
</div>
</div>

Centering images with text as menu

Im trying to put together some images together with an text under the images which will work as an menu, which should be centered horizontal under an header. The website is supposed to work as an responsive website. The HTML and CSS code is currently looking like this:
Edited
I want 5 images, each one of them shall have a text under them. And I want the my images together with the text to be centered.
HTML
<nav>
<div id="content">
<img src="ikoner/icon_90_2.png"/>
<div class="text">Utvecklingen sedan 90-talet</div>
</div>
<div id="content">
<img src="ikoner/icon_html5.png"/>
<div class="text">HTML5</div>
</div>
<div id="content">
<img src="ikoner/icon_html5video.png"/>
<div class="text">HTML5 Video</div>
</div>
<div id="content">
>img src="ikoner/icon_responsive.png"/>
<div class="text">Responsive Webdesign</div>
</div>
<div id="content">
<img src="ikoner/icon_heart.png"/>
<div class="text">Emotional Design</div>
</div>
</nav>
CSS
#content {
position: relative;
width: 15%;
display: inline-block;
text-align: center;
margin-left: auto;
margin-right: auto;
}
#content img {
padding-top: 370px;
width: 100px;
}
.text {
font-size: 12px;
font-family: 'ciclethin';
text-decoration: none;
}
You're not aligning your "Nav" div anywhere.
So, I've changed the id="content" to classes, because IDs should be unique to the page.
Set nav element to text-align:center. Here's a fiddle, and the relevant code:
http://jsfiddle.net/cw16tkdn/2/
<nav>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Utvecklingen sedan 90-talet
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">HTML5
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">HTML5 Video
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Responsive Webdesign
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Emotional Design
</div>
</div>
</nav>
and CSS:
nav {
text-align:center;
}
.content {
display: inline-block;
text-align: center;
}
.content img {
width: 100px;
}
.text {
font-size: 12px;
font-family:'ciclethin';
text-decoration: none;
}
maybe you want this: (i have changed id=content with class=content in html code!)
.content {
position: relative;
width: 100px;
display: inline-block;
height: 520px;
text-align: center;
vertical-align:bottom;
}
.content img {
padding-top: 370px;
width: 100px;
display:block;
margin: auto;
}
.text a {
font-size: 12px;
font-family: 'ciclethin';
text-decoration: none;
}
.text {
height: 3em;
}