Unwanted spacing below image - html

I'm trying to create a fixed-position footer at the bottom of my page. but there's an issue with spacing below the image and the bottom of the viewpoint that is unwanted:
Base Image:
The Issue:
The padding below the image is unwanted.
HTML:
<div id="containerBarKonge">
<ul>
<li><img src="./kongelogo.png" /></li>
</ul>
</div>
CSS:
#containerBarKonge {
position: fixed;
bottom: 0px;
width: 100%;
z-index:9999;
padding: 0px;
margin: 0px;
}
#containerBarKonge > ul {
position: relative;
list-style-type: none;
padding: 0px;
padding-left: 2px;
margin: 0px 20px;
min-width: 1053px;
background-color: #900;
}
#containerBarKonge > ul * {
padding: 0px;
margin: 0px;
}

Try setting the vertical align to bottom on the image:
#containerBarKonge img { vertical-align: bottom; }

The issue comes from the image having a default property of "display: inline;" - which is the equivalent to saying "have this image run along like text."
Images should rarely be employed as inline containers. Instead, an image should be defined as either display: block or inline-block. This gives you much precise control over your iamges versus - just align this to the top or bottom. What if you want the image 1px from the bottom? With vertical-align you can not.
So the solution is to do the following:
#containerBarKonge > ul li {
display: block;
height: 20px; /* or however tall it is */
}
#containerBarKong > ul li img {
display: inline-block;
/* Assuming it is 18px tall and you want it at the bottom: 20 - 18 = 2px */
margin: 2px 0 0 0;
}
there you go. You have PRECISe control of the positioning of the image while it retains its ability to run along like text.

Related

display: inline-block leaves gap with respect to height after div element

I have a div and an image in one div. Parent div has the background color. display: inline-block is given to both child div and the image.
<div style="background-color: black;">
<div style="display: inline-block; width: 20px; height: 105px; background-color: #27ae60; margin: 0;"></div>
<img style="display: inline-block; padding: 0px 10px;" src="http://cdn01.coupondunia.in/sitespecific/media/generated/merchantlogos/logo_5e29580_97.jpg?v=1413531812" />
</div>
jsfiddle link
http://jsfiddle.net/hv9szL92/2/
Gap below ebay image and green block must be removed. Thanks
The gap is because you set child elements as display: inline-block, and inline/inline-block elements respect white spaces, including new-line characters.
The simplest fix is to set zero font-size on the parent container in order to make those white spaces zero sized.
<div style="background-color: black; font-size: 0;">
/* content unchanged */
</div>
Remember to reset font-size back to some reasonable value for any nested element if you need to display text in them.
And it's better not to use inline styles, but I assume this is just an example in your case.
Demo: http://jsfiddle.net/hv9szL92/4/
As asked by OP, "Gap below ebay image and green block must be removed. Thanks"
http://jsfiddle.net/hv9szL92/5/
set the vertical-align property on the image and you're done (see Get rid of space underneath inline-block image) :
<img style="display: inline-block; padding: 0px 0px; vertical-align: top;" src="http://cdn01.coupondunia.in/sitespecific/media/generated/merchantlogos/logo_5e29580_97.jpg?v=1413531812" />
As for the green block, just remove the nested div element
You can just edit the margin of your img
<div style="background-color: black;" >
<div style="display: inline-block; width: 20px; height: 105px; background-color: #27ae60; margin: 0;" ></div>
<img style="display: inline-block; padding: 0px 10px; margin-bottom: -3.1px;margin-left: -13.5px;" src="http://cdn01.coupondunia.in/sitespecific/MEDIA/generated/merchantlogos/logo_5e29580_97.jpg?v=1413531812" />
</div>
Giving the image a negative margin should prove to be helpful
Any problems , let me know
Properly aligned and formatted using CSS-tables and Unordered List.http://codepen.io/anon/pen/WvGJqq
<div id="container">
<ul>
<li id="green-block"></li>
<li id="logo-wrap"><img id="logo" src="http://cdn01.coupondunia.in/sitespecific/media/generated/merchantlogos/logo_5e29580_97.jpg?v=1413531812" /></li>
</ul>
</div>
By using CSS tables you are able to use 'vertical-align: bottom;' to align the image with the bottom of the css cell.
Structure as follows:
- div#container [display: inline-table]
- ul [display: table-row]
- li [display: table-cell, vertical-align:bottom]
- img#logo [display: block, vertical-align:bottom]
Its pure css, but the same concept besides table layout creating from the mid 90's.
/* css reset */
ul {
padding: 0;
margin: 0;
list-style: none;
}
li {
padding: 0;
margin: 0;
width: 0;
}
/* css */
#container {
width: 100%;
height: 105px;
background: #000;
margin: 0;
padding: 0;
display: inline-table;
}
ul {
display: table-row;
}
#green-block {
width: 20px;
height: 105px;
background-color: #27ae60;
margin: 0;
display: table-cell;
}
#logo-wrap {
display: table-cell;
vertical-align: bottom;
}
#logo {
display: block;
vertical-align: bottom;
margin: 0 10px;
}
A really nice article out lying many of the concepts used for CSS tables.
http://colintoh.com/blog/display-table-anti-hero

