Use table-cell to fill rest of div - html

I'm trying to make a table where the final column of the table fills the rest of the table.
I'm using divs to design the table and using the borders of the div to make the borders between each element, but if you look at my link http://subjectplanner.co.uk/Me/test.php, you can see that the last elements don't fill the end of the table resulting in the border falling short.
CSS
.Larger{
font-size: 125%;
}
.Smaller{
font-size: 85%;
}
.Block{
display: block;
}
.TodayList{
font-family:'Proxima Nova',Helvetica,Arial,sans-serif;
display:table;
width:100%;
margin:0 0 1em 0;
-webkit-border-radius:15px;
border-radius:15px;
overflow:hidden;
border:0 none;
border-collapse:collapse;
background-color:#247B2B;
font-size:1.5em;
position:relative;
padding:0;
}
.TodayItem{
position:relative;
display:table-row;
border-collapse:collapse;
overflow:hidden;
color:#70BB75;
-webkit-transition:background-color 0.2s linear;
-moz-transition:background-color 0.2s linear;
-o-transition:background-color 0.2s linear;
-ms-transition:background-color 0.2s linear;
transition:background-color 0.2s linear;
background-color:rgba(0,0,0,0.001);
}
.TodayItem:hover{
background-color:#95FA9D;
}
.TodayItem a{
color:#fff;
}
.TodayItem .smaller,.TodayItem .TodayInfo{
color:#fff;
}
.TodayItemWrapper{
display:block;
position:relative;
overflow:hidden;
height:100%;
width:100%;
}
.TodayIcon,.TodayTitle,.TodayInfo{
display:table-cell;
border-collapse:collapse;
border:1px solid #31AE33;
border-width:0 1px 1px 0;
padding:2em;
margin:0;
font-size:100%;
min-height:120px;
font-weight:normal;
}
.TodayItem:last-of-type .TodayIcon,.TodayItem:last-of-type .TodayTitle,.TodayItem:last-of-type .TodayInfo{
border-bottom-width:0;
}
.TodayIcon{
width:130px;
vertical-align:middle;
text-align:center;
}
.TodayTitle{
width:260px;
}
.TodayInfo{
border-right-width:0;
}
.TodayTitle a{
text-decoration:none;
}
.TodayTitle a:hover{
text-decoration:underline;
}
.TodayLink{
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
background-color:rgba(0,0,0,0.001);
vertical-align:top;
z-index:2;
}
HTML
<ul class="TodayList">
<li class="TodayItem">
<div class="TodayItemWrapper">
<span class="TodayIcon"></span>
<h3 class="TodayTitle">
Monday<span class="TodayLink"></span> <span class="Block Smaller">You've 3 lessons today</span>
</h3>
<div class="TodayInfo">
<ul>
<li>9 - 10: Maths</li>
<li>10 - 11: English</li>
<li>12 - 13: ICT</li>
</ul>
</div>
</div>
</li>
<li class="TodayItem">
<div class="TodayItemWrapper">
<span class="TodayIcon"></span>
<h3 class="TodayTitle">
Tuesday<span class="TodayLink"></span> <span class="Block Smaller">You've 2 lessons on this day</span>
</h3>
<div class="TodayInfo">
<ul>
<li>10 - 11: Art</li>
<li>11 - 13: Double Business</li>
</ul>
</div>
</div>
</li>
</ul>
Here's a fiddle if you want it http://jsfiddle.net/tR7WX/

Simply add this rule to your style:
ul.TodayList>li:last-child {
width:100%;
}
Btw, you're not obliged to have a class for every level of tag. You can user CSS node rules to select specific tag and apply style. Should you go for it, you get a simpler (and lighter) HTML file.

Is there a specific reason why you're not using a table for this? I know tables are often seen as old school, but you've got table data here and scenario that requires table logic. I think to use DIVs and CSS to replicate tables would be complex and difficult to change/maintain and make it quite fragile.
Another possible solution would be to not use table-cell at all and instead use DIVs with percentage widths, so they always fill the total width. You could then have a container inside each DIV with display:table to vertically centre the content.
Sorry if I've misunderstood anything.

