I have a lot of images having inline-block display type within a fixed width div.
The images have a margin of 0 5px 5px 0 which means you get a nice table effect when you have many of them.
Unfortunately this creates a side effect where the containing div has extra space between the images and its padding at the bottom and right.
How can I fix this?
CSS
div{
padding: 10px;
max-width: 191px;
background: #ddd;
}
img {
max-width: 30px;
min-height: 23px;
margin:0 5px 5px 0;
display: inline-block;
}
HTML
<div>
<img src="..." />
<img src="..." />
<img src="..." />
<img src="..." />
</div>
Fiddlesis
DEMO
Change your div's padding to this:
padding:10px 5px 0 10px;
A quick approach could be to simply justify align with margins of auto for right and left and vertical align middle:
Fiddle
div{
padding: 10px 10px 5px;
max-width: 191px;
background: #ddd;
text-align:justify;
}
img {
max-width: 30px;
min-height: 23px;
margin:0 auto 5px auto;
vertical-align:middle;
display: inline-block;
}
rearrange padding for your div and set image as vertical-align:top or bottom to erase the gap under it .
div{
padding: 10px 10px 5px;
max-width: 191px;
background: #ddd;
}
img {
max-width: 30px;
min-height: 23px;
margin:0 5px 5px 0;
vertical-align:top;
display: inline-block;
}
http://jsfiddle.net/LnHDc/1/
Else dispatch margin and padding and see how to deal with white-space (code not indented, use of comment, font-size to 0 , .... ) http://jsfiddle.net/LnHDc/4 or http://jsfiddle.net/LnHDc/5 or http://jsfiddle.net/LnHDc/6 .
you have many ways to approach this, eeven floatting image .
Related
I have a small issue with a website I'm creating.
The page has a background and a white body in the center, in the white body there is padding for the text so it doesn't start at the border.
#content
{ width: 900px;
overflow: hidden;
margin: 0 auto 0 auto;
padding: 20px 30px 20px 31px;
background: #FFFFFF;
text-align: left;}
So the problem is I have a jquery gallery in the top of the content body, but I don't want the gallery to have the padding around it, I mean, the white body. I want the gallery to start at the border of the body and end at the other end.
So I figured I have to make a new CSS tag without padding or negative padding but that isn't working.
How can I fix this?
You can use negative margins that match the padding amount to make the gallery flush with the edges.
body {
background: #eee;
}
#content {
width: 900px;
overflow: hidden;
margin: auto;
padding: 20px 30px 20px 31px;
background: #FFFFFF;
text-align: left;
}
.flush {
background: #171717;
color: #fff;
margin: 0 -30px 0 -31px;
}
<div id="content">
<div>normal</div>
<div class="flush">flush</div>
</div>
The following is the code for index.html
figure,
figcaption {
display: block;
}
figcaption {
color: black;
}
#profile_photo {
padding: 10px 20px;
width: 100%;
overflow: hidden;
}
#profile_photo figure {
padding: 6px 8px 10px 8px;
float: left;
position: relative;
width: 200px;
}
<div id="profile_photo">
<figure>
<img src="http://www.placehold.it/200X350" alt="Profile Photo" height="350px" />
<figcaption>Welcome</figcaption>
</figure>
</div>
The padding for the image is not being displayed. What am I doing wrong?
If it helps, I'm trying to complete Step 2 of the following tutorial
It's being displayed as others have commented, you just have no background color in order to see it. If you use inspection tools you'll see the padding is there.
#profile_photo figure{
padding: 6px 8px 10px 8px;
float: left;
position: relative;
width: 200px;
background: red;
}
Working example
the padding is actually showing
but if you want to give some space between the image and the space between image and text try assigning the padding to the tag
img{ padding: 6px 8px 10px 8px; }
Try putting
#profile_photo img instead of #profile_photo figure since the HTML might not render <figure> tag
Im trying to make pictures align evenly inside a div with the div width dependent on the picture width so it can adapt to wider and slimmer screens. How can this be done? So far my attempt is:
<style>
.pictures {
width: auto;
border-radius: 30px 0 30px 0;
background: white;
text-align: justify;
}
img {
border-radius: 30px 0 30px 0;
border-style: solid;
border-width: 0 1px 3px 0;
border-color: rgba(0,0,0,1);
height: 199px;
margin: 15px;
}
</style>
...(some code that is superfluous with respect to the question)...
<article>
<div class="pictures">
<img src="images/001.jpg">
<img src="images/002.jpg">
<img src="images/003.jpg">
<img src="images/004.jpg">
<img src="images/005.jpg">
</article>
</body>
The "width: auto;" seems to do nothing. Is there a better way of trying to make the div fit snug with its contents?
You could trigger text-align:justify on every line adding an extra invisible line a the end. DEMO
.pictures {
width: auto;
border-radius: 30px 0 30px 0;
background: white;
text-align: justify;
}
.pictures:after {
content:'';
display:inline-block;
width:100%;
}
use display:flex properties. DEMO
.pictures {
width: auto;
border-radius: 30px 0 30px 0;
background: white;
display:flex;
justify-content:space-between;
flex-wrap:wrap;
}
Both render will not align the last line as column would do.
See the use of column properties: DEMO
.pictures {
width: 100%;
border-radius: 30px 0 30px 0;
background: white;
text-align: justify;
column-width:250px;/* add prefix if needed */
}
You can do this very easy by using the image as background:
<div style="background-image: url('image1.jpg');"></div>
<div style="background-image: url('image2.jpg');"></div>
<div style="background-image: url('image3.jpg');"></div>
div{
background-position: center center; /* IE8 support, not required */
background-position: cover;
background-size: 100%;
}
Here in the image Title "Accounts and Holding Disclosure in crossing the white line while DRF is way above the white line...
How can i put the text just above the line using css.
Html code is
<div class="tabs">
<img src="images/disclosure.png" />
Accounts and Holdings Disclosure</div>
<div class="tabs">
<img src="images/drf.png" />
DRF</div>
Css is
.tabs
{
height: 85px;
border-bottom: 1px solid #fff;
text-align: center;
color: #fff;
padding-bottom:7px;
}
.tabs img
{
display: block;
margin-left: auto;
margin-right: auto;
height: 70px;
margin-top: 5px;
}
you should write:
.tabs {
height: auto;
}
There is simply not enough splace in the first block to apply the padding. The .tabs is 85px height, the image is 70px height with a margin of 5px top. So the remaining vertical space for your text is 10px only, and you add 7px of padding.
You need to reduce the size of the image in my opinion.
should be :
.tabs {
height: 90px;
}
I am making div with image and text. User can hover on this div to get dropdown.
I have issue on alignment of dropdown. I need it to be aligned with the right border of hovered div:
This is the code:
<div id="hoverDiv">
<img alt="" width="32px" height="32px" src="http://www.fordesigner.com/imguploads/Image/cjbc/zcool/png20080526/1211776868.png" />
Hover Me!
<div class="showme">
<p>
Hidden Stuff!</p>
</div>
</div>
And CSS
#hoverDiv
{
width: 100px;
height: 40px;
float: right;
margin-right: 5%;
}
#hoverDiv:hover
{
background: #ff0000;
}
#hoverDiv:hover .showme
{
display: inline;
float: left;
position: relative;
margin-left: 5px;
margin-right: 5px;
}
.showme
{
display: none;
width: 100px;
height: 200px;
background: #0000ff;
margin: 0px auto;
float: left;
left: -999em;
padding: 10px 5px 0px 5px;
border: 1px solid #777777;
border-top: none;
z-index: 10;
position: absolute;
left: auto;
top: auto;
}
In #hoverDiv, add position:relative
In #hoverDiv:hover div.showme:
Remove float:left (redundant)
Remove position:relative (redundant)
Remove margin-left:5px && margin-right:5px unless you prefer them
In div.showme:
Remove float:left (redundant)
Remove left:-999em (redundant)
Replace left:auto with right:0
This jsFiddle has all the work done for you.
Did you mean something like this?
http://jsfiddle.net/nbZmG/9/
Here's another one -
http://jsfiddle.net/nbZmG/10/
Notice that in both cases, the width of the blue box is 120px, and they are aligned according to the left and right side of the red box using margin.
Hope this helped.
You're adding margin-left:5px on hover on your .showme div, remove that and it should align:
#hoverDiv:hover .showme {
display: inline;
float: left;
margin-left: 0; /* here */
margin-right: 5px;
position: relative;
}
In #hoverDiv:hover .showme remove margin-left and margin-right.
In .showme remove margin and modify padding to 10px 0px 0px 0px, and border: 1px to 0px.