for some reason I am having one heck of a time trying to figure out how to center this silly pricing table in my page using css. Each table has a width of 40%, I've already tried changing the left and right margin to auto using CSS but with no success.
Here is the HTML:
<div id="pricing-table" class="pricing-table">
<ul>
<li class="heading">Bronze</li>
<li class="price">£20</li>
<li>Starter package</li>
<li>15 Projects</li>
<li class="action">Buy Now</li>
</ul>
<ul class="feature">
<li class="heading">Silver</li>
<li class="price">£60</li>
<li>Intermediate package</li>
<li>20 Projects</li>
<li class="action">Buy Now</li>
</ul>
</div>
Here is the CSS:
.pricing-table ul{
border-width: 1px;
border-style: solid;
border-color: #CCCCCC;
border-radius: 4px;
margin: 2px;
width: 40%;
text-align: center;
font-family: 'Arial';
list-style: none;
float: left;
padding: 5px;
background-color: #FFFFFF;
}
.pricing-table ul:hover{
-webkit-transform: scale(1.1);
transform: scale(1.1);
box-shadow: 3px 5px 7px rgba(0,0,0,.7);
}
.pricing-table ul li{
padding: 10px;
background-color: #FFFFFF;
border-width: 0px;
border-style: dotted;
border-color: #CCCCCC;
border-radius: 4px;
border-bottom-width: 1px;
font-size: 15px;
}
.pricing-table li:first-child{
border-bottom: 0;
}
.pricing-table li:last-child{
border-bottom: 0;
}
.pricing-table li:nth-child(odd){
background-color: #FFFFFF;
}
.pricing-table ul .heading{
color: #FFFFFF;
background-color: #5091B2;
font-size: 30px;
}
.pricing-table ul .price{
color: #636363;
background-color: #FFFFFF;
font-size: 25px;
}
.pricing-table ul .action{
font-size: 20px;
background-color: #ffffff;
color: #6C9694;
}
.pricing-table .action a{
border-color: #CCCCCC;
border-width: 1px;
border-radius: 4px;
background-color: #E9F7FE;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 100px;
padding-right: 100px;
border-style: solid;
color: #5091B2;
}
I'd like to thank everyone in advance for any help you may provide.
And here's a fiddle for what I have so far.
The <ul> elements are floated to left. In order to align the items horizontally, you could set a proper width on .pricing-table then use margin: 0 auto;
Mind the margins. you have to include the margin of <ul> elements for calculating the width of the .pricing-table element.
However, to get rid of specifying an explicit width for .pricing-table, you could change the display type of the ul elements to inline-block and align the inline elements by using text-align: center; for their parent as follows:
.pricing-table {
text-align: center; /* <-- align the inline(-block) elements horizontally */
}
.pricing-table ul {
display: inline-block; /* <-- display the ul elements as inline-block */
vertical-align: top; /* <-- keep the inline(-block) elements at the top */
/* other styles here... */
}
Working Demo.
There's also a white space between inline-block elements, you might want to consider removing that.
You can also remove the margins from <ul> elements, instead of removing the white space between them.
Updated Demo
Your choice :)
Try to do this:
.pricing-table{
width: 80%;
margin: auto;
}
Or any width you want.
Fiddle Demo
If you can define width in body, then do in CSS as :
body {
width :900px;
margin:auto;
}
Have you tried this? fiddle here
#pricing-table{
width:80%;
margin: auto;
}
Maybe you should add this to your CSS:
body{
text-align:center;
margin:0 auto;
padding:0 auto;
}
.pricing-table {
text-align:center;
margin:0 auto;
padding:0 auto;
width:40%;
}
.pricing-table ul{
border-width: 1px;
border-style: solid;
border-color: #CCCCCC;
border-radius: 4px;
margin: 2px;
width: 100%; //40% is now 100%
text-align: center;
font-family: 'Arial';
list-style: none;
float: left;
padding: 5px;
background-color: #FFFFFF;
}
Try including this; a fiddle
.pricing-table{
disply:block;
margin-right: auto;
margin-left:auto;
border:1px solid black; //just extra
width:80%; //need to define width to be able to center
}
Try the following CSS if you want them in the middle of the whole screen (centered), with some spacing between the two <ul> elements. Just added a body declaration and changed the margin in .price-table ul, just something different.
body {
width:900px;
margin:auto;
padding-top:150px
}
.pricing-table ul {
border-width: 1px;
border-style: solid;
border-color: #CCCCCC;
border-radius: 4px;
margin:30px;
width: 40%;
text-align: center;
font-family: 'Arial';
list-style: none;
float: left;
padding: 5px;
background-color: #FFFFFF;
}
.pricing-table ul:hover {
-webkit-transform: scale(1.1);
transform: scale(1.1);
box-shadow: 3px 5px 7px rgba(0,0,0,.7);
}
.pricing-table ul li {
padding: 10px;
background-color: #FFFFFF;
border-width: 0px;
border-style: dotted;
border-color: #CCCCCC;
border-radius: 4px;
border-bottom-width: 1px;
font-size: 15px;
}
.pricing-table li:first-child{
border-bottom: 0;
}
.pricing-table li:last-child{
border-bottom: 0;
}
.pricing-table li:nth-child(odd) {
background-color: #FFFFFF;
}
.pricing-table ul .heading {
color: #FFFFFF;
background-color: #5091B2;
font-size: 30px;
}
.pricing-table ul .price {
color: #636363;
background-color: #FFFFFF;
font-size: 25px;
}
.pricing-table ul .action {
font-size: 20px;
background-color: #ffffff;
color: #6C9694;
}
.pricing-table .action a {
border-color: #CCCCCC;
border-width: 1px;
border-radius: 4px;
background-color: #E9F7FE;
padding-top: 4px;
padding-bottom: 4px;
padding-left: 100px;
padding-right: 100px;
border-style: solid;
color: #5091B2;
}
Related
Live example: https://jsfiddle.net/qnx8btw5/
The <li> in my navbar-container are moving while I hover over the other elements. How do I stop this from happening?
I know that I could set the size while hovering to a size that would stop this from happening, but in my opinion that is not the best solution to this problem.
I think this happen because you set border-bottom when you hover on your list-item.
you can set transparent border by default to your list item like below
#navbar-container ul li{
border-bottom:3px solid transparent;
}
using this your your navbar will not move.
It happening due to border adding on hover. Just set border with transparent color to element <li> default.
Result
https://jsfiddle.net/kwvLuxgs/
Add the same border which you have on hover as a transparent border by default. With this the styling doesn't get changed between "default" and hover.
I made this to you css and it stopped moving.
li {
float: left;
color: $ColorStandard;
text-align: center;
margin-left: 12.5px;
margin-right: 12.5px;
margin-bottom: 12.5px;
margin-top: 12.5px;
font-size: $FontSizeMedium;
text-decoration: none;
cursor: pointer;
a {
text-decoration: none;
color: $ColorStandard;
&:hover {
border-bottom-color: $ColorStandard;
border-bottom-style: solid;
border-bottom-width: 3px;
}
}
add border bottom in li
css.
$DefaultFont: "Roboto", "Open Sans";
$ColorStandard: #212121;
$ColorSubordinate: #A7ADB6;
$FontSizeMedium: 13.5pt;
#header-container {
position: absolute;
top: 0;
z-index: 999;
margin-top: 0;
background-color: white;
}
#navbar-container {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: $ColorSubordinate;
border-top-width: 1px;
border-top-style: solid;
border-top-color: $ColorSubordinate;
ul {
list-style: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
li {
float: left;
color: $ColorStandard;
text-align: center;
margin-left: 12.5px;
margin-right: 12.5px;
margin-bottom: 12.5px;
margin-top: 12.5px;
border-bottom:3px solid transparent;
font-size: $FontSizeMedium;
text-decoration: none;
cursor: pointer;
a {
text-decoration: none;
color: $ColorStandard;
}
&:hover {
border-bottom-color: $ColorStandard;
border-bottom-style: solid;
border-bottom-width: 3px;
width:100px;
}
}
}
}
#data-container {
margin-top: 20px;
z-index: 1;
}
It is hard to learn "float" "overflow" "clear" and some other properties so please help me find good online websites to learn these properties ..
I opened some websites to make designs like them I found http://wix.com I admired its nav bar so i tried to make like it but i had a problem when mouse is over the il it is pushed down to show the top border how can I fix that
thanks and I am sorry for my weak English
body {
background-color: lightblue;
}
ul {
position: fixed;
list-style-type: none;
overflow: hidden;
top: 0px;
right: 0px;
width: 100%;
margin: 0px;
padding: 0px;
padding-top: 8px;
padding-bottom: 8px;
display: block;
background-color: #666666;
transition:background-color, 1s;
}
ul:hover {
background-color: #333;
}
il {
transition:border-top,1s;
float: left;
padding-right: 10px;
border-right: 1px solid white;
}
il:hover {
border-top:5px solid lightblue;
}
#navl {
font-family: Trebuchet MS’, Helvetica, sans-serif;
letter-spacing: 3px;
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
pre{
font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace;
letter-spacing: 2px;
font-size: 30px;
text-align: center;
color: white;
margin-top: 150px;
}
#plans:link, #plans:visited {
background-color: white;
color: black;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: block;
border: 1px solid white;
border-radius: 30px;
margin: auto;
width: 110px;
padding-top: 20px;
padding-bottom: 20px;
font-size:20px;
font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace;
}
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<ul>
<il><a id="navl" href="index.html">Home</a></il>
<il><a id="navl" href="Plans.html">Plans</a></il>
<il><a id="navl" href="About.html">About</a></il>
<il><a id="navl" href="Contact.html">Contact Us</a></il>
</ul>
<pre>test</pre>
<a id="plans" href="plans.html">Plans</a>
</body>
</html>
The reason this happens is because the border adds height to the element. To correct it, you can either remove height from the main element or shift it up:
li:hover {
margin-top: -5px; //shifts the element up 5px
}
or you can have an invisible border as Teuta mentions that gets "covered up" by the new border.
At first, replace those il with li, and add this style to your li:
li {
border-top: 5px solid transparent;
}
And in ul, instead of padding-top:8px add padding-top:3px.
Here is the link with a little work around I did. I removed the padding top in ul. Changed the il to li. Because actually it is 'li' not 'il'. And I added a border top in li.
Here is the css code I changed.
ul:hover {
background-color: #666666;
}
li {
transition:border-top,1s;
float: left;
padding-right: 10px;
border-right: 1px solid white;
border-top:5px solid #666666;
}
li:hover {
border-top:5px solid lightblue;
}
https://jsfiddle.net/7x7dy3jt/
I tried to round the corners on this div box that I created and it doesn't work. Tested this out on Chrome, IE, Firefox and no go. I am not too fluent in CSS and DIV. So if you can see my problem, please help me.
Code CSS:
.side-nav-menu{
width: 100%;
border-radius: 10px;
}
.side-nav-menu h1{
font-size: 1.1em;
font-weight:bold;
color: white;
background: #3F5671;
margin-bottom: 0;
padding: 7px 0 7px 7px;
}
.side-nav-menu ul{
list-style-type: none;
margin: 0;
padding: 0;
border-left: 1px solid #c0c0c0;
border-right: 1px solid #c0c0c0;
margin-bottom: 0;
}
.side-nav-menu ul li{
padding-bottom: 0px;
border-bottom: 1px solid #c0c0c0;/
}
.side-nav-menu ul li a{
font-size: normal 1.1em;
font-weight:bold;
color: #777777;
background: #ffffff;
display: block;
padding: 5px 0;
line-height: 17px;
padding-left: 7px;
text-decoration: none;
}
.side-nav-menu ul li a:hover{
color: #777777;
background: #F7F7F7;
}
HTML
<div class="side-nav-menu">
<h1>Sub-Categories</h1>
<ul>
<li>Air Sampling Pumps</li>
<li>Dust Monitors</li>
<li>Flame Ionization Detectors</li>
<li>Photoionization Detectors</li>
<li>Ventilation Blower</li>
</ul>
</div>
https://jsfiddle.net/pssz0xv0/
Child elements wont inherit round corners from their parents. You will have to apply a border radius to the top element 'h1' and bottom element, the last 'a'.
https://jsfiddle.net/pssz0xv0/5/
.side-nav-menu h1{
border-radius:10px 10px 0 0;
}
.side-nav-menu ul li:last-child a{
border-radius: 0 0 10px 10px;
}
border-radius: 10px
On .side-nav-menu ?
.side-nav-menu{
width: 100%;
border-radius: 10px;
overflow: hidden;
}
.side-nav-menu h1{
font-size: 1.1em;
font-weight:bold;
color: white;
background: #3F5671;
//margin-bottom: 0;
margin: 0;
padding: 7px 0 7px 7px;
}
https://jsfiddle.net/alireza_safian/pssz0xv0/9/
Essentially, I'm trying to get the entire box to be a link and when you hover over it, the entire box also changes colors. I know this is easily done if I write separate code for each "li" tag but that would be timely. Is there something I'm doing wrong?
Here is my code:
.genrelist li {
float: left;
text-transform: uppercase;
font-weight: bolder;
list-style-type: none;
text-align: center;
width: 150px;
height: 150px;
margin: 50px;
background: #fff;
margin: 15px;
border-style: solid;
border-width: 5px;
border-color: #000;
}
.genrelist li:hover {
float: left;
list-style-type: none;
text-align: center;
width: 150px;
height: 150px;
background: #000;
margin: 15px;
border-style: solid;
border-width: 5px;
border-color: #000;
}
<ul>
<li><span>Fiction Short Stories</span></li>
<li><span>Non-Fiction Short Stories</span></li>
<li><span>Comic Strips</span></li>
<li><span>Poetry</span></li>
<li><span>Biblical</span></li>
<li><span>Inspirational</span></li>
<li><span>Children's Corner</span></li>
<li><span>Comedy</span></li>
<li><span>Drama</span></li>
<li><span>Chiller</span></li>
<li><span>Romance</span></li>
<li><span>Science Fiction</span></li>
<li><span>Memoirs</span></li>
<li><span>In The Feathers</span></li>
</ul>
They all work when you hover over the word, but only the first item works when you hover over any part of it's box. Any help is appreciated!
a needs to be wrapped into li to valid your HTML structure, then displayed as block.
A pseudo element can be used to help vertical-align your span.
display:flex; could be used too to center a content.
Demo using pseudo-element
li {
float: left;
text-transform: uppercase;
font-weight: bolder;
list-style-type: none;
text-align: center;
width: 150px;
height: 150px;
margin: 50px;
background: #fff;
margin: 15px;
border-style: solid;
border-width: 5px;
border-color: #000;
}
li:hover {
list-style-type: none;
text-align: center;
width: 150px;
height: 150px;
background: #000;
margin: 15px;
border-style: solid;
border-width: 5px;
border-color: #000;
}
li a {
display:block ;
height:100%;
width:100%;}
a:before {
content:'';
display:inline-block;
vertical-align:middle;
height:100%;
}
a span {
display:inline-block;
max-width:99%;
}
<ul>
<li><span>Fiction Short Stories</span></li>
<li><span>Non-Fiction Short Stories</span></li>
<li><span>Comic Strips</span></li>
<li><span>Poetry</span></li>
<li><span>Biblical</span></li>
<li><span>Inspirational</span></li>
<li><span>Children's Corner</span></li>
<li><span>Comedy</span></li>
<li><span>Drama</span></li>
<li><span>Chiller</span></li>
<li><span>Romance</span></li>
<li><span>Science Fiction</span></li>
<li><span>Memoirs</span></li>
<li><span>In The Feathers</span></li>
</ul>
I have created a vertical menu and would like it to have a right red border on hover and selected item.
However, I can't seem to get it correct on hovering as my li border bottom seems to mess up the hover state. The bottom border slightly overlaps the right border.
Here is the code in a fiddle.
http://jsfiddle.net/4KBE4/1/
HTML:
<div class="messaging">
<div class="sideMenu">
<ul class="messagesMenu">
<li class="selected">Inbox<span>14</span></li>
<li>Outbox</li>
<li>Address Book</li>
<li>Trash</li>
</ul>
</div>
<div class="messagesWrapper">
</div>
</div>
CSS:
.messaging {
width: 500px;
margin-bottom: 20px;
}
.sideMenu {
display: inline-block;
width: 200px;
float: left;
}
.messagesWrapper {
background: honeydew;
width: 300px;
height: 200px;
float: right;
min-height: 500px;
}
.messagesMenu {
background: #FFF;
padding-bottom: 20px;
}
.messagesMenu li {
padding: 5px;
border-top: 1px solid #d4d4d4;
height: 3em;
display: block;
position: relative;
border-right: 5px solid #d4d4d4;
}
.messagesMenu li:first-child { border-top: none; }
.messagesMenu li:last-child { border-bottom: 1px solid #d4d4d4; }
.messagesMenu li a {
line-height: 3em;
font-size: 1em;
text-transform: uppercase;
text-decoration: none;
padding-left: 5px;
color: #c4c4c4;
cursor: pointer;
}
.messagesMenu li a span {
color: #FFF;
font-size: 1em;
text-transform: uppercase;
text-decoration: none;
background: #999;
border-radius: 5px;
margin-left: 100px;
padding: 2px 6px;
}
.messagesMenu li:hover { border-right-color: #ed1c24; }
.messagesMenu li.selected {
border-right-color: #ed1c24;
border-bottom: none;
}
.messagesMenu li.selected a { color: #2f3239; }
.clearfix { zoom: 1; }
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
Hope someone can help! Thanks :)
Give the links display: block, remove their width: 100%, remove the padding, the height and the horizontal borders from the li and add them on the links.
demo
.messagesMenu li { border-right: 5px solid #d4d4d4; }
.messagesMenu li:first-child a { border-top: none; }
.messagesMenu li:last-child a { border-bottom: 1px solid #d4d4d4; }
.messagesMenu li a {
display: block;
line-height: 3em;
font-size: 1em;
text-transform: uppercase;
text-decoration: none;
color: #c4c4c4;
cursor: pointer;
height: 3em;
padding: 5px 5px 5px 10px;
border-top: 1px solid #d4d4d4;
}