How can i set height of my banner and vertically align its content to center?

I'm trying to make a banner on my webpage, the part on the top that is 700px wide and 80px high.
Code looks like:
<div class="container-narrow" style="heigth: 80px;">
<img src="#" width="52" height="52" alt="my logo" />
<ul>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
Css:
.container-narrow
{
margin: 0 auto;
max-width: 700px;
background: yellow;
}
ul
{
float: right;
width: 100%;
padding: 0;
margin: 0;
list-style-type: none;
}
a
{
float: right;
width: 6em;
color: black;
text-decoration: none;
padding: 0.2em 0.6em;
}
a:hover {color: #ccc; text-decoration: none;}
li {display: inline;}
What I want is the image and the horizontal menu to be vertically aligned in the center of the 80px. the logo to the left and the menu to the right.
I've tried to set the height and then padd/margin my way to get the job done but it feels rubbish...
Problem:
ul has a width:100%; if you give it a black border you will see that its occupying the width of the page, means it has no space to reside on the left of the logo inside the yellow header.
Removing this width will give the following result: http://jsfiddle.net/YBVe6/
Now since the header has a fixed max width, which is 700px, there's many ways to center the logo and the menu.
Fastest way I can think of is the following:
Give ul a display: inline-block;, (remove float: right;) then give the header a text-align: center;, here's the result : http://jsfiddle.net/YBVe6/1/
And if you want the menu to be displayed in the upper part, just add vertical-align: top;.
To start of, it's a good practice if you have an external CSS, don't put additional CSS in your HTML blocks:
<div class="container-narrow">
and put the height style in your css sheet, as you have a class setup for your div there anyway.
Second, making typo's is a pain if you want your CSS to work properly, so instead of heigth you should use height, will make you div actually 80px high.
Third of all: margins are there the position elements. Use them!
.container-narrow
{
height: 80px;
margin: 0 auto;
max-width: 700px;
background: yellow;
}
img
{
margin-top:14px;
}
ul
{
float: right;
padding: 0;
margin: 0;
list-style-type: none;
margin-top:25px;
}
a
{
width: 6em;
color: black;
text-decoration: none;
padding: 0.2em 0.6em;
}
a:hover {color: #ccc; text-decoration: none;}
li {display: inline;}
Edit
This is mostly applicable for vertical alignment. If you want to auto-center horizontally, you can make use of the margin:auto concept. This is possible because a page can't extend beyond the browser width (browser height can extend as you have scrolling available as default behavior).

Mysterious gap under image appearing [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
White space at bottom of anchor tag
Check out this sample page here..
http://denise.brixwork.com/
For some odd reason, under that pic of that family, there's a gap before the grey border (5px #333) div that contains the image. I removed all margins, paddings etc. and it still wont' disappear. :(
Short of setting a fixed height on the #index_content div, which i don't want in case the image has to be re-sized later (which means double the work for me), how can I remove that gap while leaving it elastic?
My HTML Code:
<div id="index_content_container">
<div id="index_content">
<img src="http://denise.brixwork.com/images/index_photo.jpg" alt="Real Whistler Living - Real Estate for the Next Generation" />
</div>
<div class="clear"></div>
</div>
The CSS:
/* INDEX PAGE SPECIAL CSS */
#index_content_container {
position: relative;
width: 970px;
border: 5px solid #e1bb14;
left: -20px;
display: block;
float: left;
padding: 0px;
margin: 0px;
}
#index_content {
position: relative;
width: 960px;
border: 5px solid #333;
float: left;
display: block;
padding: 0px;
margin: 0px;
}
#index_content img {
padding: 0px;
border: none;
margin: 0px;
clear: none;
}
Try this:
#index_content img{
padding: 0px;
border: none !important;
margin: 0px;
clear: none;
display: block;
}
You only need display: block in your img tag, nothing else =)

