Where does this margin come from? [duplicate] - html

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>

Related

Reduce div width to size of child paragraphs and image [duplicate]

This question already has answers here:
How can I make a div not larger than its contents?
(43 answers)
Closed 9 months ago.
So I have this kind of structure:
<div class="caption">
<img src="...">
<p>Something</p>
<p>SomethingElse</p>
<p>SomethingElseAgain</p>
</div>
Every paragraph MUST be in its own line, justified to the left, and my .caption div must not take any more horizontal space than its children need.
I tried with
.caption { display: inline-block; } but that doesn't reduce the caption div at all.
I tried adding float: left to div.caption children, but all <p> tags got jumbled in one line.
How should I do this? I'm using plain html+css
In modern browsers you can simply use fit-content:
.caption {
border:1px solid red;
width:fit-content;
}
<div class="caption">
<img src="...">
<p>Something</p>
<p>SomethingElse</p>
<p>SomethingElseAgain</p>
</div>
Something else
<div class="caption">
<img src="...">
<p>Something</p>
<p>SomethingElse</p>
<p>SomethingElseAgain</p>
</div>
<style>
.caption {
width: auto;
height: auto;
}
.caption img {
width:200px;
height:200px;
}
.caption p {
display: block;
text-align: left;
}
</style>

White line between the header and a section is visible [duplicate]

This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 3 years ago.
For some reason a white line between the header and a section is visible that I have no idea why it is there, I double-checked and it's part of the content and not the padding, and I have no idea how to remove it that the header won't have that line between itself and the section below it, can someone have a look to see if there is something I missed in code?
header {
position: relative;
}
.headImage {
width: 100%;
height: 100%;
}
<header>
<img class="headImage" src="../images/Corson.with.wings.png" alt="Head Image">
</header>
I have added 3 solutions to fix the issue its because the default vertical-align value of the image is baseline; and img is considered as inline element
body {
background: url(https://placeimg.com/640/480/nature);
background-size: cover;
}
.header {
position: relative;
width: 100px;
margin: 10px;
background: red;
float:left;
}
.headImage {
width: 100%;
height: 100%;
}
.header.block img {
display: block; /* this will set image as a block */
}
.header.v-align img {
vertical-align: middle; /* this will align the inline element in the middle */
}
.header.f-left img {
float:left; /* in this case you will need to clear floats */
}
<div class="header">
<img src="https://placeimg.com/100/100/any" />
</div>
<div class="header block">
<img src="https://placeimg.com/100/100/any" />
</div>
<div class="header v-align">
<img src="https://placeimg.com/100/100/any" />
</div>
<div class="header f-left">
<img src="https://placeimg.com/100/100/any" />
</div>

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!

Images displaying a margin with none specified [duplicate]

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>

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;
}