Related

Fix elements so only the one hovered over extends?

I currently have a top menu consisting of four div's: Home, Menu, Order, and Review. I have set it so that each div extends 100px when hovered over. Everything worked fine at this point. I then added some words and an image within each of the div's extended area. Now whenever I hover over any of the div's, it extends, but it carry's the rest of the div's with it. I want it so that only the div I am hovering over will extend and the rest will remain where they were. Here's the html:
<div class="TopNav">
<a href="file:///C:/Users/Justin/SkyDrive/Documents/Websites/Snack%20Shack%202/SS2.html"><div class="Home">
<h4>Home</h4> <br><br>
<p>Learn about us!</p>
<img class="Hamburger" src="http://i.imgur.com/0htcpM2.png" title="source: imgur.com" />
</div></a>
<a href="file:///C:/Users/Justin/SkyDrive/Documents/Websites/Snack%20Shack%202/SS2%20Menu.html"><div class="Menu">
<h4>Menu</h4>
</div></a>
<a href="file:///C:/Users/Justin/SkyDrive/Documents/Websites/Snack%20Shack%202/SS2%20Order.html"><div class="Order">
<h4>Order</h4>
</div></a>
<a href="file:///C:/Users/Justin/SkyDrive/Documents/Websites/Snack%20Shack%202/SS2%20Review.html"><div class="Review">
<h4>Review</h4>
</div></a>
</div>
Here's the css:
.Home:hover, .Menu:hover, .Order:hover, .Review:hover{
height: 150px;
}
.Home, .Menu, .Order, .Review {
height:50px;
width:100px;
display:inline-block;
position:relative;
z-index:1;
transition: height .5s ease-in-out;
-webkit-transition: height .5s ease-in-out;
overflow:hidden;
}
.Home p, .Menu p, .Order p, .Review p {
text-align:right;
color:white;
position:relative;
right:2px;
bottom:5px;
}
.Home h4, .Menu h4, .Order h4, .Review h4 {
text-align:center;
color:white;
position:relative;
bottom:5px;
font-family:Garamond;
}
.Hamburger {
height:40px;
width:auto;
position:relative;
left:50px;
top:10px;
display:inline-block;
}
Does anyone know how to fix this?
add vertical-align: top; to .Home, .Menu, .Order, .Review
inline-block element aligns to the bottom of the highest element by taking vertical-align: baseline; as default but you can align it to the top by adding vertical-align:top
demo - http://jsfiddle.net/hsj2ebc2/1/

css transitions pushing elements

i am trying to make a new menu for my site and i'm using transitions on highlight.
but i am getting some issues with elements being pushed around. for example if you highlight Home it will push all elements to right of it.
however if there are 2 lines it will not push the element down. instead it will just mask it. how can i make sure each element has it's own dedicated space and not be pushed and also not be masked.
I tried making an absolute with an inner relative but that didn't work.
http://jsfiddle.net/yg68cnnt/
Html:
<ul>
<li> Home </li>
<li> About </li>
<li> FAQ </li>
<li> Locations </li>
<li> StackOverflow </li>
</ul>
CSS:
ul{
list-style-type:none;
position:absolute;
}
li{
display:inline;
transition: all 2s;
width:0px;
position:relative;
margin-right:3em;
padding-top:10px;
padding-right:30px;
padding-left:4px;
}
li:hover{
background-color:red;
border-right:20px solid black;
border-bottom:20px solid black;
border-bottom-right-radius:10px;
border-top-left-radius:10px;
}
If you want the border to grow, you can trick it by using css3 box-shadow with blur set to 0 instead of using border, because shadow does not cause the element itself to grow.
li:hover{
background-color:red;
box-shadow: 10px 10px 0 10px black;
border-bottom-right-radius:10px;
border-top-left-radius:10px;
}
(Note that it is probably a hack and not the most correct way to solve your problem. It sort of works though.)
Vertical space between items can be achieved by setting display to inline-block and setting margin-bottom:
li{
display:inline-block;
margin-bottom:2em;
transition: all 2s;
position:relative;
margin-right:3em;
padding-top:10px;
padding-right:30px;
padding-left:4px;
}
updated jsFiddle
You could set a transparent border on the non-hover state like this:
li {
display:inline;
transition: all 2s;
width:0px;
position:relative;
margin-right:3em;
padding-top:10px;
padding-right:30px;
padding-left:4px;
border-right:20px solid transparent;
border-bottom:20px solid transparent;
}
jsFiddle example

