I am trying to design a simple header to a page in css. I planned to stack two divs on top of each other. The top one has many tabs and the bottom one is a plain solid single image div. But when rendering i see that an extra 5px is getting added to the the heights of both these divs. So i am not able to place the bottom on exactly on top of the other one.
There is a 5px bottom margin automatically. I tried negative margins, reset the global margins and paddings to zero. Still no use.
Heres the code.
<div class ="main_nav">
<div class="first_tab">
<img src ="images/startup/tab1_brown.png" height="25" width="90" alt="Temp" />
</div>
<div class = "ind_tab">
<img src ="images/startup/tab1_orange.png" height="25" width="90" alt="Temp"/>
</div>
<div class = "ind_tab">
<img src ="images/startup/tab1_brown.png" height="25" width="90" alt="Temp" />
</div>
</div>
<div class="lock">
<img src ="images/startup/divbg_new.png" alt="Temp" />
</div>
CSS:
*{ margin:0; padding:0; }
ul.master_navigation
{
font-size: 125%;
font-weight: bold;
text-align: center;
list-style: none;
margin: 0.5em 0;
padding: 0;
}
ul.master_navigation li
{
display: inline-block;
padding: 0 1%;
}
a
{
color: #08f;
font-weight: bold;
text-decoration: none;
}
a:visited
{
color: #88f;
}
a:hover
{
color: #f00;
}
p
{
text-align: justify;
}
p.cent
{
text-align: left;
}
div.header
{
height: 200;
}
div.main_nav
{
display: inline-block;
height: 25;
width: 900;
padding: 0;
margin: 0;
vertical-align: bottom;
}
div.first_tab
{
height: 25;
float: left;
}
div.ind_tab
{
height: 25;
float: left;
margin-left: -10px;
z-index: -5;
}
div.lock
{
margin-top: -100;
height: 91;
width: 900;
padding: 0;
margin: -5;
}
body
{
width:900px;
max-width: 100%;
margin: auto;
padding: 0;
background-image:url(images/startup/bg_2.gif);
background-repeat:repeat-x;
}
.pad
{
padding: 0;
margin: 0;
}
Here's the link to the page
http://net4.ccs.neu.edu/home/pradep/
Ive been spending too much time on this. Please help.
Ege's answer was very useful for me. I have spent hours to find the reason of a bottom padding of some images in div's. It was the line-height. Set it to 0px on the interesting areas:
.divclass {
line-height: 0px; /* crucial for bottom padding 0 !!! */
}
I think your problem is the line-height. Yup, there it is. Just added line-height:0, on firebug and they stuck together.
The thing about inline-blocks is that they behave just like any inline text, you also have a similar issue on the navigation below, because you pressed enter in your code, it will render it as a non-breaking space and add extra x margins to the right and left sides as well. X here will depend on the font size.
In order to solve this, you can either close and open tags on the same line like below:
<div>
.
.
.
</div><div>
.
.
.
</div>
or you can set the font-size and line-height to 0, but thats not always possible if you don't have other selectors inside that div.
You need to specify units on your CSS declarations.
http://jsfiddle.net/m7YCW/
div.main_nav
{
display: inline-block;
height: 25px; /* set px */
width: 900;
padding: 0;
margin: 0;
vertical-align: bottom;
}
Learn to make use of your developer tools in Chrome, if you had right mouse buttoned on the elements and chosen -> inspect it would bring up the dev tools. You can then view the 'metrics' and 'computed styles' areas to see that main_nav was rendering as 30px instead of 25px and also that there was a warning symbol next to the 25 css declaration and it was being explicitly dropped.
Try setting vertical-align:bottom on the images.
Related
I'm trying to get a text within div to be entered with word spacing and image in the background.
An example of what i'm trying to achieve:
Her's a fiddle that shows what I achieved so far:
div {
width: 200px;
}
h2 {
display: inline-block;
text-align: center;
color: #000000;
word-spacing: 40px;
background: url("http://s33.postimg.org/twxfn1by7/Playlist_Triangle.png") top center no-repeat;
background-size:50px;
padding: 20px 0;
}
<div>
<h2>
Some text
</h2>
</div>
https://jsfiddle.net/wes2sa1t/
You'd have to wrap the words in something like a span so you can center them. This is how to do it with CSS, as you tagged this with the CSS tag, but you could also achieve this with jQuery.
HTML:
<div>
<h2>
<span>Some</span> <span>text</span>
</h2>
</div>
CSS:
h2 {
display: inline-block;
text-align: center;
color: #000000;
word-spacing: 40px;
background: url("http://s33.postimg.org/twxfn1by7/Playlist_Triangle.png") top center no-repeat;
background-size: 50px;
padding: 20px 0;
}
span {
width: 100px;
display: inline-block;
text-align: right;
}
span:nth-child(2) {
text-align: left;
}
Rather than centering something, it more seems like you want the image evenly spaced between the words. I agree w/ Blaine that the words need to be wrapped in a span. I don't agree with setting a fixed width though, as that is very constraining.
Instead, I would move the background image from the h2 and place it on a psuedo-element of one of the spans:
h2 {
display: inline-block;
text-align: center;
color: #000000;
padding: 20px 0;
font-size: 0; // gets rid of whitespace between the spans
}
span {
font-size: 24px; // resets the font-size of the words
}
span:nth-child(1):after {
content: '';
display: inline-block;
width: 50px;
height: 50px;
background: url("http://s33.postimg.org/twxfn1by7/Playlist_Triangle.png") top center no-repeat;
background-size: 50px;
}
Using inline-block places everything right next to each other, and putting a font-size: 0 on the h2 removes any whitespace.
Now the words can be any length, and the image will remain perfectly spaced between them.
Here's a demo: https://jsfiddle.net/rq8u5b3k/1/
If you can't control the markup for whatever reason, here's a jQuery snippet that will wrap each word in a span:
var words = $("h2").text().split(" ");
$("h2").empty();
$.each(words, function(i, v) {
$("h2").append($("<span>").text(v));
});
Updated demo: https://jsfiddle.net/rq8u5b3k/3/
I've been working on building a website for a while now (scarletorigami.com, if it helps). I've written some PHP which generates lists of captioned thumbnail links to individual pages, which have the following structure:
#thumbnails {
margin-top: 0;
margin-bottom: 0;
margin-left: auto;
margin-right: auto;
padding: 60px;
width: 680px;
background-color: #BBCCBB;
}
#thumb {
margin: 0;
padding: 0;
width: 220px;
height: 280px;
background-color: #BBBBBB;
text-align: center;
font-style: italic;
font-size: 100%;
border: 1px solid #ccc;
}
#thumb:hover {
border: 1px solid #777;
}
#thumb a {
display: inline-block;
width: 220px;
height: 280px;
text-decoration: none;
margin: 0;
padding: 0;
}
#thumb_image {
width: 220px;
height: 220px;
}
#caption {
font-size: .65em;
float: bottom;
margin: 0;
padding: 0;
background-color: #AACCAA;
}
<div id=thumbnails>
<div id=thumb>
<a href="link to content">
<div id=thumb_image>
image or "Can't find image" message
</div>
<div id="caption">
Name
<br />Author Date
</div>
</a>
</div>
</div>
I've encountered a number of issues regarding the scope of various text and font properties on firefox and safari (can't test any others at the moment).
Specifically, if I move the 'text-decoration:none' line anywhere other than the #thumb a section, underscores reappear on all text in the thumbnail caption, and I can't get the 'font-size:.65em' to take effect in the 'caption' div. I can change the font size in the whole section by moving the line to the #thumb a or #thumb section, but I cannot change just the caption text size by any means I've tried. In both cases, using firefox's inspect element feature shows that inheritance of css properties is working properly for all other properties, so it seems like it is some kind of quirk or issue with how text/font properties are overridden or passed down.
In keeping with Lauren Fauvel's suggestion, I changed my code so that my divs were given classes instead of ids, and somehow this seems to have fixed the scope problem. I'm still not sure why exactly the problem was caused in the first place, but if properly written html doesn't have the problem, I suppose I should consider this solved.
In a CSS file I have the following rules:
div.breadcrumbs span {
position: relative;
left: -120px;
height: 16px;
line-height: 16px;
margin: 0 20px;
overflow: hidden;
}
div.breadcrumbs img {
margin: 0 -20px;
padding: 5px 5px 0px 5px;
}
div.breadcrumbs a {
color: #88263F;
font-weight:bold;
}
The rules for img and a work, but not for span.
Also something does not work like
span {
display: none;
}
At the moment I have no clue how to debug this.
In principal, your posted CSS works.
If your HTML looks like this...
<div class="breadcrumbs">
These are <span>breadcrumbs</span> in a line...
</div>
and this is your CSS:
div.breadcrumbs span {
position: relative;
left: -120px;
height: 16px;
line-height: 16px;
margin: 0 20px;
overflow: hidden;
}
span {
display: none;
}
then the span element is not shown as you intended.
See demo at: http://jsfiddle.net/audetwebdesign/qyu5A/
You may have other problems such as other CSS rules that are conflicting and preventing the display: none property from working correctly.
There is nothing wrong with the positioning of an inline element, but you may not get exactly what you expect depending on the line height and surrounding content.
You may want to learn more about how the CSS cascade and specificity work.
Reference: http://www.w3.org/TR/CSS2/cascade.html#cascade
Note: The height property is ignored for inline elements.
Thank you for your hints, especially the fiddle!
Playing around with it I found the following code snippet also in the CSS file:
body.home div.breadcrumbs span { position:relative; left:0; }
Placing "div.breadcrumbs span" after this and deleting "position: relative;" it works as exspected.
I'm trying to use CSS divs to add images to my site. I'm using background-image:url(""); but the image doesn't appear when loading the site.
The images I'm referencing are in the same folder as my style.css, and I quadruple-checked that I wrote the file names correctly.
Any help is very much appreciated. Thank you.
CSS:
div#logo {
background-image:url(dm-button2.png);
height: 120px;
width: 120px;
position:absolute;
z-index: 100;
background: blue; /* #333333; */
padding: 0px;
margin: 0px auto;
display: inline;
}
HTML: (Am I missing something here?)
<div id="logo">
</div>
div#logo {
background:url(dm-button2.png) blue;
height: 120px;
width: 120px;
position:absolute;
z-index: 100; /* #333333; */
padding: 0px;
margin: 0px auto;
display: inline;
}
try this, your second background is rewriting the first
use this:
div#logo {
background-image:url(dm-button2.png);
height: 120px;
width: 120px;
position:absolute;
z-index: 100;
background-color: blue; /* #333333; */
padding: 0px;
margin: 0px auto;
display: inline;
}
Try replacing Background image and background with something like this
background: blue url('dm-button2.png') no-repeat fixed center;
I am not 100% sure but i think having background-image followed by background, background will overwrite the background-image call since it loads in order
example FIDDLE HERE
start small and add the other attributes.
div#logo {
height: 120px;
width: 120px;
background:url(http://flyingmeat.s3.amazonaws.com/acorn4/images/Acorn256.png) 0 0;
}
The background image will not display if there is nothing to put a background image on... for example, all you have a div tags but nothing inbetween them.
Add at least a br tag or something to create some space for the image to be displayed.
I have a bunch of divs inside a container that is equally spaced from the right as well as from the bottom. (i.e margin-right and margin-bottom are the same)
Here is my jsfiddle below:
http://jsfiddle.net/wYCzJ/1/
Here is my css code:
.container {
width: 100%;
height: auto;
display: inline-block;
}
.wrapper {
position: relative;
float: left;
width: 25%;
}
.box {
margin-bottom: 0.5em;
margin-right: 0.5em;
border: 1px solid;
border-color:#DDD;
padding: 0.5em;
height: 150px;
}
.name{
width: 95%;
font-size: 1.2em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-weight: bold;
}
.result {
text-align: right;
margin-top: 0.5em;
font-weight: bold;
margin-right: 0.75em;
}
.result-type {
float:left;
display:inline;
font-size: 1.1em;
display: inline;
}
.result-value {
font-size: 1.5em;
display: inline;
}
.no_data {
font-size: 1.2em;
color: darkgray;
}
.date {
position: absolute;
bottom: 1em;
color: gray;
}
Everything works fine as expected, except that the last div box has extra some extra spacing towards the right ( Test 5 box and Test 7 box in this case)
I kinda need the same spacing all around. Is there a workaround for this?
if you add:
body {
margin: 0;
padding: 0;
}
you will have only 5px from the right
it's up to you to make div container to margin 5px from left and top
i managed to twick it:
body {
padding: 0;
margin: 0;
margin-top: 0.5em;
margin-left: 0.5em;
}
tested it in Chrome and FF - http://jsfiddle.net/elen/wYCzJ/3/
found and adopted this version - jsfiddle.net/elen/5CJ5e/131 - see if it works for you
please notice combination of text-align: justify;, font-size: 0; and heights for both outer and inner boxes. also use of <span class="stretch"></span> for 100% width
Your probleme is simple, the body have a natural margin.
body{margin-right:0px}
That solve your probleme, but it's a bit wierd to have a bodywith only the margin-right at 0...
The overall container has spacing for its top, bottom, left, and right. Your individual boxes only have spacing on the bottom and right. The reason you are seeing "extra" spacing on the right is because the spacing for the individual box and the overall container are being added together.
A possible sollution with nth-child. This removes the margin of every 4th .box element.
.wrapper:nth-child(4n) .box{
margin-right: 0;
}
http://jsfiddle.net/wYCzJ/5/
Have a look at browser support of nth-child at caniuse.