CSS: Float Image [duplicate] - html

This question already has answers here:
Why doesn't the height of a container element increase if it contains floated elements?
(7 answers)
Closed 8 years ago.
Why does the float:left and float:right element cause my web page to become squashed?
This is what happens when I try to float:left or float:right.
http://prntscr.com/3fx03d
The page seems to forget the images take up space on the page
The only way to fix this is to use "<p>...</p>" at the very bottom of the images in the HTML Code then it will look like this.
http://prntscr.com/3fx13l
What is going on here?
Yes I have ensured to specify the size of the images beforehand.
HTML
<div id="main-content">
<h2>Images</h2>
<div class="images">
<img src="images/Home_Pic1.jpg" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic2.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic3.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic4.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic5.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic6.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic7.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic9.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic8.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic10.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic11.png" alt="Motivational Image" width="250" height="150">
<img src="images/Img_Pic12.png" alt="Motivational Image" width="250" height="150">
</div>
<p align="center">...</p>
</div>
<footer>
<p>© Copyright 2014 All rights reserved </p>
<ul>
<li><img src="images/rss.png" width="16" height="16" /></li>
<li><img src="images/facebook.png" alt="Facbook" width="16" height="16" /></li>
<li><img src="images/twitter.png" alt="Twitter" width="16" height="16" /></li>
<li><img src="images/share.png" width="16" height="16" /></li>
<li><img src="images/bloggr.png" width="16" height="16" /></li>
<li><img src="images/google-plus.png" width="16" height="16" border="0" /></li>
</ul>
</footer>
</div> <!--end of wrapper-->
CSS:
div.images{
position:relative;
left:0px;
float:left;
width:765px;
margin:0px -5px;
}

If I am understanding your problem correctly, in a nutshell, floated elements do not add height to the container. There are a number of ways to correct this behavior. Float the parent element, specify overflow: hidden on the parent or use a clearfix hack http://css-tricks.com/snippets/css/clear-fix/.
There is a pretty indepth article on this here at stackoverflow:
Why doesn't the height of a container element increase if it contains floated elements?

Related

How to show buttons side by side instead of stacked

so i have a table and i want the buttons side by side instead of stacked
Css or HTML is fine but not js sorry if the question isnt very clear im still new to this :/
i tried
display: flex;
align-items: center;
justify-content: center;
but that just does this
ive included the CSS and html code snippett bellow thanks to everyone who can help i kept the alts instead of the actual image because this is for my photography website
#charset "UTF-8";
button{
 display:inline-block;
 padding:0.5em 3em;
 border:0.16em solid #FFFFFF;
 margin:0 0.3em 0.3em 0;
 box-sizing: border-box;
 text-decoration:none;
 text-transform:uppercase;
 font-family:'Roboto',sans-serif;
 font-weight:400;
 color:#FFFFFF;
 text-align:center;
 transition: all 0.15s;
}
button:hover{
 color:#DDDDDD;
 border-color:#DDDDDD;
}
button:active{
 color:#BBBBBB;
 border-color:#BBBBBB;
}
#media all and (max-width:30em){
 button{
  display:block;
  margin:0.4em auto;
 }
}
<div style="text-align:center">
<button id="wildlife">EG </button><br>
<button id="landscape">EG </button><br>
<button id="ocean">EG </button>
</div>
<div class="wildlife">
<img src="Images/animals/DSC04758.jpg" eight="150" width="200" alt="rocks" />
<img src="Images/animals/bird.png" eight="150" width="200" alt="rocks" />
<img src="Images/animals/birds1.png" eight="150" width="200" alt="rocks" />
<img src="Images/animals/birds2.png" eight="150" width="200" alt="rocks" />
<img src="Images/animals/birds3.png" eight="150" width="200" alt="rocks" />
<img src="Images/animals/birds4.png" eight="150" width="200" alt="rocks" />
</div>
<div class="landscape">
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
</div>
<div class="ocean">
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
<img src="" height="150" width="200" alt="rocks" />
</div>
<font face="sans-serif" color="#017bf5" size="5" align="center">
<h1>### </h1>
</font>
<font face="sans-serif" color="#444" size="3" align="center">
<h1>###</h1>
</font>
</body>
In Your HTML Code, you used <br> tag after each button. Which pushes your button to the next line.
Solution: Remove <br> tags after button elements.
A div box around the buttons with display: flex; and flex-direction: row; Should work

Why is this basic HTML code not working as it should

