Div not inline when window gets smaller? - html

I'm having a small issue with a couple divs. I have it set up with 5 divs all different colors, when the window size is shrunk the divs drop down under each other one by one. Is there a way I can make the space between them shrinks with it so they but up closer?
Thanks again guys
p {
margin: 0;
}
.pageColourOn {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 155px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.pageColourOff {
display: none;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
.bg01Off {
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.bg02Off {
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.bg03Off {
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.bg04Off {
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.bg05Off {
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.center {
text-align: center;
}
<div class="pageColourOn" id="pageColour">
<div id="pageName">
<p>Colour</p>
</div>
<div class="center">
<div id="bg01" class="bg01Off">
</div>
<div id="bg02" class="bg02Off">
</div>
<div id="bg03" class="bg03Off">
</div>
<div id="bg04" class="bg04Off">
</div>
<div id="bg05" class="bg05Off">
</div>
</div>

Change the container center to a flexbox with the following properties:
.center {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
padding: 0 4%
}
p {
margin: 0;
}
.pageColourOn {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 155px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.pageColourOff {
display: none;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
.bgOff {
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}
.bg01Off {
background-color: #80b3ff;
}
.bg02Off {
background-color: #afe9af;
}
.bg03Off {
background-color: #ffb380;
}
.bg04Off {
background-color: #ffaaaa;
}
.bg05Off {
background-color: #eeaaff;
}
.center {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
padding: 0 4%
}
<div class="pageColourOn" id="pageColour">
<div id="pageName">
<p>Colour</p>
</div>
<div class="center">
<div id="bg01" class="bgOff bg01Off">
</div>
<div id="bg02" class="bgOff bg02Off">
</div>
<div id="bg03" class="bgOff bg03Off">
</div>
<div id="bg04" class="bgOff bg04Off">
</div>
<div id="bg05" class="bgOff bg05Off">
</div>
</div>

Add a media query, so that after a certain width of screen the elements will get a margin-bottom that is a percentage instead of px.

Use media queries to make elements respond as the width of the viewport changes for example:
body {
background-color: lightgreen;
}
#media only screen and (max-width: 500px) {
body {
background-color: lightblue;
}
}
This would make the background color change when the width of the viewport goes below 500 px. You can use this same concept with the width of your divs.
** Also, check out Bootstrap. Bootstrap makes it easy to define widths of elements using a grid system. You are trying to make your site "RESPONSIVE" which is a well-known concept in web dev. Bootstrap has an already created library for this problem. It use media queries to do it. It is worth understanding media queries deeply, but for a quick fix, research bootstrap.

You could put a rule in a media query that reduces the margins like in my example (last rule):
p {
margin: 0;
}
.pageColourOn {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 155px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.pageColourOff {
display: none;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
.bg01Off {
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.bg02Off {
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.bg03Off {
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.bg04Off {
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.bg05Off {
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
}
.center {
text-align: center;
}
#media screen and (max-width: 760px) {
.bg01Off,
.bg02Off,
.bg03Off,
.bg04Off,
.bg05Off {
margin-left: 1%;
margin-right: 1%;
}
<div class="pageColourOn" id="pageColour">
<div id="pageName">
<p>Colour</p>
</div>
<div class="center">
<div id="bg01" class="bg01Off">
</div>
<div id="bg02" class="bg02Off">
</div>
<div id="bg03" class="bg03Off">
</div>
<div id="bg04" class="bg04Off">
</div>
<div id="bg05" class="bg05Off">
</div>
</div>

You can use a table instead of the .center div, and give it the following styles:
table {
width: 100%;
text-align: center;
}
td {
width: 20%; /* This is 100/the number of <td>'s you have in the table. */
}
p {
margin: 0;
}
.pageColourOn {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 155px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.pageColourOff {
display: none;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
.bg01Off {
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}
.bg02Off {
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}
.bg03Off {
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}
.bg04Off {
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}
.bg05Off {
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}
table {
width: 100%;
text-align: center;
}
td {
width: 20%;
}
<div class="pageColourOn" id="pageColour">
<div id="pageName">
<p>Colour</p>
</div>
<table>
<tr>
<td>
<div id="bg01" class="bg01Off">
</div>
</td>
<td>
<div id="bg02" class="bg02Off">
</div>
</td>
<td>
<div id="bg03" class="bg03Off">
</div>
</td>
<td>
<div id="bg04" class="bg04Off">
</div>
</td>
<td>
<div id="bg05" class="bg05Off">
</div>
</td>
</tr>
</table>

You can remove margin left & right and use flexbox on .center like this :
p {
margin: 0;
}
.pageColourOn {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 155px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.pageColourOff {
display: none;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
.bg01Off {
background-color: #80b3ff;
}
.bg02Off {
background-color: #afe9af;
}
.bg03Off {
background-color: #ffb380;
}
.bg04Off {
background-color: #ffaaaa;
}
.bg05Off {
background-color: #eeaaff;
}
.bg05Off, .bg04Off, .bg03Off, .bg02Off, .bg01Off {
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}
.center {
display: flex;
justify-content: space-around;
}
<div class="pageColourOn" id="pageColour">
<div id="pageName">
<p>Colour</p>
</div>
<div class="center">
<div id="bg01" class="bg01Off">
</div>
<div id="bg02" class="bg02Off">
</div>
<div id="bg03" class="bg03Off">
</div>
<div id="bg04" class="bg04Off">
</div>
<div id="bg05" class="bg05Off">
</div>
</div>

Related

Need to make two buttons align a few pixels left and right of the center

Need to make two buttons align a few pixels left and right of the centre
I need div left to be 1px to the left of the centre. And right to be 1px right of it.
Any ideas how?
.btn {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
color: black;
border: 2px solid black;
background-color: white;
width: 100px;
text-decoration: none;
}
.btn2 {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
color: white;
border: 2px solid white;
background-color: black;
width: 100px;
text-decoration: none;
}
.divleft {
margin: auto 0;
text-align: left;
}
.divright {
margin: auto 0;
text-align: right;
}
<div class="divleft"> Memento </div>
<div class="divright"> Mori </div>
Use flexbox:
.box {
display: flex;
width: 100%;
}
.left,
.right {
width: 100%;
}
.left {
text-align: right;
margin-right: 10px;
}
a {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
border: 2px solid black;
width: 100px;
text-decoration: none;
}
.btn {
color: black;
background-color: white;
}
.btn2 {
color: white;
background-color: black;
}
<div class="box">
<div class="left">
Memento
</div>
<div class="right">
Mori
</div>
</div>
Codepen: https://codepen.io/manaskhandelwal1/pen/jOMgpbd
I created a CodePen that shows how to make it work: https://codepen.io/kaireidcasey/pen/rNMXrde
The parent element needs display: flex set on it. The children each need an auto margin on one side. I am sure there are other ways to solve this, as well.
Code snippets:
HTML:
<div class="container">
<div class="divleft">
Memento
</div>
<div class="divright">
Mori
</div>
</div>
CSS:
.btn {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
color: black;
border: 2px solid black;
background-color: white;
width: 100px;
text-decoration: none;
}
.btn2 {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
color: white;
border: 2px solid white;
background-color: black;
width: 100px;
text-decoration: none;
}
.divleft {
margin-right: 1px;
margin-left: auto;
}
.divright {
margin-left: 1px;
margin-right: auto;
}
.container {
display: flex;
}

How to make whole Div hoverable

I am trying to make somethng like that:enter image description here
Image from the left I have done without botton-right cut, I have made border-radius.
Image from the right is what happens when you hover on whole item. AS you can see only middle is highlighted. Any idea how to fix it?
Here is my Code:
HTML:
<div class="pojemnik" onclick="location.href='nitystandardowe.html'" >
<div class="zdjecie"> <img src="img/nitystandardowe.jpg"> </div>
<div class="tekst_"><h5>Nity Standardowe</h5> </div>
</div>
CSS:
.pojemnik{
display: flex;
width: 190px;
height: 170px;
background-color: #f5f7f6;
flex-wrap: wrap;
flex-direction: column;
color: silver;
font-family: sans-serif;
text-decoration: none;
border-bottom-right-radius: 30px;
}
.pojemnik:hover {
text-decoration: none;
cursor: pointer;
width: 190px;
height: 190px;
background-position:bottom;
background-image: url("../images/icons/strzalka-w-praw-tlo.png");
background-repeat: no-repeat;
bottom: 20px;
}
.tekst_ {
border-bottom: solid 2px white;
padding-left: 10px;
}
.tekst_:hover {
border-bottom: solid 2px blue;
background-color:#00a2fa;
border-bottom: solid 1px white;
color: white;
}
.tekst_ h5{
font-family: sans-serif;
font-size: 15px;
margin-top: 5px;
margin-left: 5px;
}
.tekst_ h5:hover{
font-family: sans-serif;
font-size: 15px;
margin-top: 5px;
margin-left: 5px;
color: white;
}
.zdjecie{
align-self: flex-start;
}
.zdjecie img{
position: relative;
width: 190px;
}
You need to specify that you also need to target the .tekst_ class upon hover of .pojemnik like so:
.pojemnik:hover .tekst_ {
border-bottom: solid 2px blue;
background-color:#00a2fa;
border-bottom: solid 1px white;
color: white;
}
.pojemnik{
display: flex;
width: 190px;
height: 170px;
background-color: #f5f7f6;
/* flex-wrap: wrap; */
flex-direction: column;
color: silver;
font-family: sans-serif;
text-decoration: none;
border-bottom-right-radius: 30px;
}
.pojemnik:hover {
text-decoration: none;
cursor: pointer;
width: 190px;
height: 190px;
background-position:bottom;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAUVBMVEX///8AAAD7+/s7OzusrKze3t7Z2dmvr6/b29tVVVUFBQVdXV34+Pjt7e0SEhKUlJRCQkLl5eXy8vJzc3NlZWXLy8tra2u9vb1KSkp5eXmZmZlkbd6rAAACfElEQVR4nO2di27aQBBFbWhSYhzCK03T///QVkhR0mAjEyBrn3vOB6C5mjs7uwvLVJWIiIiIiIiIiIiIiIiIiIjIG+1mWzqEW7LYNfU/9s+lA7kRs9f6jeVj6WBuQTuv31ndlQ7nBqzr/+BJ/FN/4r50RFdmu/qssF6Ujum6/DwSSDPqrkMhK4vLLoWoWnzoVEgy6q9uhSCJTz0KOUa971PIkdi91JCMuulViGkaL/0SKUb9wc/iCYmUWuzanOZkMaAWA4waIDHAqAESA4xq05gMARs4mwaB7FoMMCpFYrZRKU0juxYDsmgtToaApuEGjkB206BIzDYqpWlk12JAFgNqMcCoARIDjBogMcCoNo3JELCBs2kQyK7FAKNSJGYb1abRw2xsXDeLm6f9ej42fvcrPLcW29cTnzVSzsri5vjl3AQ4oxYfm9LBfolm+FvinkdXo+dhqMAT7yBGzgs8hXW9HCawLR3nBbSDFN6VDvMChi2nz6XDvIBh/z7BzyG/DvlraUA/nGwSB+9pAval/LPFNM+H515k0M/4B0pfyxzBv23DXwr3Z7BhZBB/5x1sUbzABm9RxiKTXIOMDCa3CXwG6TUI2arhfyqU3CbwAvEWZSwyyRbFZxBfg3iL0gXyT/R4gXSL8gXiLYpv9HiL4jOIr0G8RekC+Vs1xiKTXIOMDCa3CXwG6TXoly/TILlN4AXiLcpYZJItysggft7TiZldDIvy564t4BZNmH/In2HJn0PKnyXLnwfMn+nMn8vNn61eVWuyRQ+08w/6VkCBVTV7f6m6POMN76RY7A6PqvfD/u1horSbbekQRERERERERERERERERERE5Jv4CxOfKflP0w6QAAAAAElFTkSuQmCC");
background-size: 20px 20px;
background-repeat: no-repeat;
bottom: 20px;
}
.tekst_ {
border-bottom: solid 2px white;
padding-left: 10px;
}
/* .tekst_:hover {
border-bottom: solid 2px blue;
background-color:#00a2fa;
border-bottom: solid 1px white;
color: white;
} */
.pojemnik:hover .tekst_ {
border-bottom: solid 2px blue;
background-color:#00a2fa;
border-bottom: solid 1px white;
color: white;
}
.tekst_ h5{
font-family: sans-serif;
font-size: 15px;
margin-top: 5px;
margin-left: 5px;
}
/* .tekst_ h5:hover{
font-family: sans-serif;
font-size: 15px;
margin-top: 5px;
margin-left: 5px;
color: white;
} */
.zdjecie{
align-self: flex-start;
}
.zdjecie img{
position: relative;
width: 190px;
}
<div class="pojemnik" onclick="location.href='nitystandardowe.html'" >
<div class="zdjecie"> <img src="https://cdn.pixabay.com/photo/2020/11/17/15/44/cup-5752775__340.jpg"> </div>
<div class="tekst_"><h5>Nity Standardowe</h5> </div>
</div>

How to move elements to the down of the page?

I want to move to the text area to align with other fields and then move all these fields to the down of the text "Feel free...." I was trying to use marigin-left, marigin-top, but nothing works. All the time these fields stay in one place. Do not know why.
It has to work on ip 6/7/8 plus resolution.
Could you tell me how can I achieve it?
* {
margin: 0;
padding: 0;
}
header {
width: 1920;
height: 1080px;
}
body {
display: flex;
flex-direction: column;
min-height: 100vh;
margin: 0;
height: 1080px;
background-image: linear-gradient(180deg, #EFEFEF00 0%, #0F4A37 100%);
}
footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: black;
color: white;
text-align: center;
}
footer img {
margin-top: 5px;
height: 30px;
display: inline-block;
padding: 0px 10px 0px 0px;
}
.main-nav {
float: right;
color: #000000;
margin-top: 40px;
margin-right: 0px;
}
.main-nav li {
display: inline-block;
}
.main-nav li a {
color: #000000;
text-decoration: none;
font: Bold 25px/15px Arial;
padding: 5px;
}
#logo {
margin-top: 10px;
float: left;
}
#tekst {
position: absolute;
}
#sign a {
background-color: #DCDFDE;
padding: 30px 15px 17px 15px;
border-top: 3px solid black;
border-bottom: 3px solid black;
border-left: 3px solid black;
border-right: 3px solid black;
}
#profilesign {
margin-top: 400px;
margin-left: 250px;
font: Bold 40px/40px Georgia;
letter-spacing: 0;
color: black;
}
.left {
-webkit-border-radius: 20px;
-khtml-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 150px 150px;
}
img.left {
padding: 0px 40px 20px 40px;
width: 250px;
height: 250px;
margin-left: 400px;
margin-top: 500px;
}
article input {
width: 300px;
height: 40px;
background: white;
border-radius: 4px;
text-decoration: none;
text-align: center;
font: Bold 25px/12px Arial;
border-radius: 120;
border-style: none;
padding: 6px;
margin-left: 1000px;
margin-top: 500px;
}
article #textSign {
font-size: 50px;
color: black;
text-align: center;
}
#centerText {
text-align: center;
}
#something {
width: 700px;
height: 300px;
text-align: justify;
margin-left: 1000px;
font-size: 30px;
font-weight: bold;
}
#media only screen and (max-device-width: 500px) {
#profilesign {
width: 1000px;
margin-top: 750px;
margin-left: 400px;
font: Bold 60px/40px Georgia;
letter-spacing: 0;
color: black;
}
img.left {
padding: 0px 40px 20px 40px;
width: 550px;
height: 550px;
margin-left: 550px;
margin-top: 450px;
}
footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 60px;
background-color: black;
color: white;
text-align: center;
}
footer img {
margin-top: 5px;
height: 50px;
display: inline-block;
padding: 0px 10px 0px 0px;
}
#sign a {
background-color: #DCDFDE;
padding: 20px 15px 17px 1px;
border-top: 3px solid black;
border-bottom: 3px solid black;
border-left: 3px solid black;
border-right: 3px solid black;
}
#logo img {
margin-left: 550px;
text-align: center;
width: 650px;
}
body {
background-image: linear-gradient(180deg, #EFEFEF00 0%, #0F4A37 100%);
background-size: 100% 3000px;
width: auto;
}
.row {
width: 2500px;
display: grid;
grid-template-columns: 0% 80%;
}
.main-nav {
margin-left: 100px;
margin-top: 250px;
float: left;
display: inline-flex;
list-style: none;
}
.main-nav li a {
border-right: 3px solid black;
color: #000000;
text-decoration: none;
font: Bold 58px/45px Arial;
}
#something {
width: 700px;
height: 300px;
text-align: justify;
margin-top: 200px;
font-size: 30px;
font-weight: bold;
}
article input {
width: 400px;
height: 70px;
background: white;
border-radius: 4px;
text-decoration: none;
text-align: center;
font: Bold 45px/12px Arial;
border-radius: 120;
border-style: none;
padding: 6px;
margin-left: 700px;
}
}
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>DingDog</title>
<link rel="stylesheet" href="css-images/style-contact.css">
</head>
<body>
<header>
<div class="row">
<ul id="logo"> <img src="css-images/dingdog-logo.png"> </ul>
<ul class="main-nav">
<li style="padding-left:10px">PROFILE</li>
<li style="padding-left:10px">MAP</li>
<li style="padding-left:10px">YOUR FRIENDS</li>
<li style="padding-left:10px">MAILBOX</li>
<li style="padding-left:10px" id="sign">LOG OUT</li>
</ul>
</div>
<section>
<article>
<p id="profilesign">Feel free to send us a question.</p>
<img class="left" src="css-images/mial.jpg" style='position:absolute;left:0px; top:0px;' />
<div id="lala">
<p id="centerText">
<label><input type="email" name="email" placeholder="Email" style='margin-top:250px;position:absolute;left:0px; top:0px;' ></label><br/>
<label><input type="name" name="name" placeholder="Name" style="margin-top: 350px; position:absolute;left:0px; top:0px;"></label><br>
<label><input type="subject" name="subject" placeholder='Subject:' style="margin-top: 450px; position:absolute;left:0px; top:0px;"></label><br></p>
<textarea placeholder='Type something' id="something" style="margin-top: 550px; position:absolute;left:0px; top:0px;"></textarea>
</div>
<label id="submit"><input type="submit" name="send" value="Send" style="margin-top: 900px;position:absolute;left:0px; top:0px; background: #2699FB 0% 0% no-repeat padding-box;"></label>
</article>
</section>
</header>
<footer>
<img src="social/instagram.png" />
<img src="social/twitter-white-logo.png" />
<img src="social/facebook.png" />
</footer>
</body>
</html>

Can't center divs HTML CSS

i'm having a small issue getting my divs to sit inline with each other and in the center of the parent div. So I have one parent "page" then 6 other divs inside of that the "pageName" which sits above "bg_01", "bg_02", "bg_03", "bg_04", "bg_05", "bg_06" which all sit inline with each other. However it works when the window is quite small however i'm trying to get it to work when the window is any size, can anyone see where I'm going wrong?
Thanks again guys.
p {
margin: 0;
}
#page {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 200px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
#bg_01 {
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
float: left;
}
#bg_02 {
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
float: left;
}
#bg_03 {
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
float: left;
}
#bg_04 {
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
float: left;
}
#bg_05 {
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
float: left;
}
<div id="page">
<div id="pageName" }>
<p>Colour</p>
</div>
<div id="bg_01">
</div>
<div id="bg_02">
</div>
<div id="bg_03">
</div>
<div id="bg_04">
</div>
<div id="bg_05">
</div>
</div>
Just add text-align: center; to #page and replace float:left; width display: inline-block and it should work.
Something as follows:
<div id="page">
<div id="pageName" }>
<p>Colour</p>
</div>
<div id="bg_01">
</div>
<div id="bg_02">
</div>
<div id="bg_03">
</div>
<div id="bg_04">
</div>
<div id="bg_05">
</div>
</div>
And the css:
p {
margin: 0;
}
#page {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #f00;
width: 100%;
height: 100%;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: center;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
#bg_01 {
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
#bg_02 {
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
#bg_03 {
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
#bg_04 {
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
#bg_05 {
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
Here is the fiddle.
Take away Float: left from your objects and give them display: inline-block.
Also give text-align: center to your parent div
p {
margin: 0;
}
#page {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 200px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: center;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
#bg_01 {
display: inline-block;
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
#bg_02 {
display: inline-block;
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
#bg_03 {
display: inline-block;
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
#bg_04 {
display: inline-block;
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
#bg_05 {
display: inline-block;
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
1) wrap Elments in DIV with class center
<div class="center"> <-------------------
<div id="bg_01">
</div>
<div id="bg_02">
</div>
<div id="bg_03">
</div>
<div id="bg_04">
</div>
<div id="bg_05">
</div>
</div>
2) Remove float: left; and use display:inline block
#bg_01,#bg_02,#bg_03,#bg_04,#bg_05 {
display: inline-block;
float: left;<--------Remove
More code...
}
3) added css For .center :
.center {
text-align: center;
}
Full Code :
p {
margin: 0;
}
#page {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 200px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
#bg_01 {
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
#bg_02 {
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
#bg_03 {
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
#bg_04 {
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
#bg_05 {
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
display: inline-block;
}
.center {
text-align: center;
}
<div id="page">
<div id="pageName">
<p>Colour</p>
</div>
<div class="center">
<div id="bg_01">
</div>
<div id="bg_02">
</div>
<div id="bg_03">
</div>
<div id="bg_04">
</div>
<div id="bg_05">
</div>
</div>
</div>
p {
margin: 0;
}
#page {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: auto;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: center;
}
#page:after {
content: '';
display: table;
clear: both;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
.item {
display: inline-block;
}
#bg_01 {
background-color: #80b3ff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
#bg_02 {
background-color: #afe9af;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
#bg_03 {
background-color: #ffb380;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
#bg_04 {
background-color: #ffaaaa;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
#bg_05 {
background-color: #eeaaff;
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 4%;
}
<div id="page">
<div id="pageName" }>
<p>Colour</p>
</div>
<div id="bg_01" class="item">
</div>
<div id="bg_02" class="item">
</div>
<div id="bg_03" class="item">
</div>
<div id="bg_04" class="item">
</div>
<div id="bg_05" class="item">
</div>
</div>
p {
margin: 0;
}
#page {
border: 2px solid #e1dfe1;
border-radius: 5px;
background-color: #fff;
width: 100%;
height: 200px;
margin-top: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#pageName {
background-color: #f5f0f5;
border-bottom: 2px solid #e1dfe1;
}
#pageName p {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
color: #565656;
font-weight: bold;
}
.center_div{
text-align:center;
margin:20px auto;
display:flex;
justify-content:center;
align-items:center;
}
.common_div{
width: 80px;
height: 80px;
border: 3px solid #666;
border-radius: 20px;
margin: 3%;
display:inline-block;
}
#bg_01 {
background-color: #80b3ff;
}
#bg_02 {
background-color: #afe9af;
}
#bg_03 {
background-color: #ffb380;
}
#bg_04 {
background-color: #ffaaaa;
}
#bg_05 {
background-color: #eeaaff;
}
<div id="page">
<div id="pageName" >
<p>Colour</p>
</div>
<div class="center_div">
<div id="bg_01" class="common_div">
</div>
<div id="bg_02" class="common_div">
</div>
<div id="bg_03" class="common_div">
</div>
<div id="bg_04" class="common_div">
</div>
<div id="bg_05" class="common_div">
</div>
</div>
</div>
Is this the same that you are looking for?
Hope this helps.

