How to make whole Div hoverable - html

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>

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 create side by side layout of an image and label?

I have been trying for a while now and cant seem to achive the bellow design:
.exploreItem {
background-color: #353258;
/* rgba(31, 31, 31, 1) */
border: 1px solid #4152F1;
color: white;
/* padding: 20px 24px; */
cursor: pointer;
width: 90%;
height: 45px;
/* font-size: 15px;
font: Arial;
font-family: sans-serif;
display: block; */
}
.exploreImg {
/* background-color: lightblue; */
display: inline-block;
vertical-align: top;
height: 30px;
/* width: 10px; */
padding-left: 10px;
}
.exploreLabel {
/* vertical-align: middle; */
/* background-color: grey; */
display: inline-block;
font-size: 15px;
font: Arial;
font-family: sans-serif;
/* width: 10px; */
margin-top: 0px;
}
<div class="exploreItem" id="exploreItem">
<img class="exploreImg" src="images/defaultProfImg.png">
<label class="exploreLabel">Explore</label>
</div>
How can I create the intended design layout? (An image next to the explore label like in the image)
You even don't need the image just use css to do it. And even if you use image you can use display: flex for .exploreItem and align-items: center can do the magic.
I had put down the simpler css only solution here with :before pseudo element.
.exploreItem {
background-color: #353258;
border: 1px solid #4152F1;
color: white;
cursor: pointer;
padding: 16px;
width: 90%;
border-radius: 32px;
}
.exploreLabel {
display: flex;
align-items: center;
font-size: 15px;
font: Arial;
font-family: sans-serif;
margin-top: 0px;
}
.exploreLabel:before {
content: '';
height: 28px;
width:28px;
background-color: #4152F1;
border: 1px solid #a89dff;
display: block;
margin-right: 16px;
border-radius: 50%;
}
<div class="exploreItem" id="exploreItem">
<label class="exploreLabel">Explore</label>
</div>
.wrapper {
width: 200px;
}
.exploreItem {
width: 100%;
display: flex;
background: transparent;
padding: 20px 30px;
border: 1px solid transparent;
border-radius: 50px;
align-items: center;
cursor: pointer;
}
.exploreItem label {
color: #919191;
}
.exploreItem.active {
display: flex;
background: #2F2D50;
border: 1px solid #483EF1;
}
.exploreItem.active label {
color: #ffffff;
}
.exploreItem i {
display: block;
background: #A3A3A3;
border: 1px solid transparent;
width: 25px;
height: 25px;
border-radius: 50px;
margin-right: 10px;
}
.exploreItem.active i {
background: #483EF1;
border: 1px solid #A5A0FF;
}
<div class="wrapper">
<div class="exploreItem active">
<i></i>
<label class="exploreLabel">Explore</label>
</div>
<div class="exploreItem">
<i></i>
<label class="exploreLabel">Explore</label>
</div>
</div>
Use below code:
HTML:
<div class="outer">
<div class="round"></div>
<label>
<span>Explore</span>
</label>
</div>
CSS:
.outer
{
background: #353258;
border: 1.5px solid #4152F1;
color: white;
padding: 7px 8px;
cursor: pointer;
width: 150px;
height:33px;
border-radius: 30px;
cursor: pointer;
}
.round
{
background: #502ffb;
height: 28px;
width: 28px;
display: inline-block;
border: 1px solid white;
border-radius: 50%;
}
label
{
color: white;
display: inline-block;
cursor: pointer;
}
label span
{
position: absolute;
margin-top: -24px;
margin-left: 3px;
font-size: 17px;
}

CSS\HTML Responsive flexbox