How to define margin (CSS) around an absolutely positioned, floating element?

Before I explain...
This is the HTML part:
<div class="HeadingTabs">
<ul>
<li>Google</li>
</ul>
<div class="TitleTab">This is some very very long title. This is some very very long title. This is a very long title.</div>
</div>
This is the CSS part:
.HeadingTabs {
display: block;
padding: 8px 8px 8px 2px;
margin: 0;
border: 0;
background: transparent;
}
.HeadingTabs ul {
display: inline;
margin: 0 0 0 10px;
float: right;
position: absolute;
bottom: 0;
right: 8px;
}
.HeadingTabs li {
display: inline;
margin: 0;
}
.TitleTab {
margin: 0;
display: inline;
font-weight: bold;
text-decoration: none;
padding: 5px 10px;
line-height: 2.6;
white-space: nowrap;
/* I haven't included the styling info like
borders and background to avoid unnecessary
distractions in code. */
}
Now... as you can see, the ul element is floating right and is absolutely positioned to the bottom-right of the parent div. This is what I meant, when I said 'an absolutely positioned, floating element.'
Dispite the giving it a margin, I am unable to prevent the title (<div class="TitleTab"> element) from protruding into it. The image below should make it clear.
What am I missing?
Points of note:
I cannot modify the HTML. My only go is CSS.
I want the title to wrap around the ul element. So, I can't use width.
I am using position: absolute; because I want the ul element to stay at the bottom of the div right above the content div (just cut-off in the image).
PS: I am not very proficient with CSS.
The absolute:position function is designed to be protruded into.
you should try floating the elements instead without the absolute:position
.HeadingTabs ul {
margin:10px;
float: right;
}
.TitleTab {
float:left;
margin: 0;
font-weight: bold;
text-decoration: none;
padding: 5px 10px;
line-height: 2.6;
white-space: nowrap; // you need to remove no wrap, so it wraps instead of cuts off
}

Why is this ul exceeding the size of it's div?

Although li.textmenu has width: 140px, padding: 5px, and div.textmenu has width: 150px, the one list item i've made so far has a big left margin, and extends beyond the right edge of the div by at least 30px. What could be causing this and how can I restrict it's width?
http://www.briligg.com/frailty.html
CSS
div.textmenu {
background-color: #3b3b3b;
float: left;
width: 150px;
margin: 30px 10px 0 30px;
}
li.textmenu {
background-color: #4a4a4a;
margin: 0;
padding: 5px;
border: none;
width: 140px;
list-style: none;
text-align: right;
}
HTML
<div class="textmenu">
<ul>
<li class="textmenu">
<a class="pink" href="http://www.briligg.com/frailty.html#culture">Stress Causes Addiction</a>
</li>
</ul>
</div>
Did you add a zip/uni reset to the top of your css file?
* { margin:0; padding:0; }
( Put that exactly as is at the very top of CSS to override browser default margins/padding ).
Most likely the ul is being given default padding/margin, so this is to counter-act it.
Make sure the ul does not have padding and margin of its own, by resetting it with padding:0;margin:0;
The ul has a margin and padding set it on by the browser. You'll want to remove this:
div.textmenu ul {margin:0;padding:0;}
Only the padding affects the width, but you'll probably want to take off the margin too.
Its like smeridan said. There are for all html elements preset styling properties.
I recommend you to use the reset css by Eric Meyer: http://meyerweb.com/eric/tools/css/reset/
You can include it at the top of your document. After that you have more control about your desired styling.
Make sure you've calculated the exact width and height of the Li you want to fix inside the Div by making sure the DIV has enough space within it.
div.textmenu {
background-color: #3b3b3b;
float: left;
width: 150px;
margin: 30px 10px 0 30px;
}
li.textmenu {
background-color: #4a4a4a;
margin: 0;
padding: 5px;
border: none;
width: 140px;
list-style: none;
text-align: right;
}
Since you made the padding: 5px, calculated by the 2xwidth + height of the Li, the Li should exceed 150px width of the Div box. you can fix by reducing your padding pixel of the LI.