Getting no space between image and div - html

I just wanted to create a newsbox just by using CSS without so many IMG or TABLE crap. It works quite well but there will always appear a space between my image and the colored bar under the picture which should be directly under the picture not with some space between. Here is my code :
<div id="mainbody">
<div class="news_box">
<div class="news_box_inside">
<img src="img/newsbox1.jpg" width="270" height="140" border="0" />
<div class="news_box_bar"></div>
</div>
</div>
</div>
#mainbody {
margin: 0 auto;
width: 900px;
padding-top:30px;
padding-bottom:30px;
}
.news_box {
float:left;
width:288px;
height:348px;
background-color:#DDDDDD;
margin-right:5px;
margin-left:5px;
border:1px;
border-style:solid;
border-color:#BBBBBB;
}
.news_box_inside {
float:left;
margin:9px;
width:270px;
height:330px;
background-color:#FCFCFC;
}
.news_box_bar {
background-color:#540000;
height:43px;
border:1px solid #892d2d;
}
I tried to set the margin and padding to zero for the image or trying position: or top: but somehow I can't get rid of the space. Anyone got a good solution ?
Best regards,
Kris

Add this to your CSS:
.news_box_inside > img {
display: block;
}
Example: http://jsfiddle.net/grc4/TV4zT/

Kris,
If you inspect <img> element by default it's css property display is set to inline-block, SO I suggest to apply style on <img> element and make it display:block
<img src="img/newsbox1.jpg" width="270" height="140" border="0" style="display:block" />
DEMO

Just add a margin to your newsbar as showm: DEMO
.news_box_bar {
background-color:#540000;
height:43px;
border:1px solid #892d2d;
margin-top:-5px;
}

.news_box_bar {
background-color:#540000;
margin-top:-5px;
height:43px;
border:1px solid #892d2d;
}
set this in your CSS class

use link below to see working solution for your problem
http://jsfiddle.net/v7NwR/
<div id="mainbody">
<div class="news_box">
<div class="news_box_inside">
<figure><img src="http://static.adzerk.net/Advertisers/a04d6b3e25c747f48ef794d13e765425.jpg" border="0" /></figure>
<div class="news_box_bar">sdfgsdfgsdfg</div>
</div>
</div>
</div>
css
.news_box{ float:left; border:5px #444 solid;}
figure{ font-size:0%;}
#mainbody{ color:#000;}
.news_box_bar{ background:red;}

Related

HTML navbar with two image hyperlinks

I've been trying to create a responsive navbar with just two images (which are hyperlinks and transparent) and I can't seem to get the formatting right. The way I want it to look is:
First image: width:60%
Second image: width: 40%
Both have the same height
Border: 2px solid black (around both images)
Padding: 10px (Around both images and between the two)
Keep the navbar on the top of the page
Hover effect that changes the background color
Basic Idea
The closest I've come is this code:
HTML:
<head>
<div id="outerdiv" class="navbar-fixed-top">
<img id="image1" src="image1.png" alt="Find"/>
<a href="add.php" > <img id="image2" src="image2.png" alt="Add"/></a>
</div>
</head>
CSS:
<style>
img{
display:inline-block;
border: 2px solid black;
background-color:#499FE2;
}
img:hover{
background-color: #91BCEE;
}
#image1{
width:60%;
float:left;
}
#image2{
width:40%;
float:left;
}
#outerdiv{
background-color: #black ;
}
a{
display: block;
}
</style>
The main problem I'm having is that I cannot figure out where to implement the padding so that it will separate the two images and surround them.
First you need to clean up you HTML code into valid HTML so that your CSS selectors are able to apply styles to the elements in the DOM. Remove the backslashes from your HMTL code to give you this;
<head>
<div id="outerdiv" class="navbar-fixed-top">
<img id="image1" src="image1.png" alt="Find"/>
<a href="add.php" > <img id="image2" src="image2.png" alt="Add"/></a>
</div>
</head>
Add a -4px left-margin to the images to counter the space used by the borders (this prevents the second image from going to next line since they occupy 60% + 40% of the entire page width, yet right + left borders of images take up 4px).
Also add display:block; property to the "#outerdiv" selector and change the value of the display property for the "a" selector to inline.
img{
display:inline-block;
border: 2px solid black;
background-color:#499FE2;
margin-left:-4px;
}
img:hover{
background-color: #91BCEE;
}
#image1{
width:60%;
float:left;
}
#image2{
width:40%;
float:left;
}
#outerdiv{
background-color:black;
display: block;
}
a{
display: inline;
}
see working snippet
img{
display:inline-block;
border: 2px solid black;
background-color:#499FE2;
margin-left:-4px;
}
img:hover{
background-color: #91BCEE;
}
#image1{
width:60%;
float:left;
}
#image2{
width:40%;
float:left;
}
#outerdiv{
background-color:black;
display: block;
}
a{
display: inline;
}
<head>
<div id="outerdiv" class="navbar-fixed-top">
<img id="image1" src="image1.png" alt="Find"/>
<a href="add.php" > <img id="image2" src="image2.png" alt="Add"/></a>
</div>
</head>

