• 0

Need help with 100% height float element


Question

Hey all. Right now I am trying to get the left navigation button to be a height of 100% because this will be my mobile CSS sheet.

I want it to go all the way down the white element that it is in.

The pink background color is there to help me see what's going on.

I'm using Firefox's web dev. inspector and it seems the #left-col is not height 100%, which means I won't be able to get the #prev-button-i to be height 100%, which is what I need.

My thought is maybe this is caused by the float? Maybe it really is at height 100% but it's just displayed differently because of the left float?

The site with the issue

http://alllols.com/index3.php

http://alllols.com/stylem.css

The main site with no issue (maybe it's useful?)

http://alllols.com/index.php

http://alllols.com/style.css

If anyone is curious, I just made this site for fun to learn PHP and MySQL :)

16 answers to this question

Recommended Posts

  • 0
  On 31/05/2013 at 01:37, AWKM said:

Hard to figure out what is up because you seem to have height:100% on just about everything

Thank god I'm not the only one.

Could it be because, if when there is no float, it is at 100% height. So when it's floating, it is at 100%, we just perceive it to not be at 100% height?

  • 0
  On 31/05/2013 at 02:05, thatguyandrew1992 said:

Thank god I'm not the only one.

Could it be because, if when there is no float, it is at 100% height. So when it's floating, it is at 100%, we just perceive it to not be at 100% height?

if you didn't abuse 100% height like this the height of all the elements should have been based on the content and there shouldn't have been any bug at all :p

Also don't use float on every single element either, float is usseless when there is no element next to it, and use other position types then static(default) if neccessary (absolute, relative, fixed).

  • 0
  On 31/05/2013 at 05:37, Seahorsepip said:

if you didn't abuse 100% height like this the height of all the elements should have been based on the content and there shouldn't have been any bug at all :p

Also don't use float on every single element either, float is usseless when there is no element next to it, and use other position types then static(default) if neccessary (absolute, relative, fixed).

Can you be more specific? I need that button to be 100% height because resolutions change. What am I supposed to do?

  • 0
  On 31/05/2013 at 05:52, thatguyandrew1992 said:

Can you be more specific? I need that button to be 100% height because resolutions change. What am I supposed to do?

you mean the next and previous buttons right?

if so, try using fixed or absolute:


.nextbutton {
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 30px;
}
[/CODE]

  • 0

I don't want to sound rude but that's some nasty code here. I don't even know where to start. Maybe reading a book on css would be a good idea ...

prev-button-a cannot go all the way down the element it is in because there's a br after it. You should apply display:block to prev-button-a since you have a block level element inside it. Never put a block level element inside an inline element. The height 100% to prev-button-i will never ever do anything for 2 reasons. Its parent is an inline element (which doesn't support the height property). The height of an inline element is the height of the line (line-height). If you apply display:block to the parent of prev-button-i then it wont change anything cause the height of its parent (prev-button-a) is set to auto (ie the height of the content inside it which is min-height:100px).

<div id="left-col"> height is set to auto too. Like prev-button-a it will take the height of the content part of the normal page flow inside it. Its height will be 100px too if you remove the br (min-height:100px). Add to this the padding 60px at the top. Add to this the line-height of the br under it if you don't remove it. This element is floated. It is not part of the normal page flow. The reason <div id="left"> has an height is because of the central content (which is part of the normal page flow). As far as <div id="left-col"> goes its parent doesn't have any height other than min-height:220px.

Here's a quote from the css spec :

  Quote
percentage

Specifies a percentage height. The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to 'auto'.

So according to the css spec since the parent's height of <div id="left-col"> is not explicitely specified and <div id="col-left"> is floated then its height in % is then set to auto.

prev-button-i height is 100px because of min-height:100px. Remove this property and its height will then become 0px. You should try working with absolute positionning instead since absolu

  • 0

Here's something to help you start. It's not perfect by any mean since i did this really quickly in my break in about 10 min (with the previous post).

#left-col{
	width: 56px;
	height: 95%;
	position: absolute;
	left: 0px;
	top: 60px;
}

#prev-button-a{
	display: block;
	height: 100%;
}

#prev-button-i {
	height: 100%;
	width: 56px;
	background: url("./s_images/prev-button.png") no-repeat scroll 0% 0% rgb(255, 0, 255);
	min-height: 100px;
}