The tops of these links aren't working, how can I get the link inside just the buttons?

The top part of the five links on the right aren't clickable. How can I get the link to be active throughout the entire button?
Also, how would I make it so that when I hover over the links, the background color still changes as it currently does but has an opacity:0.5. Whenever I try this the background color as well as the words turn transparent.
One more thing. If I re-size my browser the navbar moves around and looks terrible. How can I keep the navbar in place as I re-size the browser?
Here's the JSFiddle link
HTML Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Me</title>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Montserrat:700' rel='stylesheet' type='text/css'>
</head>
<body>
<section class="main_front">
<nav id="nav_container">
<div class="logo"><img src="../images/logo.png" height="65px" /></div><!--end of logo-->
<ul class="right_links">
<li class="nav_li">Goals</li>
<li class="nav_li">School Site</li>
<li class="nav_li">Web Design</li>
<li class="nav_li">Summer</li>
<li class="nav_li">Schedule</li>
</ul><!--end of right_links-->
</nav><!--end of nav_container-->
</section><!--end of main_front-->
<section class="footer">
<div class="phonenumber">
<b>Contact:</b> 239-XXX-XXXX
</div><!--end of phonenumber-->
<div id="email">
adesign#email.com
</div><!--end of email-->
<div class="address">
1234 Web Design Ave.
</div><!--end of address-->
</section><!--end of footer-->
</body>
</html>
CSS Code
#charset "utf-8";
/* CSS Document */
body {
margin:0;
margin:none;
}
.logo {
float:left;
margin-top:5px;
}
.main_front {
width:100%;
height:90vh;
background-color:#A9D2F1;
}
/* .nav_links {
width:1600px;
height:100px;
margin:auto;
color:white;
} */
.nav_li {
float:right;
margin-right:20px;
}
#nav_container {
width:100%;
height:79px;
/*background-color:#82B5E8;*/
background-image:url(../images/nav_container_bg.png);
}
.right_links {
width:70%;
float:right;
list-style-type:none;
text-align:center;
}
.right_links a {
display:inline-block;
list-style-type:none;
text-decoration:none;
color:white;
font-size:17px;
margin-top:15px;
font-family:Montserrat, "Arial Black", Gadget, sans-serif;
}
.right_links li {
width:130px;
height:40px;
line-height:10px;
text-align:center;
border-radius:15px;
transition:all 0.5s;
-moz-transition:all 0.5s;
-webkit-transition:all 0.5s;
-ms-transition:all 0.5s;
}
.right_links li a {
display:block;
width:130px;
height:40px;
}
.right_links li:hover {
background-color:#166083;
}
.phonenumber {
font-size:26px;
margin-left:15px;
float:left;
}
.address {
font-size:26px;
margin-left:75%;
}
#email {
font-size:26px;
float:left;
margin-left:-295px;
margin-top:40px;
}
.footer {
width:100%;
height:10vh;
background-color:#8FC6ED;
}
change your CSS to this:
/* CSS Document */
body {
margin:0;
margin:none;
}
.logo {
float:left;
margin-top:5px;
}
.main_front {
width:100%;
height:90vh;
background-color:#A9D2F1;
}
/* .nav_links {
width:1600px;
height:100px;
margin:auto;
color:white;
} */
.nav_li {
float:right;
margin-right:20px;
}
#nav_container {
width:100%;
height:79px;
/*background-color:#82B5E8;*/
background-image:url(../images/nav_container_bg.png);
}
.right_links {
width:70%;
float:right;
list-style-type:none;
text-align:center;
}
.right_links a {
display:block;
list-style-type:none;
text-decoration:none;
color:white;
font-size:17px;
margin-top:0px; height:30px; padding-top:15px;
font-family:Montserrat, "Arial Black", Gadget, sans-serif;
}
.right_links li {
width:130px;
height:40px;
line-height:10px;
text-align:center;
border-radius:15px;
transition:all 0.5s;
-moz-transition:all 0.5s;
-webkit-transition:all 0.5s;
-ms-transition:all 0.5s;
}
.right_links li a {
display:block;
width:130px;
height:40px;
}
.right_links li:hover {
background-color:rgba(22,96,131,0.5);
}
.phonenumber {
font-size:26px;
margin-left:15px;
float:left;
}
.address {
font-size:26px;
margin-left:75%;
}
#email {
font-size:26px;
float:left;
margin-left:-295px;
margin-top:40px;
}
.footer {
width:100%;
height:10vh;
background-color:#8FC6ED;
}
About your last question, it all depends on what you need. If you want to make it responsive, the size of the nav will vary, hence the menu elements will re-locate, this requires a decision on what do you want to do depending on which size is shown (you can do nothing as well, as in no resizing)
You are using margin-top:15px to move the text down on the button. Change this to padding-top and the entire button will be clickable. This is because padding is on the inside of the a tag, and so expands the size of the a tag (which is your clickable link).
You have stumbled onto a problem that bothers a lot of us. When you have text within an element, it is tricky to apply opacity to the element but not to the text within. However, there are workarounds that workgreat. Here are a couple of posts:
http://css-tricks.com/non-transparent-elements-inside-transparent-elements/
CSS - Apply Opacity to Element but NOT To Text Within The Element
There are two ways to specify the location/size of elements on your page: fixed px/em or percentages. Fixed sizes do not re-size, but percentages do. Therefore, instead of this:
Do this:
<div style="height:10%;width:15%;"></div>
As the window size changes, so will the width/height of the div.
Two downsides to this approach:
a. You probably can't do this with just the navbar -- you may have to refactor your page to use percentages in most places;
b. Large monitors will have larger elements than smaller monitors -- but usually, this is a good thing.
What most folks do when switching to percentages is to set the outer page boundaries (the "wrap" or "container" or whatever is your top-level level div beneath body) in pixels -- and then use percentages for all else underneath. Okay, rarely all -- it is okay to mix percents and pixels/ems (of course, not in the same element ). Usually, there are some divs (buttons or shapes or whatever) that will remain fixed size regardless the size of the monitor/window.
A couple of references on this one:
http://kyleschaeffer.com/development/css-font-size-em-vs-px-vs-pt-vs/
Which is better to use in CSS, percentage or pixels?