First of all I'm new and I need a little help to fix this basic HTML code ,
the code is :
<head>
<title>
Shared column border
</title>
<style type="text/css">
/*<![CDATA[*/
<!--
#left { width: 5px; float: left;
border-right: 8px solid #444 }
#right { margin-left: 500px;
border-left: 8px solid #0b9cef }
/*]]>*/
</style>
</head>
<body>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20" /> <big>Secure Client Area- Portal</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20" /> <big>Urgent Delivery Available</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20" /> <big>100% Manual Photo Editing</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20" /> <big>SSL Secured Image Transfer</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20" /> <big>Monthly Payment Plan</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20" /> <big>Variety of Payment Methods</big>
</p>
<div id="right">
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20" /> <big>100% Satisfaction Gauranteed</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20" /> <big>Money-Back Gaurantee</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20" /> <big>Right Price & Best
Quality</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20" /> <big>12hr Quick Turnaround Time</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20" /> <big>Volume Discount Up to 20%</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20" /> <big>365 Days Operation Enabled</big>
</p>
</div>
</body>
</html>
I want to 2nd column in the same position as the 1st column is in.
+
I want some space between the blue separator / divider & 2nd column
Can anyone help me to fix this or Can anyone teach me how to do this ?
as I said I'm new so looking forward for some guidance !
First of all you are not using the styling rule #left that has float:left anywhwere. So no floating is happening to the p elements.
Then you are wrapping your second column with a <div id="right"> and the #right styling ruke has no float in it. Thats why the <p> elements are displaying as blocks and not aligning next to each other. Maybe wrap the first column with <div id="left"> and use the following for your #left css rule :
#left {
float: left;
border-right: 8px solid #444;
padding-right: 25px // added some padding distance between the content and right border
}
Second point, for
I want some space between the blue separator / divider & 2nd column
you can use padding (refer to this article to see the difference between padding and margin : Margin vs Padding.
Here's your updated code to provide what you need (note that I added 25px padding ditance beween the blue border and the content, and 25px distance between the left colulmn and the right one.)
<head>
<title>
Shared column border
</title>
<style type="text/css">
/*<![CDATA[*/
<!--
#left {
float: left;
border-right: 8px solid #444;
padding-right: 25px
}
#right {
border-left: 8px solid #0b9cef;
float: left;
padding-left: 25px;
margin-left: 25px;
}
/*]]>*/
</style>
</head>
<body>
<div id="left">
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20"/> <big>Secure Client Area- Portal</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20"/> <big>Urgent Delivery Available</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20"/> <big>100% Manual Photo Editing</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20"/> <big>SSL Secured Image Transfer</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20"/> <big>Monthly Payment Plan</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20"
height="20"/> <big>Variety of Payment Methods</big>
</p>
</div>
<div id="right">
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20"/> <big>100% Satisfaction Gauranteed</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20"/> <big>Money-Back Gaurantee</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20"/> <big>Right Price & Best
Quality</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20"/> <big>12hr Quick Turnaround Time</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20"/> <big>Volume Discount Up to 20%</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src=
"https://i.postimg.cc/SNJHq645/1398913.png" alt="" width=
"20" height="20"/> <big>365 Days Operation Enabled</big>
</p>
</div>
</body>
To adjust that blue line on the left you will need to add padding to the left ( I made it 10px but you can adjust it)
And set the width of the left to look good for you.
Here is the code
<body>
<title>
Shared column border
</title>
<style type="text/css">
/*<![CDATA[*/
<!--
#left {
width: 300px;
float: left;
border-right: 8px solid #444 }
#right {
margin-left: 500px;
border-left: 8px solid #0b9cef;
padding-left: 10px;
}
/*]]>*/
</style>
<div id="left">
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>Secure Client Area- Portal</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>Urgent Delivery Available</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>100% Manual Photo Editing</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>SSL Secured Image Transfer</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>Monthly Payment Plan</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>Variety of Payment Methods</big>
</p>
</div>
<div id="right">
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>100% Satisfaction Gauranteed</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>Money-Back Gaurantee</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>Right Price & Best
Quality</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>12hr Quick Turnaround Time</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>Volume Discount Up to 20%</big>
</p>
<p>
<img class="alignnone size-thumbnail wp-image-5242" src="https://i.postimg.cc/SNJHq645/1398913.png" alt="" width="20" height="20"> <big>365 Days Operation Enabled</big>
</p>
</div>
</body>

Underscore between pictures in html