How to get hovered images into background ?

#charset "utf-8";
html{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #F2F2F2;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: expresswayregular;
}
#font-face {
font-family: 'expresswayregular';
src: url('fonts/expressway_rg-webfont.woff2') format('woff2'),
url('fonts/expressway_rg-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
#header {
position: fixed;
background: #333333;
width: 100%;
height: 50px;
padding: 0;
margin: 0;
top: 0;
}
#header-content {
background: #333333;
width: 1280px;
height: 50px;
margin-left: auto;
margin-right: auto;
}
#logo {
position: absolute;
}
#currentsite-info font {
position: absolute;
height: 30px;
width: auto;
margin-left: 60px;
padding: 10px;
color: #fff;
font-size: 26px;
}
#search-box {
width: 400px;
height: 50px;
margin-right: auto;
margin-left: auto;
}
#search {
background: #fff;
width: 356px;
height: 16px;
margin-top: 10px;
margin-bottom: 10px;
padding: 6px;
border: 1px solid #fff;
border-radius: 6px 0 0 6px;
}
#submit {
float: right;
background: #fff;
width: 29px;
height: 28px;
margin-top: 10px;
margin-bottom: 10px;
padding: 0;
border-top: 1px solid #fff;
border-right: 1px solid #fff;
border-bottom: 1px solid #fff;
border-radius: 0 6px 6px 0;
}
#menu {
margin-right: 30px;
margin-left: 25px;
z-index: 1000;
}
.menu-linkbox a{
position: static;
float: right;
width: 60px;
height: 14px;
top: 0;
padding: 18px 15px 18px 15px;
color: #F2F2F2;
font-size: 14px;
text-decoration: none;
text-align: center;
}
.menu-linkbox:hover a {
color: #2997D3;
transition: all 500ms;
}
#menu-linkbox-live a {
color: #2997D3;
}
#main-content {
background: #fff;
min-height: 100%;
width: 1280px;
margin: 0 auto;
padding-top: 50px;
overflow: auto;
}
#content-articles {
background: #F2F2F2;
width: 1220px;
bottom: 0;
margin: 20px;
padding: 10px;
border: 1px solid #000;
overflow: auto;
}
#article1 {
width: 550px;
margin: 10px;
float: left;
text-align: justify;
word-spacing: 4px;
}
#article1 h1 {
font-size: 40px;
}
#article1-content {
width: 100%;
}
#photo1 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
}
#photo1:hover {
opacity: 0.8;
}
#article2 {
width: 550px;
margin: 10px;
float: right;
text-align: justify;
word-spacing: 4px;
}
#article2 h1 {
font-size: 40px;
}
#article2-content {
width: 100%;
}
#photo2 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
z-index: -1000;
}
#photo2:hover {
opacity: 0.8;
}
#article3 {
width: 550px;
margin: 60px 10px 10px 10px;
float: left;
text-align: justify;
word-spacing: 4px;
}
#article3 h1 {
font-size: 40px;
}
#article3-content {
width: 100%;
}
#photo3 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
z-index: -1000;
}
#photo3:hover {
opacity: 0.8;
}
#article4 {
width: 550px;
margin: 60px 10px 10px 10px;
float: right;
text-align: justify;
word-spacing: 4px;
}
#article4 h1 {
font-size: 40px;
}
#article4-content {
width: 100%;
}
#photo4 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
z-index: -1000;
}
#photo4:hover {
opacity: 0.8;
}
#imprint {
background: #333333;
bottom: 0;
width: 100%;
}
#imprint-content {
background: #333333;
width: 1280px;
height: 150px;
margin: auto;
}
#about-info {
width: 300px;
height: 130px;
float: left;
margin-left: 20px;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#about-info h2 {
text-align: center;
}
#about-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
#contact-info {
position: static;
width: 300px;
height: 130px;
margin-right: auto;
margin-left: auto;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#contact-info h2 {
text-align: center;
}
#contact-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
#legal-info {
width: 300px;
height: 130px;
float: right;
margin-right: 20px;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#legal-info h2 {
text-align: center;
}
#legal-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
h1 {
color: #2997D3;
font-size: 20px;
text-align: center;
margin-bottom: 20px;
}
p {
margin: 20px;
}
a {
color: #2997D3;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="stylesheet_topics.css">
<link rel="icon" href="images/logo_site.png">
<title>Topics</title>
<script>
function toggleNavPanel(x){
var panel = document.getElementById(x), navarrow = document.getElementById("navarrow"), maxH="300px";
if(panel.style.height == maxH){
panel.style.height = "0px";
navarrow.innerHTML = "▾";
}
else {
panel.style.height = maxH;
navarrow.innerHTML = "▴";
}
}
</script>
</head>
<body>
<div id="header">
<div id="header-content">
<img id ="logo" src="images/logo.png" />
<div id="currentsite-info">
<font>Topics</font>
</div>
<div id="menu">
<div class="menu-linkbox" id="menu-linkbox-breaking">Breaking</div>
<div class="menu-linkbox" id="menu-linkbox-live">Topics</div>
<div class="menu-linkbox" id="menu-linkbox-scene">News</div>
<div class="menu-linkbox" id="menu-linkbox-home">Overview</div>
</div>
<div id="search-box">
<form action="http://www.google.com/search" method="get">
<input id="search" type="text" name="q" placeholder="Search">
<input id="submit" type="image" src="images/search.png" alt="Submit">
</form>
</div>
</div>
</div>
<div id="main-content">
<div id="content-articles">
<div id="article1">
<div id="article1-content">
<h1>Politics</h1>
</div>
<div id="article1-photo">
<img id ="photo1" src="images/footage/topic1adjusted.jpeg" />
</div>
</div>
<div id="article2">
<div id="article2-content">
<h1>Healthcare</h1>
</div>
<div id="article2-photo">
<img id ="photo2" src="images/footage/topic2.jpeg" />
</div>
</div>
<div id="article3">
<div id="article3-content">
<h1>Network</h1>
</div>
<div id="article3-photo">
<img id ="photo3" src="images/footage/topic3adjusted.jpeg" />
</div>
</div>
<div id="article4">
<div id="article4-content">
<h1>Travel</h1>
</div>
<div id="article4-photo">
<img id ="photo4" src="images/footage/topic4adjusted.jpeg" />
</div>
</div>
</div>
</div>
<div id="imprint">
<div id="imprint-content">
<div id="about-info">
<h2>About Us</h2>
<p>
Company information
</p>
</div>
<div id="legal-info">
<h2>Legal Use</h2>
<p>
Copyright information
</p>
</div>
<div id="contact-info">
<h2>Contact</h2>
<p>
Contact information
</p>
</div>
</div>
</div>
</body>
</html>
Hello I have given you a snippet with my current website. It has 4 pictures and a fixed header. When you hover over the picture their opacity is being changed (1->0.8). My problem is that they are also goin over the header... I tried using a z-index but it's not working, any ideas on how to get them behind the header ?
z-index only works on positioned elements
So, I've added position: relative to #photo1 and z-index: 1 to header.
Bonus - added a link to hosted photo instead of the non-working local paths you gave, so you can see it work.
#charset "utf-8";
html{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #F2F2F2;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: expresswayregular;
}
#font-face {
font-family: 'expresswayregular';
src: url('fonts/expressway_rg-webfont.woff2') format('woff2'),
url('fonts/expressway_rg-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
#header {
position: fixed;
background: #333333;
width: 100%;
height: 50px;
padding: 0;
margin: 0;
top: 0;
z-index: 1;
}
#header-content {
background: #333333;
width: 1280px;
height: 50px;
margin-left: auto;
margin-right: auto;
}
#logo {
position: absolute;
}
#currentsite-info font {
position: absolute;
height: 30px;
width: auto;
margin-left: 60px;
padding: 10px;
color: #fff;
font-size: 26px;
}
#search-box {
width: 400px;
height: 50px;
margin-right: auto;
margin-left: auto;
}
#search {
background: #fff;
width: 356px;
height: 16px;
margin-top: 10px;
margin-bottom: 10px;
padding: 6px;
border: 1px solid #fff;
border-radius: 6px 0 0 6px;
}
#submit {
float: right;
background: #fff;
width: 29px;
height: 28px;
margin-top: 10px;
margin-bottom: 10px;
padding: 0;
border-top: 1px solid #fff;
border-right: 1px solid #fff;
border-bottom: 1px solid #fff;
border-radius: 0 6px 6px 0;
}
#menu {
margin-right: 30px;
margin-left: 25px;
z-index: 1000;
}
.menu-linkbox a{
position: static;
float: right;
width: 60px;
height: 14px;
top: 0;
padding: 18px 15px 18px 15px;
color: #F2F2F2;
font-size: 14px;
text-decoration: none;
text-align: center;
}
.menu-linkbox:hover a {
color: #2997D3;
transition: all 500ms;
}
#menu-linkbox-live a {
color: #2997D3;
}
#main-content {
background: #fff;
min-height: 100%;
width: 1280px;
margin: 0 auto;
padding-top: 50px;
overflow: auto;
}
#content-articles {
background: #F2F2F2;
width: 1220px;
bottom: 0;
margin: 20px;
padding: 10px;
border: 1px solid #000;
overflow: auto;
}
#article1 {
width: 550px;
margin: 10px;
float: left;
text-align: justify;
word-spacing: 4px;
}
#article1 h1 {
font-size: 40px;
}
#article1-content {
width: 100%;
}
#photo1 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
position: relative;
}
#photo1:hover {
opacity: 0.8;
}
#article2 {
width: 550px;
margin: 10px;
float: right;
text-align: justify;
word-spacing: 4px;
}
#article2 h1 {
font-size: 40px;
}
#article2-content {
width: 100%;
}
#photo2 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
z-index: -1000;
}
#photo2:hover {
opacity: 0.8;
}
#article3 {
width: 550px;
margin: 60px 10px 10px 10px;
float: left;
text-align: justify;
word-spacing: 4px;
}
#article3 h1 {
font-size: 40px;
}
#article3-content {
width: 100%;
}
#photo3 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
z-index: -1000;
}
#photo3:hover {
opacity: 0.8;
}
#article4 {
width: 550px;
margin: 60px 10px 10px 10px;
float: right;
text-align: justify;
word-spacing: 4px;
}
#article4 h1 {
font-size: 40px;
}
#article4-content {
width: 100%;
}
#photo4 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
z-index: -1000;
}
#photo4:hover {
opacity: 0.8;
}
#imprint {
background: #333333;
bottom: 0;
width: 100%;
}
#imprint-content {
background: #333333;
width: 1280px;
height: 150px;
margin: auto;
}
#about-info {
width: 300px;
height: 130px;
float: left;
margin-left: 20px;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#about-info h2 {
text-align: center;
}
#about-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
#contact-info {
position: static;
width: 300px;
height: 130px;
margin-right: auto;
margin-left: auto;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#contact-info h2 {
text-align: center;
}
#contact-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
#legal-info {
width: 300px;
height: 130px;
float: right;
margin-right: 20px;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#legal-info h2 {
text-align: center;
}
#legal-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
h1 {
color: #2997D3;
font-size: 20px;
text-align: center;
margin-bottom: 20px;
}
p {
margin: 20px;
}
a {
color: #2997D3;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="stylesheet_topics.css">
<link rel="icon" href="images/logo_site.png">
<title>Topics</title>
<script>
function toggleNavPanel(x){
var panel = document.getElementById(x), navarrow = document.getElementById("navarrow"), maxH="300px";
if(panel.style.height == maxH){
panel.style.height = "0px";
navarrow.innerHTML = "▾";
}
else {
panel.style.height = maxH;
navarrow.innerHTML = "▴";
}
}
</script>
</head>
<body>
<div id="header">
<div id="header-content">
<img id ="logo" src="images/logo.png" />
<div id="currentsite-info">
<font>Topics</font>
</div>
<div id="menu">
<div class="menu-linkbox" id="menu-linkbox-breaking">Breaking</div>
<div class="menu-linkbox" id="menu-linkbox-live">Topics</div>
<div class="menu-linkbox" id="menu-linkbox-scene">News</div>
<div class="menu-linkbox" id="menu-linkbox-home">Overview</div>
</div>
<div id="search-box">
<form action="http://www.google.com/search" method="get">
<input id="search" type="text" name="q" placeholder="Search">
<input id="submit" type="image" src="images/search.png" alt="Submit">
</form>
</div>
</div>
</div>
<div id="main-content">
<div id="content-articles">
<div id="article1">
<div id="article1-content">
<h1>Politics</h1>
</div>
<div id="article1-photo">
<img id ="photo1" src="http://www.mtv.com/crop-images/2013/09/11/Foo%20Fighters%20officail.jpg" />
</div>
</div>
<div id="article2">
<div id="article2-content">
<h1>Healthcare</h1>
</div>
<div id="article2-photo">
<img id ="photo2" src="images/footage/topic2.jpeg" />
</div>
</div>
<div id="article3">
<div id="article3-content">
<h1>Network</h1>
</div>
<div id="article3-photo">
<img id ="photo3" src="images/footage/topic3adjusted.jpeg" />
</div>
</div>
<div id="article4">
<div id="article4-content">
<h1>Travel</h1>
</div>
<div id="article4-photo">
<img id ="photo4" src="images/footage/topic4adjusted.jpeg" />
</div>
</div>
</div>
</div>
<div id="imprint">
<div id="imprint-content">
<div id="about-info">
<h2>About Us</h2>
<p>
Company information
</p>
</div>
<div id="legal-info">
<h2>Legal Use</h2>
<p>
Copyright information
</p>
</div>
<div id="contact-info">
<h2>Contact</h2>
<p>
Contact information
</p>
</div>
</div>
</div>
</body>
</html>
I added z-index properties to your #header and #main-content css classes and there is no longer any overlap on hover.
I've also removed the z-index values you set on the images themselves (#photo1 etc) as the z-index set on #main-content applies to them as well, as they are its children.
Hope this helps.
#charset "utf-8";
html{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
background: #F2F2F2;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: expresswayregular;
}
#font-face {
font-family: 'expresswayregular';
src: url('fonts/expressway_rg-webfont.woff2') format('woff2'),
url('fonts/expressway_rg-webfont.woff') format('woff');
font-weight: normal;
font-style: normal;
}
#header {
position: fixed;
background: #333333;
width: 100%;
height: 50px;
padding: 0;
margin: 0;
top: 0;
z-index: 1;
}
#header-content {
background: #333333;
width: 1280px;
height: 50px;
margin-left: auto;
margin-right: auto;
}
#logo {
position: absolute;
}
#currentsite-info font {
position: absolute;
height: 30px;
width: auto;
margin-left: 60px;
padding: 10px;
color: #fff;
font-size: 26px;
}
#search-box {
width: 400px;
height: 50px;
margin-right: auto;
margin-left: auto;
}
#search {
background: #fff;
width: 356px;
height: 16px;
margin-top: 10px;
margin-bottom: 10px;
padding: 6px;
border: 1px solid #fff;
border-radius: 6px 0 0 6px;
}
#submit {
float: right;
background: #fff;
width: 29px;
height: 28px;
margin-top: 10px;
margin-bottom: 10px;
padding: 0;
border-top: 1px solid #fff;
border-right: 1px solid #fff;
border-bottom: 1px solid #fff;
border-radius: 0 6px 6px 0;
}
#menu {
margin-right: 30px;
margin-left: 25px;
z-index: 1000;
}
.menu-linkbox a{
position: static;
float: right;
width: 60px;
height: 14px;
top: 0;
padding: 18px 15px 18px 15px;
color: #F2F2F2;
font-size: 14px;
text-decoration: none;
text-align: center;
}
.menu-linkbox:hover a {
color: #2997D3;
transition: all 500ms;
}
#menu-linkbox-live a {
color: #2997D3;
}
#main-content {
background: #fff;
min-height: 100%;
width: 1280px;
margin: 0 auto;
padding-top: 50px;
overflow: auto;
z-index: -1;
}
#content-articles {
background: #F2F2F2;
width: 1220px;
bottom: 0;
margin: 20px;
padding: 10px;
border: 1px solid #000;
overflow: auto;
}
#article1 {
width: 550px;
margin: 10px;
float: left;
text-align: justify;
word-spacing: 4px;
}
#article1 h1 {
font-size: 40px;
}
#article1-content {
width: 100%;
}
#photo1 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
}
#photo1:hover {
opacity: 0.8;
}
#article2 {
width: 550px;
margin: 10px;
float: right;
text-align: justify;
word-spacing: 4px;
}
#article2 h1 {
font-size: 40px;
}
#article2-content {
width: 100%;
}
#photo2 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
}
#photo2:hover {
opacity: 0.8;
}
#article3 {
width: 550px;
margin: 60px 10px 10px 10px;
float: left;
text-align: justify;
word-spacing: 4px;
}
#article3 h1 {
font-size: 40px;
}
#article3-content {
width: 100%;
}
#photo3 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
}
#photo3:hover {
opacity: 0.8;
}
#article4 {
width: 550px;
margin: 60px 10px 10px 10px;
float: right;
text-align: justify;
word-spacing: 4px;
}
#article4 h1 {
font-size: 40px;
}
#article4-content {
width: 100%;
}
#photo4 {
width: 500px;
height: 500px;
margin: 0px auto;
border: 2px solid #2997D3;
display: block;
transition: all 500ms;
}
#photo4:hover {
opacity: 0.8;
}
#imprint {
background: #333333;
bottom: 0;
width: 100%;
}
#imprint-content {
background: #333333;
width: 1280px;
height: 150px;
margin: auto;
}
#about-info {
width: 300px;
height: 130px;
float: left;
margin-left: 20px;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#about-info h2 {
text-align: center;
}
#about-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
#contact-info {
position: static;
width: 300px;
height: 130px;
margin-right: auto;
margin-left: auto;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#contact-info h2 {
text-align: center;
}
#contact-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
#legal-info {
width: 300px;
height: 130px;
float: right;
margin-right: 20px;
padding: 10px 20px 10px 20px;
vertical-align: middle;
font-size: 18px;
text-align: justify;
color: #fff;
}
#legal-info h2 {
text-align: center;
}
#legal-info p {
margin: 20px;
text-align: center;
vertical-align: middle;
}
h1 {
color: #2997D3;
font-size: 20px;
text-align: center;
margin-bottom: 20px;
}
p {
margin: 20px;
}
a {
color: #2997D3;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="stylesheet_topics.css">
<link rel="icon" href="images/logo_site.png">
<title>Topics</title>
<script>
function toggleNavPanel(x){
var panel = document.getElementById(x), navarrow = document.getElementById("navarrow"), maxH="300px";
if(panel.style.height == maxH){
panel.style.height = "0px";
navarrow.innerHTML = "▾";
}
else {
panel.style.height = maxH;
navarrow.innerHTML = "▴";
}
}
</script>
</head>
<body>
<div id="header">
<div id="header-content">
<img id ="logo" src="images/logo.png" />
<div id="currentsite-info">
<font>Topics</font>
</div>
<div id="menu">
<div class="menu-linkbox" id="menu-linkbox-breaking">Breaking</div>
<div class="menu-linkbox" id="menu-linkbox-live">Topics</div>
<div class="menu-linkbox" id="menu-linkbox-scene">News</div>
<div class="menu-linkbox" id="menu-linkbox-home">Overview</div>
</div>
<div id="search-box">
<form action="http://www.google.com/search" method="get">
<input id="search" type="text" name="q" placeholder="Search">
<input id="submit" type="image" src="images/search.png" alt="Submit">
</form>
</div>
</div>
</div>
<div id="main-content">
<div id="content-articles">
<div id="article1">
<div id="article1-content">
<h1>Politics</h1>
</div>
<div id="article1-photo">
<img id ="photo1" src="images/footage/topic1adjusted.jpeg" />
</div>
</div>
<div id="article2">
<div id="article2-content">
<h1>Healthcare</h1>
</div>
<div id="article2-photo">
<img id ="photo2" src="images/footage/topic2.jpeg" />
</div>
</div>
<div id="article3">
<div id="article3-content">
<h1>Network</h1>
</div>
<div id="article3-photo">
<img id ="photo3" src="images/footage/topic3adjusted.jpeg" />
</div>
</div>
<div id="article4">
<div id="article4-content">
<h1>Travel</h1>
</div>
<div id="article4-photo">
<img id ="photo4" src="images/footage/topic4adjusted.jpeg" />
</div>
</div>
</div>
</div>
<div id="imprint">
<div id="imprint-content">
<div id="about-info">
<h2>About Us</h2>
<p>
Company information
</p>
</div>
<div id="legal-info">
<h2>Legal Use</h2>
<p>
Copyright information
</p>
</div>
<div id="contact-info">
<h2>Contact</h2>
<p>
Contact information
</p>
</div>
</div>
</div>
</body>
</html>