nested accordion menu in CSS html

Based on this thread, I tried to build myself a css/html only accordion menu. When I took what I learned from the above, and applied it to my divs, it worked perfectly. I also needed to add a submenu that acted the same to the first menu item, portfolio. I attempted it with no success. It was explained to me that the reason was that I was using the same target.
(To begin, I am novice when it comes to a lot of these things so while some questions I have might seem fundamental it is because I am learning as I go.)
Based on the feedback, I attempted to make a new version creating 2 accordion classes. While that did not break the functionality I wanted, it still had the problem of opening both of the submenus. When you click PORTFOLIO, BRANDING should appear. When you click BRANDING, CONTENT should appear. Instead when you click PORTFOLIO, BRANDING and CONTENT appear.
It was indicated that this is because the first accordion function includes all child objects. While I've touched on those briefly in the js I'm learning I didn't know how to work with them in css other than the :not(x) I've come across but that did not seem to resolve it in any attempt though I could be doing it wrong.
jsfiddle
Here is the css to the above jsfiddle link:
a {
color:inherit;
text-decoration:none;
font-style:normal;
}
/* ---------- SECTION ---------- */
.accordion p + div :not(.accordion2) {
height: 0;
overflow: hidden;
-webkit-transition: height 0.3s ease-in;
-moz-transition: height 0.3s ease-in;
-o-transition: height 0.3s ease-in;
-ms-transition: height 0.3s ease-in;
transition: height 0.3s ease-in;
}
.accordion :target p + div :not(.accordion2) {
height:auto;
}
.accordion .section.large:target p + div :not(.accordion2) {
overflow: auto;
}
.section p {
color:#FFFfff;
text-align:right;
min-width:200px;
background-color:#2d2d2d;
font-size:12px;
font-size-adjust:inherit;
padding:0px;
margin:0px;
border-top:#161616 1px solid;
text-decoration:none;
text-transform:uppercase;
text-decoration:none;
color:#ffffff;
}
.section p a {
display:block;
text-align:right;
padding-right:10px;
padding-left:10px;
padding-top:3px;
padding-bottom:3px;
min-width:180px;
}
.section p a:hover {
background-color:#c569f2;
}
/* ---------- SubSection ---------- */
.accordion2 p + div {
height: 0;
overflow: hidden;
-webkit-transition: height 0.3s ease-in;
-moz-transition: height 0.3s ease-in;
-o-transition: height 0.3s ease-in;
-ms-transition: height 0.3s ease-in;
transition: height 0.3s ease-in;
}
.accordion2 :target p + div {
height:auto;
}
.accordion2 .subsection.large:target p + div {
overflow: auto;
}
.subsection p {
color:#FFFfff;
text-align:right;
min-width:200px;
background-color:#3d3d3d;
font-size:12px;
font-size-adjust:inherit;
padding:0px;
margin:0px;
border-top:#161616 1px solid;
text-decoration:none;
text-transform:uppercase;
text-decoration:none;
color:#ffffff;
}
.subsection p a {
display:block;
text-align:right;
padding-right:10px;
padding-left:10px;
padding-top:3px;
padding-bottom:3px;
min-width:180px;
}
.subsection p a:hover {
background-color:#c39bda;
}
/* ---------- Sidebar ---------- */
#sidebar {
float: right;
right: 0px;
background-color:#161616;
position:fixed;
width:20%;
min-height: 100%;
min-width: 200px;
top:0px;
}
#side-menu {
right: 0px;
top:0px;
position:absolute;
height:75%;
width:100%;
min-width: 200px;
bottom:0px;
margin-bottom:0px;
min-height:600px;
}
Here is the html:
<div id="sidebar">
<div id="side-menu" class="accordion">
<div id="menu-portfolio" class="section">
<p> Portfolio
</p>
<div class="accordion2">
<div id="submenu-branding" class="subsection">
<p> Branding
</p>
<div>
<p> Content
</p>
</div>
</div>
</div>
</div>
<div id="menu-about" class="section">
<p> About
</p>
<div>
<p>Resume
</p>
</div>
</div>
<div id="menu-contact" class="section">
<p> Contact
</p>
<div>
<p>Content
</p>
<p>Content2
</p>
<p>Content3
</p>
</div>
</div>
</div>
</div>
Can anyone assist me in understanding what I am doing wrong?
It doesn't matter if you use divs or lists (though most tutorials will use lists). Its mostly referencing the right item. Looking briefly at the code, you are not specifying to not show the sub sub menu.
I've added a new class to your first content and what the target does in css - showing only the div right after:
HTML:
<div class="subsub"> <!--added a new class. I have never used :not, but it seems that it does't allow nesting inside :not selectors -->
<p>Content</p>
</div>
CSS:
.accordion :target p + div :not(.subsub) {
height:auto;
}
You have to reiterate what you have done to show the sub menu when clicking on portfolio onto the sub sub menu when clicking on branding.
A quick fiddle: http://jsfiddle.net/jennift/m4ADf/2/
I haven't looked into your code, but like you've said "it includes all child objects". You can prevent this by using the direct descendant selector ">". It will only get the direct child elements, e.g.
ul > li {
}
will only style the li element and no other li elements inside it.