You should think about merging prev-button-i into prev-button-a. No reason to have both.

  • 0

It is indeed some messy css but rewriting it all might not be a option he would like to choose :p

That's why I posted the position absolute code, which should work no matter what the parent elements are like(ofcourse the parent elements shouldn't have position relative or fixed in that case)

  • 0
  On 31/05/2013 at 17:03, thatguyandrew1992 said:

Thanks guys, I will try this later today. And LaP, why is my CSS so bad looking? Is there anywhere online that could help me with this?

You can read the specification. It's a daunting task but if you are serious about web design i think it's something that needs to be done once.

http://www.w3.org/TR/2011/REC-CSS2-20110607/

If you find reading the specification boring then a book is probably your best option. But i actually think the specification is easy to read and well explained.

After that you can find a good blog to learn about the quicks. I'm french so the blogs i'm reading are mostly french but i'm sure you can find good ones in english too. Here's one of the blog i read once a week.

http://www.alsacreations.com/

If you want to start with html5 there's a good free online book.

http://diveintohtml5.info/

http://html5please.com/

You should take a look at responsive web design too specially if you are into mobile web site.

http://alistapart.com/article/responsive-web-design

  • 0
  On 31/05/2013 at 17:03, thatguyandrew1992 said:

Thanks guys, I will try this later today. And LaP, why is my CSS so bad looking? Is there anywhere online that could help me with this?