Why aren't these img's counted in the parent div?

The images at the bottom arent't counted in the overflow:hidden attribute in the all class. They overflow and the positioning is very difficult as the border of the all div does not follow the images down.
<div class="all">
<div id="banner"><img src="images/banner1.jpg" alt="PCXD Banner"/></div>
<div class="nav">
...
</div>
<h1 class="under"><br/><br/>Image><br/></h1>
<table>
...
</table>
<img id="reviewI1" src="images/RL1.jpg" alt="Rocket League 1"/>
<img id="reviewI2" src="images/RL2.jpg" alt="Rocket League 2"/>
<img id="steam2" src="images/steam.png" alt="Steam"/>
</div>
CSS:
.all{
width:1200px;
margin:auto;
border:5px solid #404040;
overflow:hidden;
}
#reviewI1 {
width:500px;
position:absolute;
top:415px;
left:1010px;
border: 3px solid #fedd58;
}
#reviewI2 {
width:500px;
position:absolute;
top:710px;
left:1010px;
border: 3px solid #fedd58;
}
#steam2 {
width:100px;
left:1210px;
position:absolute;
top:1010px;
}
You need to add a height to the .all class e.g. height: 400px;
Yours images are in absolute position, that mean they are out of the DOM flow.
So the overflow property won't apply in that case. You need to remove absolute position to use it :
#reviewI1 {
width:500px;
top:415px;
border: 3px solid #fedd58;
}
See this fiddle
Remove the "position:absolute" from the images' styling.

HTML+CSS Menu with icons, combining 2 pictures