CSS Can only style elements with pixels, not percents

i'm having a bit of a brain melting problem. I have a master div thats pretty much the body (don't ask me why, i was getting desperate), and within that div is a head div, and within that div is the navigation bar. It's a clear hierarchy. The problem is, whenever i try to use percents to adjust the height and width of the navigation bar or the head div, nothing happens. Zip, zero, nada. I've tried changing the positions to absolute, relative, even static. I've removed the Master Div, i've reordered the hierarchy, but nothing seems to work. Eventually i got to the point where i figured out that when i used pixels, i got the change wanted. (Obviously had to do a bit of conversion). My first thought was hierarchy, but again, it's clear, with no missing ending tags, no weird parents or children.
HTML
<div id="master_div">
<div id="head_div">
<div id="title_div">
<p id="title">A Challenging Sew</p>
<p id="subtitle">A sewing room, Venti Starbucks and a iPod classic....with a weekly Monday update to keep me on task....lets see what happens....</p>
</div>
<div id="nav_bar">
<ul>
<li><a class="nav_bar_links" href="/home">Home</a></li>
<li><a class="nav_bar_links" href="/about">About</a></li>
<li><a class="nav_bar_links" href="/projects/2013">Projects for 2013/2014</a></li>
<li><a class="nav_bar_links" href="http://www.flickr.com/photos/91959855#N02/collections/72157632507621761/">Completed</a></li>
<li><a class="nav_bar_links" href="/archive">Archives</a></li>
<li><a class="nav_bar_links" href="/subscribe">Subscribe</a></li>
<li><a class="nav_bar_links" id="sign_in" href="#">Sign In</a></li>
</ul>
</div>
</div>
</div>
CSS
body
{
font-family: 'Lato', Helvetica, Arial, sans-serif;
font-size: 15px;
padding:0 !important;
}
#master_div
{
position:relative;
width:100%;
height:100%;
margin:0;
padding:0;
}
/* Navigation Page */
#scary_tree
{
position:absolute;
right:40%;
top:25%;
}
/* Home */
/* TODO: Make Responsive Home Page */
#head_div
{
background-color:whitesmoke;
position:absolute;
height:63px;
width:100%;
margin:0;
padding:0;
}
/* A Challenging Sew + A sewing room, Venti Starbucks and a iPod classic..*/
#title_div
{
background-color:white;
opacity: .7;
position:relative;
height:30px;
width:100%;
top:15px;
border-top: solid 1px #e7e7e7;
border-bottom: solid 1px #e7e7e7;
}
#title
{
position:absolute;
left:3%;
top:-9%;
font-size:100%;
margin:0;
padding:0;
}
#subtitle
{
position:absolute;
left:3%;
top:50%;
padding:0;
margin:0;
font-size:40%;
line-height: 1.2;
}
#nav_bar
{
position:absolute;
top:100%;
height:15%;
width:100%;
background-color:whitesmoke;
border-top: solid 1px #e7e7e7;
border-bottom: solid 1px #e7e7e7;
margin:0;
padding:0;
}
#nav_bar ul {
margin:0;
padding:0;
position:relative;
height:20px;
top:-8px;
}
#nav_bar li {
display:inline;
}
#nav_bar a:link,a:visited {
margin:0;
padding-left:5px;
text-decoration: none;
color: black;
font-size:50%;
}
#nav_bar #sign_in
{
position:absolute;
right:2%;
top:3px;
margin:0;
padding:0;
}
Note: I am using a reset file. However, i still have margin and padding :0 in there because it doesn't really seem to be taking hold.
Feel free to critique me on my coding style, still learning!
You might wan to try
min-height: 100%;
min-width: 100%;
position: absolute;
Found the cause, setting my master div's position to relative was the issue. Have no idea why but hey. It works now. Sort of.