I have been working on developing my own webpage, and for the home page I wanted a nice looking banner with 3 tiles (1 big one left with 2 smaller ones stacked on top of eachother right).
I could get this all to work fine, but I now noticed that on mobile devices this really gets out of proportion, and I wanted to make the 3 tiles all on top of each other when the width of the screen gets less than let's say 300px.
However, I can not seem to get this to work by looking at other questions on stackoverflow, only tiles start to disappear
Example view of what I wish to accomplish
#media only screen and (min-width: 300px) {
.hero {
height: 400px;
width: 80%;
margin-left: auto;
margin-right: auto;
display: flex;
position: relative;
}
.left {
float: left;
width: 80%
}
.right {
float: left;
width: 80%
}
}
#media only screen and (min-width: 600px) {
.hero {
height: 400px;
width: 90%;
margin-left: auto;
margin-right: auto;
display: flex;
position: relative;
}
}
.left {
background-image: url('http://via.placeholder.com/1600x1200');
background-size: cover;
flex: 1;
}
.left:hover {
opacity: 0.8;
}
.left:hover .btnLeft {
color: white;
background-color: orange;
border: 1px solid orange;
}
.right {
display: flex;
margin-left: 5px;
flex-direction: column;
flex: 0 0 40%;
}
.one {
height: 175px;
background-image: url('http://via.placeholder.com/380x260');
background-size: cover;
flex: 80%;
}
.one:hover {
opacity: 0.8;
}
.one:hover .btnTop {
color: white;
background-color: orange;
border: 1px solid orange;
}
.two {
height: 175px;
margin-top: 5px;
background-image: url('http://via.placeholder.com/380x260');
background-size: cover;
flex: 50%;
}
.two:hover {
opacity: 0.8;
}
.two:hover .btnBot {
color: white;
background-color: orange;
border: 1px solid orange;
}
.btnLeft {
margin-top: 300px;
background-color: white;
color: black;
border: 1px solid black;
border-radius: 2px;
padding: 3px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 30px;
font-family: 'Titillium Web', sans-serif;
font-weight: normal;
text-transform: capitalize;
}
.btnTop {
margin-top: 140px;
background-color: white;
color: black;
border: 1px solid black;
border-radius: 2px;
padding: 2px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 25px;
font-family: 'Titillium Web', sans-serif;
font-weight: normal;
text-transform: capitalize;
}
.btnBot {
margin-top: 140px;
background-color: white;
color: black;
border: 1px solid black;
border-radius: 2px;
padding: 2px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 25px;
font-family: 'Titillium Web', sans-serif;
font-weight: normal;
text-transform: capitalize;
}
<div class="hero">
<a href="http://example.com" class="left" >
<div class="btnLeft">Option 1</div>
</a>
<div class="right">
<a href="http://example.com" class="one" >
<div class="btnTop">Option 2</div>
</a>
<a href="http://example.com" class="two" >
<div class="btnBot">Option 3</div>
</a>
</div>
</div>
This is an easy effect to achieve using flexbox. On your smallest size screens give the .hero container a property of flex-direction:column to have them stack vertically. Once you hit your bigger breakpoint, change this to flex-direction:row.
Also, it's worthwhile to note that you don't need to add a float property to the .left and .right containers as this isn't how flexbox functions.
For a pretty in depth look of how flexbox works check out this link.
#media only screen and (min-width: 300px) {
.hero {
height: 400px;
width: 80%;
margin-left: auto;
margin-right: auto;
display: flex;
position: relative;
flex-direction:column;
}
}
#media only screen and (min-width: 600px) {
.hero {
height: 400px;
width: 90%;
margin-left: auto;
margin-right: auto;
display: flex;
position: relative;
flex-direction:row;
}
}
.left {
background-image: url('http://via.placeholder.com/1600x1200');
background-size: cover;
flex: 1;
}
.left:hover {
opacity: 0.8;
}
.left:hover .btnLeft {
color: white;
background-color: orange;
border: 1px solid orange;
}
.right {
display: flex;
margin-left: 5px;
flex-direction: column;
flex: 0 0 40%;
}
.one {
height: 175px;
background-image: url('http://via.placeholder.com/380x260');
background-size: cover;
flex: 80%;
}
.one:hover {
opacity: 0.8;
}
.one:hover .btnTop {
color: white;
background-color: orange;
border: 1px solid orange;
}
.two {
height: 175px;
margin-top: 5px;
background-image: url('http://via.placeholder.com/380x260');
background-size: cover;
flex: 50%;
}
.two:hover {
opacity: 0.8;
}
.two:hover .btnBot {
color: white;
background-color: orange;
border: 1px solid orange;
}
.btnLeft {
margin-top: 300px;
background-color: white;
color: black;
border: 1px solid black;
border-radius: 2px;
padding: 3px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 30px;
font-family: 'Titillium Web', sans-serif;
font-weight: normal;
text-transform: capitalize;
}
.btnTop {
margin-top: 140px;
background-color: white;
color: black;
border: 1px solid black;
border-radius: 2px;
padding: 2px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 25px;
font-family: 'Titillium Web', sans-serif;
font-weight: normal;
text-transform: capitalize;
}
.btnBot {
margin-top: 140px;
background-color: white;
color: black;
border: 1px solid black;
border-radius: 2px;
padding: 2px 10px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 25px;
font-family: 'Titillium Web', sans-serif;
font-weight: normal;
text-transform: capitalize;
}
<div class="hero">
<a href="http://example.com" class="left" >
<div class="btnLeft">Option 1</div>
</a>
<div class="right">
<a href="http://example.com" class="one" >
<div class="btnTop">Option 2</div>
</a>
<a href="http://example.com" class="two" >
<div class="btnBot">Option 3</div>
</a>
</div>
</div>

Div not inline when window gets smaller?

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>

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.