I have 2 questions (more like 1.5)
1) What would be the correct way to modify the menu in the first picture to look like the one in the second. Since I put both the picture and the text in the same <a> tag I'm having problems with the white border (the icons are 30x30px, no transparent space around them or anything) :
HTML:
<div id="header">
<div class= "main">
<div class="logoHeader">
<img src="logo.png">
</div>
<div class="menuPicHeader">
<img src="stovyklae.png"><h2>stovykla</h2>
<img src="klubase.png"><h2>klubas</h2>
<img src="elparde.png"><h2>el. parduotuvÄ—</h2>
<img src="kontaktaie.png"><h2>kontaktai</h2>
</div>
<div class="socialIconsWrapHeader">
<img src="yttop.png">
<img src="ftop.png">
</div>
</div>
</div>
CSS:
h2{
display:inline-block;
text-transform: uppercase;
text-decoration: none;
color: black;
margin-left:10px;
margin-right:10px;
font-size:14px;
}
.logoHeader{
margin-left:15px;
float:left;
margin-bottom: 20px;
margin-top:15px;
}
.socialIconsWrapHeader{
float:right;
margin-top:15px;
margin-right:20px;
}
.socialIconsWrapHeader a{
margin:0px 10px 0px 10px;
}
.menuPicHeader{
float:left;
margin:20px 0px 0px 130px;
padding-left:10px;
}
.menuPicHeader a{
padding-top:20px;
padding-bottom:2px;
}
2) I was wondering what should I use to get the text onto the picture as seen here:
Should I cut the picture in a half, get some div and stick it to the bottom of the picture using the grey half as background? Or somehow just write on top of the <a>?
HTML:
<div class="rightCol1">
<img src="pic1.png">
<img src="pic2.png">
</div>
CSS:
.rightCol1{
float:right;
margin-right:30px;
margin-top:10px;
}
1: add .menuPicHeader a{ margin-right: 20px; }
http://jsfiddle.net/Lphup/
2: There are a lot of ways to do that, but here's one option:
http://jsfiddle.net/33vth/
for second
<div class="rightCol1">
<img src="pic1.png"><span>your text</span>
<img src="pic2.png"><span>your text</span>
</div>
CSS:
.rightCol1{
float:right;
margin-right:30px;
margin-top:10px;
}
.rightCol1 a {display:inline-block;position:relative;height:200px;width:100px;}
.rightCol1 a span {display:block;width:100px;height:70px;position:absolute;bottom:0;left:0;z-index:99;background:#333}
You can have more positioning control over the elements if you set their parent's positioning to 'relative' and then set their positioning to absolute. This lets you use top, left or right to set an absolute position for the child objects, in relation to their parent.
I didn't have a chance to try this, but something like this should do the trick:
.menuPicHeader { position: relative; }
.menuPicHeader a { position: absolute; top: 0; }

Make a div css change when hover an other div

My code is not working. I found this is because the divs whoch have to change are in an other div... How to bypass the div containing others?
In this example I want the background color change of "partagefb" div when hovering "partage" div
demo: http://jsfiddle.net/u7tYE/1994/
Thanks
html:
<div class="partage" id="partage_70"><img src="/themes/glace_et_ombre/images/partage.png" border="0" width="22" height="21"></div>
<div class="enveloppe_partage">
<div class="partagefb"></div>
</div>
css:
.partage{
position:relative;
float:left;
margin: 2px;
cursor:pointer;
z-index: 100;
width:20px;
height:20px;
}
.partagefb{
position:relative;
width: 25px;
height: 25px;
margin:100px;
background: #ccc;
}
.partage:hover ~ .partagefb{
background-color:#000000;
}
.enveloppe_partage{
position: absolute;
margin: -28px 0 0 115px;
}
The problem is with your selector
use
.partage:hover + .enveloppe_partage .partagefb{
background-color:#000000;
}
Here is the fiddle
Add Id to the div
Make HTML as
<div class="partage" id="partage_70">
<img src="/themes/glace_et_ombre/images/partage.png" border="0" width="22" height="21">
</div>
<div class="enveloppe_partage" id="ank">
<div class="partagefb"></div>
</div>
And CSS could be
#partage_70:hover + .enveloppe_partage #ank {
background-color:#000000;
}

Where did this white space came from?

I am having problems with my sidebar_box, as it is displaying a unwanted white space at the bottom of my images.
The thing is that this seems to happen only when I place an image inside (this doesn't happen with text or ul lists)
You can see this jsFiddle
My HTML structure:
<div id="sidebar">
<div class="sidebar_box">
<div class="sidebar_header">Advertisement</div>
<img src="./images/square_add.png" width="180" height="150" />
</div>
</div>
The relevant CSS to reproduce:
*{
padding:0;
margin:0;
}
img{
border:0;
}
#sidebar .sidebar_box{
width:180px;
background:#fff;
border:1px solid #000;
}
#sidebar .sidebar_header{
width:180px;
background:#ddd;
border-bottom:1px solid #000;
}
I am clueless and I have already tried everything of my knowledge.
Add vertical-align: bottom to your image. This happens because images are displayed inline, meaning they have to leave space below in case of q, p or other letters that drop below the baseline.
write this:
img{
border:0;
vertical-align:top;
}
Check this http://jsfiddle.net/sKE6y/1/