Images displaying a margin with none specified [duplicate] - html
This question already has answers here:
Images side by side without any space between them
(5 answers)
Closed 7 years ago.
I've written a very basic registration form for a football team, which is working as expected.
However, after adding two place-holder images at the bottom of the page, they are exhibiting a gap between each other in Chrome, Firefox and IE11. I'm wondering why this would be, as I've used this CSS Reset, and I haven't specified any margins or spacing for the images. Furthermore, using 'Inspect element' in Chrome does not show any graphical representation of the gap in any way.
html,body,div,span,applet,object,iframe,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,dl,dt,dd,ol,ul,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,label,legend,p,blockquote,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-weight:inherit;font-style:inherit;font-size:100%;font-family:inherit;vertical-align:baseline;}body{line-height:1;color:black;background:white;}:focus{outline:0;}table{border-collapse:collapse;border-spacing:0;}caption,th,td{text-align:left;font-weight:normal;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}ol,ul{list-style:none;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}blockquote:before,blockquote:after,q:before,q:after{content:"";}blockquote,q{quotes:"" "";}abbr,acronym{border:0;}
.wrapper {
margin: 50px auto;
max-width: 728px;
min-width: 320px;
}
#sponsors {
display: block;
margin-top: 10px;
text-align: center;
}
<div class="wrapper">
<div id="sponsors">
<img alt="Sponsor 1 Place-holder" src="http://dummyimage.com/150x75/eee/000&text=Sponsor+Placeholder" />
<img alt="Sponsor 2 Place holder" src="http://dummyimage.com/150x75/eee/000&text=Sponsor+Placeholder" />
</div>
</div>
I've provided the minimal amount of code as this still demonstrates the same behaviour. Any information would be much appreciated.
Images are inline elements by default and therefore whitespace has an effect.
One option to remove this is to set the font-size of the parent to 0.
See this question on SO for others.
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-weight: inherit;
font-style: inherit;
font-size: 100%;
font-family: inherit;
vertical-align: baseline;
}
.wrapper {
margin: 50px auto;
max-width: 728px;
min-width: 320px;
}
#sponsors {
display: block;
margin-top: 10px;
text-align: center;
font-size: 0;
}
<div class="wrapper">
<div id="sponsors">
<img alt="Sponsor 1 Place-holder" src="http://dummyimage.com/150x75/eee/000&text=Sponsor+Placeholder" />
<img alt="Sponsor 2 Place holder" src="http://dummyimage.com/150x75/eee/000&text=Sponsor+Placeholder" />
</div>
</div>
This is the newline between the img tags being visible (any amount of whitespace is treated as a single space). You could put the tags on the same line, or add font-size:0px; to your #sponsors rule.
You can use HTML comments to remove the inline whitespace caused by putting the <img> tags on two separate lines.
<div class="wrapper">
<div id="sponsors">
<img alt="Sponsor 1 Place-holder" src="..." /><!--
--><img alt="Sponsor 2 Place holder" src="..." />
</div>
</div>
... which would be the same as writing it as
<div class="wrapper">
<div id="sponsors">
<img alt="..." src="..." /><img alt="..." src="..." />
</div>
</div>
Related
Container shifting up when text is on two lines [duplicate]
This question already has answers here: Align inline-block DIVs to top of container element (5 answers) Closed 4 years ago. So if you look at the 2nd image, it shifts up when the text under spans onto two lines. Maybe this is to do something with the div containers that I'm missing? Can't seem to find the right solution. I'm not super HTML savvy but I'm sure this is a simple fix? ..help! Screenshot Here #wrapper { width: 100%; height: auto; margin: 0; padding: 0; } .thumb { position: relative; display: inline-block; width: 17.6%; height: auto; box-sizing: border-box; margin: 10px 1%; padding: 0; text-decoration: none; } .thumb p { font-family: "Helvetica", helvetica; color: #aaa; margin-left: 0em; margin: 0.5em; } .thumb img { width: 100%; height: 230px; display: block; margin: 0 auto; } <body style="margin: 0px;"> <div id="wrapper"> <h1>GALLERY</h1> <h2>LENDING LIBRARY</h2> <a id="Altamont Wet WR" class="thumb" href="openwindow-https://www.urbanelectricco.com/altamontwall.html"> <img src="thumbs/altamontwall_mtn.jpg" /> <p>Altamont Wet WR</p> <hr> <h3>'Kromezone' Powder Coat, Clear Glass</h3> </a> <a id="Archibald" class="thumb" href="openwindow-https://www.urbanelectricco.com/archibald.html"> <img src="thumbs/archibald_mtn.jpg" /> <p>Archibald WR</p> <hr> <h3>Bronze Finish, Clear Glass & Black Finish, Clear Glass </h3> </a> <a id="Belle Meade" class="thumb" href="openwindow-https://www.urbanelectricco.com/bellemeade.html"> <img src="thumbs/bellemeade_mtn.jpg" /> <p>Belle Meade WL</p> <hr> <h3>Vintage Finish</h3> </a> <a id="Belle Meade Double" class="thumb" href="openwindow-https://www.urbanelectricco.com/bellemeadedouble.html"> <img src="thumbs/bellemeadedouble_mtn.jpg" /> <p>Belle Meade Double WL</p> <hr> <h3>Polished Nickel Finish</h3> </a>
Best way of getting the alignment to be the same across all of the thumbnails is add the following to the .thumb class: vertical-align:top; The reason why the issue arises is that the standard vertical alignment for any div is baseline (right at the bottom). When your text goes onto a second line, it naturally increases the height of that element (and is double the height of all of the other tags) and pushes everything else in that particular div upwards. Hope that helps!
Align thumbnail Images with different sizes, and with caption, at bottom
I have a simple thumbnail with images and a caption for each image. The images do not have the same height but are always 125px. Captions can be short and long, they do not have the same height. I want to align all of the images at the bottom so i can put the caption at the same level. Did some research here and was able to align the images at the bottom, but without the caption https://jsfiddle.net/0bzz7397/2/ .thumb { display: flex; flex-wrap: wrap; align-items: flex-end; } .thumb > div { flex: 0 0 125px; background-color: white; } .thumb > div ~ div { margin-left: 20px; } When i add the caption, well, it's a MESS! https://jsfiddle.net/fuk45osb/1/ EDIT: i've included an example with multiple wrapped thumbs https://jsfiddle.net/fuk45osb/5/ Basically, this is the effect i'm hoping for. Images with different height are all aligned at the bottom, and the caption starts at the same level. It's simple and clean. Ive try using flexbox. But, maybe i'm wrong and there are better ways. Any ideas how to achieve this ?
In this very limited scenario I'd use absolute positioning for title and subtitle. body { background: #eee; } .thumb { display: flex; flex-wrap: wrap; align-items: flex-end; } .thumb>div { flex: 0 0 125px; background-color: white; position: relative; } .thumb>div~div { margin-left: 20px; } .title { position: absolute; top: 100%; background: #fff; width: 100%; } <div class="thumb"> <div> <img src="" width="125" height="125"> </div> <div> <img src="" width="125" height="170"> <div class="title">wefweergergerg erg er erg erg erg er gfwef</div> </div> <div> <img src="" width="125" height="125"> </div> <div> <img src="" width="125" height="130"> </div> <div> <img src="" width="125" height="160"> </div> <div> <img src="" width="125" height="125"> <div class="title">wefwefwef</div> </div> <div> <img src="" width="125" height="125"> </div> </div>
I kept researching a couple of more hours here and found an answer, for those who are interested. The answer comes from this very similar post created years ago: Align multiple images (with captions) to baseline, all different heights Basically, you just need to change the attribute align-items from flex-end to baseline. As simple as that. Here's a working example https://jsfiddle.net/fuk45osb/7/
CSS: Two Logos aligned to the left and to the right which should autoscale by window resize
I have two logos on my website which should go on top of my website. One logo should be aligned to the left and the second logo to the right. Now when the browser window gets pushed smaller, the space in between those two logos should get narrower and eventually when the two logos "hit" each other, both are supposed to scale smaller without breaking the line. Right now only the left logo scales down and the right logo breaks the line and gets pushed lower without scaling down at all. Can anybody help me? My CSS: .image-wrapper { position: relative; white-space: nowrap; } .scale-image { display: block; width: auto; max-width: 55%; white-space: nowrap; } Here is my HTML code: <div class="image-wrapper"> <a href="#" ><img src="http://www.drogies-test.de/wp-content/uploads/2016/05/Logo_oskar.jpg" align="left" class="scale-image"/></a> <div /> <div class="image-wrapper"> <a href="#" target="_blank" ><img src="http://www.drogies-test.de/pics/Logo_theater_os.gif" align="right" class="scale-image"/></a> <div /> Example link: http://www.drogies-test.de/header_show.html
I've adjusted the mark-up structure to nest elements correctly. .image-wrapper:first-of-type,.image-wrapper:nth-child(1) { float: left; } .image-wrapper:last-of-type,.image-wrapper:nth-child(2) { float: right; } .image-wrapper { max-width: 50%; } .scale-image { width: 100%; height: auto; } <body> <div class="image-wrapper"> <img src="http://www.drogies-test.de/wp-content/uploads/2016/05/Logo_oskar.jpg" align="left" class="scale-image"> </div> <div class="image-wrapper"> <img src="http://www.drogies-test.de/pics/Logo_theater_os.gif" align="right" class="scale-image"> </div> </body> Here's a flex solution: .image-wrapper { max-width: 50%; } .scale-image { width: 100%; height: auto; } .flex-wrapper { display: flex; justify-content: space-between; } <div class="flex-wrapper"> <div class="image-wrapper"> <img src="http://www.drogies-test.de/wp-content/uploads/2016/05/Logo_oskar.jpg" align="left" class="scale-image"> </div> <div class="image-wrapper"> <img src="http://www.drogies-test.de/pics/Logo_theater_os.gif" align="right" class="scale-image"> </div> </div> Note that flex is not supported in legacy browsers like IE 8 and 9, and some older versions of webkit browsers like Safari and Firefox (a deprecated or hybrid syntax variation is supported instead). Learn more: caniuse.com
Where does this margin come from? [duplicate]
This question already has answers here: Remove white space below image [duplicate] (9 answers) Closed 7 years ago. I have a margin between the images and the Share us and I don't really know where it comes from. img: https://liko.tinytake.com/sf/MTU4MjUyXzk4ODk1MA My HTML5 code: <div id="socailMedia"> <p>Follow us:</p> <div id="followImg"> <img src="socailMedia/facebook.png" alt="followFacebook"> <img src="socailMedia/twitter.png" alt="followTwitter"> <img src="socailMedia/instagram.png" alt="followInstagram"> <img src="socailMedia/pinterest.png" alt="followPinterest"> <img src="socailMedia/google.png" alt="followGoogle"> </div> <p>Share us:</p> </div> My CSS code: #socailMedia{ color:#939393; width: 350; float:left; margin-left: 20; } #socailMedia p { margin: 0; background-color: red; } #followImg img{ background-color: red; height: 35; padding:0; margin: 0; }
You need to add vertical-align: bottom to the #followImg img elements: #socailMedia { color: #939393; width: 350; float: left; margin-left: 20; } #socailMedia p { margin: 0; background-color: red; } #followImg img { background-color: red; height: 35; padding: 0; margin: 0; vertical-align: bottom; } <div id="socailMedia"> <p>Follow us:</p> <div id="followImg"> <img src="http://dummyimage.com/35x35/FC0/000" alt="followFacebook"> <img src="http://dummyimage.com/35x35/FC0/000" alt="followTwitter"> <img src="http://dummyimage.com/35x35/FC0/000" alt="followInstagram"> <img src="http://dummyimage.com/35x35/FC0/000" alt="followPinterest"> <img src="http://dummyimage.com/35x35/FC0/000" alt="followGoogle"> </div> <p>Share us:</p> </div> By default images are aligned with the baseline which rests few pixels above the bottom of the parent. Setting vertical alignment to bottom will cause the images to align with the bottom of the paragraph.
Perhaps from the enclosing "followImg" div. You've cancelled the margin attribute for the nested img tags, but haven't addressed their encompassing div. There may also be padding involved, depending on how the CSS is inherited. You can use the Web inspector in Chrome, Safari, or Firefox to take a look at the active attributes for these elements, and better troubleshoot the situation. The following might be all that's needed: #followImg { padding: 0; margin: 0; }
There is a padding that comes with paragraph tags. Try this instead: <div id="socailMedia"> <p>Follow us:</p> <div id="followImg"> <img src="socailMedia/facebook.png" alt="followFacebook"> <img src="socailMedia/twitter.png" alt="followTwitter"> <img src="socailMedia/instagram.png" alt="followInstagram"> <img src="socailMedia/pinterest.png" alt="followPinterest"> <img src="socailMedia/google.png" alt="followGoogle"> </div> <p style="margin:0;">Share us:</p> <!-- CHANGE THIS --> </div>
Div height remains zero when including images [duplicate]
This question already has answers here: Why is the parent div height zero when it has floated children (4 answers) Closed 8 years ago. I have the following code that displays 5 images horizontally across the screen, but for some reason I can not get the Div "block-before-description" to have a height, in FireBug the height is 0 but the 20px margin does show. I have tried many things including floating, display:block, position absolute/relative, and looked at previous questions to no avail. If I remove the images leaving only the heading then the block shows height to cover the headings. <style type ="text/css"> .container { margin-right: auto; margin-left: auto; padding-left: 15px; padding-right: 15px; } .col-md-2 { float: left; width: 16.66667%; position: relative; min-height: 1px; padding-left: 15px; padding-right: 15px; } .feat-icons { text-align: center; } .block-before-description { margin-bottom: 20px; padding: 0px; } </style> </head> <body> <div class="container"> <div class="block-before-description"> <div class="col-md-2 feat-icons"> <img src="icons/30-Days-Support.jpg" width="105" height="105" alt=""/> <h4>Support</h4> </div> <div class="col-md-2 feat-icons"> <img src="icons/Design-Icon.jpg" width="105" height="105" alt=""/> <h4>Premium Design</h4> </div> <div class="col-md-2 feat-icons"> <img src="icons/Features.jpg" width="105" height="105" alt=""/> <h4>Features</h4> </div> <div class="col-md-2 feat-icons"> <img src="icons/Guide-Icon.jpg" width="105" height="105" alt=""/> <h4>Gudie Included</h4> </div> <div class="col-md-2 feat-icons"> <img src="icons/Mobile-Icon.jpg" width="105" height="105" alt=""/> <h4>Mobile Supported</h4> </div> </div> </div> </body> </html> Any help on the issue would be appreciated.
This is the classic issue caused by all the containers children floating. The height of the parent is not calculated as the children are removed from the normal flow of the document. The following examples do not take into account Bootstraps ready made solutions as you have not mentioned bootstrap in your question. One option is to simply apply the overflow property to the parent: Example with overflow and floats. .block-before-description { margin-bottom: 20px; padding: 0px; background: #F00; overflow: hidden; } Another option is to not use a float at all and use display: inline-block to display your images on the one horizontal line. Example with inline-block .col-md-2 { display: inline-block; vertical-align: top; /* use middle, top or bottom to keep an even alignment */ width: 16.66667%; position: relative; min-height: 1px; padding-left: 15px; padding-right: 15px; }