I am trying to put multiple icons (pictures) in one line, and when I do that, I get underscores between each picture.
<img alt="Facebook" src="Facebook.png">
<img alt="Youtube" src="Youtube.png">
<img alt="Twitter" src="Twitter.png">
<img alt="Instagram" src="Instagram.png">
And this is how does it look like
See attached picture, notice the underscores between each picture.
Because of your spaces between <a> tags and <img> tags.
<img alt="Facebook" src="Facebook.png">
<img alt="Youtube" src="Youtube.png">
<img alt="Twitter" src="Twitter.png">
<img alt="Instagram" src="Instagram.png">
Browser considers you are in a link string, even if there is an image. So it will underline the link as usual.
a{
text-decoration:none;
}
<img alt="Facebook" src="Facebook.png">
<img alt="Youtube" src="Youtube.png">
<img alt="Twitter" src="Twitter.png">
<img alt="Instagram" src="Instagram.png">
Remove the space after the img tag within a tag which treated as a character and in default a tag has the underline(CSS text-decoration property).
<img alt="Facebook" src="Facebook.png">
<!-- -^- -^- -->
<img alt="Youtube" src="Youtube.png">
<img alt="Twit11ter" src="Twitter.png">
<img alt="Instagram" src="Instagram.png">
Use following code:
a {
text-decoration: none;
}

How to replace an IMG with a smaller IMG but without messing up the style

I am dynamically creating HTML code out of C#.
What I want is: replace each IMG-Tag with a smaller IMG-File (which is a loading-gif). But: the whole style/Layout should remain the same (as the HTML-File I am loading is completely dynamic and could contain anything.
So a sample:
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
<span>Geographie</span>
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
<span>Geschichte</span>
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
<span>Gesellschaft</span>
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
Several Images in a Row. Now I want to replace one of them (here: number 3) with a smaller image (here: a smiley) but: I want to have the same layout. So I tried this: Create a container which has the same size of the original Image and then I created the small image in it.
My problem is: As I am using DIV, it does a line break...
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
<span>Geographie</span>
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
<span>Geschichte</span>
<div style="height: 100px; width: 100px; background-color:red;display: flex; ">
<img alt="" src="https://affinity.serif.com/forum/public/style_emoticons/default/smile.png" height="20" width="20" style="margin: auto;">
</div>
<span>Gesellschaft</span>
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
How can I solve this?
I really am looking for replacing only the -tag with something that has the same dimension/properties and can contain another image...
The reason your container is causing a line break is because divs default to have a style of "display:block;"
You can fix this by changing the display style to inline-block. You'll then want to make sure it's aligned properly with "vertical-align: top;"
See fixed snippet:
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
<span>Geographie</span>
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">
<span>Geschichte</span>
<div style="height: 100px; width: 100px; background-color:red; display: inline-block; vertical-align:top; ">
<img alt="" src="https://affinity.serif.com/forum/public/style_emoticons/default/smile.png" height="20" width="20" style="margin: auto;">
</div>
<span>Gesellschaft</span>
<img alt="" src="http://csharpcorner.mindcrackerinc.netdna-cdn.com/UploadFile/mahesh/rectangle-in-wpf/Images/RectI.gif" height="100" width="100">

Text on top of an image

I want to make a navigation bar, with each item having its own image with the name of the item written on top of that. So there should be a few images in a row, and each one has some text written on it. This is the row of images I got:
<div class="navigation" align="center">
<img src="images/bn_blue.png" width="120" height="70" alt="" />
<img src="images/bn_blue.png" width="120" height="70" alt="" />
<img src="images/bn_blue.png" width="120" height="70" alt="" />
<img src="images/bn_blue.png" width="120" height="70" alt="" />
<img src="images/bn_blue.png" width="120" height="70" alt="" />
<img src="images/bn_blue.png" width="120" height="70" alt="" />
</div>
<div class="navigation" align="center">
<ul><li><div style="background-image:url(images/bn_blue.png);width:120px;height:70px">xyz</div></li>
<li><div style="background-image:url(images/bn_blue.png);width:120px;height:70px">xyz</div></li>
<li><div style="background-image:url(images/bn_blue.png);width:120px;height:70px">xyz</div></li>
<li><div style="background-image:url(images/bn_blue.png);width:120px;height:70px">xyz</div></li>
<li><div style="background-image:url(images/bn_blue.png);width:120px;height:70px">xyz</div><li>
</ul>
</div>
<style>
li
{
display:inline-block;
}
</style>
Give each a href a class ie .home_bg etc.
Then in css add a
.home_bg {
background-image: url(/example/example.png)
}
do this for each image if they are different. Then in the html remove img tags