a large part is complexity. if you write the earlier rules only with what it ends up looking in mind without thinking forward (i.e. have a general plan of how you're laying everything out before writing any code) you often end up having to put in unnecessary properties to hack the result into what you want it to be. despite the name, too many cascades make it really difficult to work with because anyone troubleshooting can't tell head from toes.

  • 0
  On 31/05/2013 at 18:22, primexx said:

a large part is complexity. if you write the earlier rules only with what it ends up looking in mind without thinking forward (i.e. have a general plan of how you're laying everything out before writing any code) you often end up having to put in unnecessary properties to hack the result into what you want it to be. despite the name, too many cascades make it really difficult to work with because anyone troubleshooting can't tell head from toes.

This and the usual diseases called "classite" and "divite".

You don't have to put everything in a div with a class attached to it. When you have 5-6 levels deep of div it becomes as bad as using tables.

The web site is really simple yet the code is hard to read without a dom inspector.

Here's a good example :

&lt;div id="footer"&gt;&lt;div id="footer-text"&gt;&lt;span&gt; ? &lt;/span&gt;&lt;span&gt; ? &lt;/span&gt;&lt;span&gt; ? &lt;/span&gt;&lt;span&gt; ? &lt;/span&gt;&lt;span&gt; ? &lt;/span&gt;&lt;/div&gt;&lt;/div&gt;

There's no reason to have 2 divs here. The spans are also useless since all the text share the same visual style. The css of the span > a in this footer could be merged.

You should use meaningful tag as much as possible. a for link. p for paragraph. h for headers. etc etc etc

The div and span tags have no meaning. They do not inform the reader about the content. Ideally they should be used only when you need to group elements and apply a common visual style to them.

This topic is now closed to further replies.
  • Posts

    • Nice ad billboard for your living room...
    • Microsoft explains why Windows 10 users should upgrade to Windows 11 by Taras Buria Windows 10 reaches its end of support in four months, but not everyone is ready to move on. Some have unsupported hardware, some do not like its controversial parts, like the taskbar and Start menu, and others simply do not see a point. If you are one of those users who are unsure if they should leave Windows 10 behind, Microsoft has a list of reasons why Windows 11 is better and why you should upgrade. In the newly published blog post, Microsoft outlined several key features that make Windows 11 a better operating system, not just a poorly reskinned Windows 10, as some think. Microsoft quotes faster performance, simpler navigation, new features and experiences, and better security. Here are some of those reasons: Security: Making TPM 2.0 and implementing other security features like Smart App Control and VBS helped reduce security incidents. Microsoft claims "a reported 62% drop in security incidents and a 3x reported reduction in firmware attacks." Speed: Windows 11 features several Windows Update improvements that make update installation faster by up to 2.3 times than Windows 10. This is a pretty strong argument, considering how much people hate installing updates, especially on their PCs. Modernized user experience: Windows 11 has several productivity-boosting features like Snap Layouts, virtual desktop improvements, and more. Microsoft also mentions cleaner looks of the taskbar and Start menu, but we all know that those areas are the reason why many actually do not want to upgrade to Windows 11, even though some notable improvements are on the way. Accessibility improvements: This is legitimately a big reason to update if you rely on assistive technologies. Windows 11 is more accessible than its predecessor and features brand-new accessibility features like Voice Access, Focus Sessions for fewer distractions, Live Captions, Voice Typing, and more. You can check out an overview of all Windows 11 accessibility features here. New AI-powered features: Windows 11 has several exclusive AI features that are not available on Windows 10. They include Recall, Click to Do, AI-powered Windows Search, a Settings agent, Paint Cocreator, and more. However, these are only available on new devices, and you cannot get them when upgrading an existing PC from Windows 10 to 11. Still, some AI features work on all devices as well, such as the recently launched Copilot Vision. If those reasons are not enough, no worries. Microsoft lets users stay on Windows 10 even after the end of support. Today, Microsoft announced that the Extended Security Update program would be free for all customers. All you need to do is back up your PC settings in the Windows Backup app using your Microsoft Account (paid options are still present). You can learn more about that here. What about you? Do you think Windows 11 has enough solid reasons for you to switch and forget about Windows 10?
    • Without regulation, greed has no limits...If you go and post an ad on a billboard without permission, you'd be arrested for trespassing or vandalising private property, yet these companies keep doing it on our paid products scott-free. Be it "Smart" TVs, Phones in this case, displays/Tablets, Laptops, Desktops, etc. I'm eagerly waiting for the day the EU makes a regulation that requires these tech giants pay end users 50%+ for ANY form of further monetization on products users have paid for when that wasn't explicitly displayed on the product purchase page in normal 12pt sized font. Then and only then will all these nonsense "updates" introducing ads on our devices be put to an end.
    • The 75-inch Hisense U7 Series mini-LED TV drops to its all-time low price by Fiza Ali Amazon US is currently offering the 75-inch Hisense U7 Series Google Smart TV at its lowest price to date. So, if you are considering an upgrade to your home entertainment system, it may be worth a look. The U7 features Mini-LED Pro technology, providing a peak brightness of up to 1,500 nits alongside Full Array Local Dimming Pro for improved contrast. Its QLED Quantum Dot panel covers over a billion colours, delivering a wide colour gamut. Furthermore, the TV's Hi-View Engine PRO chipset uses deep-learning algorithms and technologies such as Dynamic Tone Mapping Pro, Face Detection, AI HDR Enhancement and AI Detail Enhancement to refine image quality. Its sound is handled by a 2.1 multi-channel system with three speakers, offering up to 40W of output and a built-in subwoofer. Moreover, the smart audio decoding supports a 2.1 surround-sound experience without the need for additional equipment. For gaming, the 144Hz Game Mode Pro offers a Variable Refresh Rate (VRR) from 48Hz to 144Hz, AMD FreeSync Premium Pro, Auto Low Latency Mode (ALLM), and Low Latency MEMC, helping to reduce screen tearing and input lag. When it comes to the connectivity options, this Google Smart TV includes two USB-A ports and two HDMI 2.1 ports which support 4K resolution at 60Hz. Additionally, it includes one HDMI 2.1 port with eARC technology and another HDMI 2.1 port, both supporting 4K resolution at 144Hz. 75-inch Hisense U7 Series Google Smart TV: $799.99 (Amazon US) - 11% off This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
  • Recent Achievements

    • Week One Done
      DrRonSr earned a badge
      Week One Done
    • Week One Done
      Sharon dixon earned a badge
      Week One Done
    • Dedicated
      Parallax Abstraction earned a badge
      Dedicated
    • First Post
      956400 earned a badge
      First Post
    • Week One Done
      davidfegan earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      618
    2. 2
      ATLien_0
      228
    3. 3
      +FloatingFatMan
      169
    4. 4
      Michael Scrip
      166
    5. 5
      Som
      146
  • Tell a friend

    Love Neowin? Tell a friend!