Firefox float behaves differently then in Chrome and IE - html

I'm building a website, and have floated an image to the right of a div with some text to the left, which I have done many times before. However for some reason, the image is not floating completely over to the right in FF, but is in Chrome and IE/Edge. It's probably something really obvious, but any insight?
Firefox
Chrome/IE
HTML
<div class="wrapper">
<img src="http://www.chriswickham.co.uk/gohard/img/workouts/hammer_curl.png" height="85%" style="float:right;padding-left:40px"/>
<h1>Hammer Curl</h1>
<h2>Arms</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer dignissim ut mauris in vehicula. Suspendisse sodales nec quam in convallis. In quis ante eros. Pellentesque id lacus et massa tempor hendrerit.</p>
<div style="clear:both"></div>
</div>
CSS
.wrapper {
margin: 0px auto;
width: 1000px;
padding: 20px 0px;
}

You should group your text and title elements together, and provide them a width.
From the snippet you supplied, it looks like both screenshots are actually obeying the rules you've supplied - both are floating the image to the right of your text.
However, there's no specification of how far over it should be -- just how far from the text (40px padding-left) and how large the ENTIRE item should be ("wrapper" # 1000px);
Try this:
<div class="wrapper">
<img src="http://www.chriswickham.co.uk/gohard/img/workouts/hammer_curl.png" height="85%" style="float:right;padding-left:40px"/>
<div class="content">
<h1>Hammer Curl</h1>
<h2>Arms</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer dignissim ut mauris in vehicula. Suspendisse sodales nec quam in convallis. In quis ante eros. Pellentesque id lacus et massa tempor hendrerit.</p>
</div>
<div style="clear:both"></div>
</div>
CSS
.content {
width: 700px // or whatever you want to set it to
}
By wrapping the non-image elements together, and specifying a width for them specifically, you should be able to keep the experience the same across most browsers.
EDIT: Fixed some formatting.

Related

Expanding div to fit beside a float right div

I'm trying to figure out this layout issue, and I'm not entirely certain it's possible, but I thought someone here might have an idea.
<div class="outer" style="width:500px;">
<div class="rightFloat" style="float:right; width:max-content; height: 50px; background-color: transparent;">
<P>
This is content that should be right float.
</P>
</div>
<div class="Content" style="background-color:#eeeeac;">
<div class="conditionalDiv" style="background-color: #eeacee; border: 2px solid black">
This is conditional content that should not push the right float content down. The pink background should not be under the float content.
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer auctor pharetra quam id ullamcorper. Donec venenatis felis eu pulvinar porta. In non facilisis leo. Nulla ut lorem at enim tincidunt viverra. Vivamus id tempus eros. Fusce ultrices lectus sed ante hendrerit, et auctor tortor consectetur. Nam egestas sem tempor urna convallis, non maximus libero condimentum. Nullam non egestas neque.</p>
</div>
</div>
What I would like to do is to have the conditionalDiv (pink, conditional content that may or may not be present) only take up the space leading up to the rightFloat div. The rightFloat div should remain a consistent size (it's currently defined as width:max-content; I'd prefer not setting a fixed size if it can be avoided). In the referenced code, a working solution would have the border and background of the conditionalDiv not overlapping the space under the rightFloat div. (Float background should be white, with no border.)
The goal is that if the conditionalDiv is present, it's displayed beside the rightFloat div, and the main content continues below. Otherwise, if the conditional (pink) div is not present, the yellow content wraps around the rightFloat div.
I've tried a variety of ordering changes. I did a short test with flexbox, but I'm not sure a flexbox would work well in the conditional div situation.
Is there something I'm missing that would give me the behaviour I'm looking for?

How to correctly draw borders in HTML? [duplicate]

This question already has answers here:
How to make an element width: 100% minus padding?
(15 answers)
Closed 3 years ago.
I am trying to draw some rich text in a border; here is an excerpt:
<!DOCTYPE html>
<html>
<body>
<div id="140280868923376" class="Container" data-parent-widget="140280868799320" style="margin:30px;padding:10px;border-width:2px;border-style:solid;border-color:blue;border-radius:20px;width:100%;height:100%;position:static;order:-1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
<div style="color:blue;font-size:30px">Ut ut blandit erat. Suspendisse laoreet mattis condimentum.</div><br>
Quisque ullamcorper diam a tortor tempus, in scelerisque mauris facilisis.<br>
<div style="color:red;font-weight:bolder">Aenean rhoncus mattis dolor non efficitur.</div>
</div>
</body>
</html>
This seems to draw outside right border:
... while I would like to get something like:
Note: second image has been rendered using width:90%; which, of course, is not correct because right margin/padding is dependent on window size, while it should be a fixed number of pixels from right.
What is the "Right Way" to get result I need?
Simply get completely rid of the width and height settings for your outer container <div>. This will make the border's size depending on the size of the content inside.
<div id="140280868923376" class="Container" data-parent-widget="140280868799320" style="margin:30px;padding:10px;border-width:2px;border-style:solid;border-color:blue;border-radius:20px;position:static;order:-1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>
<div style="color:blue;font-size:30px">Ut ut blandit erat. Suspendisse laoreet mattis condimentum.</div><br>
Quisque ullamcorper diam a tortor tempus, in scelerisque mauris facilisis.<br>
<div style="color:red;font-weight:bolder">Aenean rhoncus mattis dolor non efficitur.</div>
</div>

Why does the child element of a div change the margin between the body and the html?

Why does adding the 60px margin to the p tag inside the body, also change the placement of the div with the class* header. Shouldn't a fixed position element be unaffected by the other elements on the page?
.header {
position: fixed;
}
.left {
margin-top: 60px;
}
<body>
<div class="header">
Exercise 2.4
</div>
<p class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sed magna vitae lorem hendrerit posuere. Nullam ut ex ipsum. Cras volutpat augue in metus tempus ultricies sit amet nec lacus.
</p>
</body>
If I remove the class left from the p tag, the spacing between the body and the html goes down to 8 pixels as expected.
Collapsing margins!
If you have two nested elements with top margins, the margin gets shared between them. That is, both elements get the same value for the margin.
Normally, this will only affect the first child element in the parent, but in this case the browser will make an exception for you because the first element has position:fixed, so it will take the second element.
Solution: give .left a padding instead of a margin.
.header {
position: fixed;
}
.left {
padding-top: 60px;
}
<div class="header">
Exercise 2.4
</div>
<p class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sed magna vitae lorem hendrerit posuere. Nullam ut ex ipsum. Cras volutpat augue in metus tempus ultricies sit amet nec lacus.
</p>

Basic CSS styling issue

I'm making a new website and in my sidebar I'm trying to add this section below but I'm struggling to get the about text to be to the right of the image. I've tried floating the text left but it didn't really work. The only CSS I've got so far is that the sidebar is 300px wide.
<div id="sidebarabout">
<h3>About Elliott Davidson</h3>
<img src="http://placehold.it/100x100"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus luctus odio, sed sagittis dolor volutpat ut. Pellentesque efficitur orci at nunc fermentum, nec feugiat erat gravida. Continue reading</p>
</div>
Add this css and check out
img{float:left;padding:0 15px 0 0}
https://jsfiddle.net/vasanthanvas/s4pb17tr/
Try like this
<p><img src="http://placehold.it/100x100"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus luctus odio, sed sagittis dolor volutpat ut. Pellentesque efficitur orci at nunc fermentum, nec feugiat erat gravida. Continue reading</p>
img{float:left;margin:0 15px 0 0}
Padding will squeeze your image little.
You can use margin instead of padding.
You need to set the img and p to be either inline or inline-block on their CSS styles.
And also - depending how you want your text to "float" it may need a width:
https://jsfiddle.net/xoL510og/ << Example
<div id="sidebarabout">
<h3>About Elliott Davidson</h3>
<img style='display:inline-block;' src="http://placehold.it/100x100"><p style='display:inline-block; width:400px;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus luctus odio, sed sagittis dolor volutpat ut. Pellentesque efficitur orci at nunc fermentum, nec feugiat erat gravida. Continue reading</p>
</div>
use display: table;
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.item-inner{
display: table;
width: 100%;
padding: 20px;
}
.item{
display: table-cell;
vertical-align: top;
}
.item-text{
padding-left: 15px;
}
<div class="item-inner">
<div class="item">
<img src="http://placehold.it/100x100" />
</div>
<div class="item item-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam rhoncus luctus odio, sed sagittis dolor volutpat ut. Pellentesque efficitur orci at nunc fermentum, nec feugiat erat gravida. Continue reading</p>
</div>
When defining the img markup, make sure that it only affects the sidebarabout div. So define the div before img. Example:
#sidebarabout img{
float: left;
padding: 0 15px 0 0;
}
In case u declared a width in ur paragraph element, for example 200px, make sure to reduce this to 185px, since we're using a 15px padding. Otherwise it will mess up ur webpage because the div will become 315px width.
I noticed someone suggested using a margin. Don't use a margin, this will only push the image 15px to the left out of the div.
Also i'm missing a width, height and alt. Make sure to define ur img element the right way, otherwise it will not pass the W3C validator. Use the following:
<img src="http://placehold.it/100x100" width="100" height="100" alt="Description">

Is there a way to make a 2 column layout stretch in both directions?

I have the following scenario:
a two column layout made up of divs A and B (in that order) wrapped with a wrapper div centered at the page. I want B to stretch horizontally to 100% - length_of_A (length of A changes depending on its content), and also for both divs to stretch vertically to fill the height. If A is longer than B then B will stretch, otherwise- A will stretch.
I tried experimenting with width and height and position and overflow values, but couldn't make it work. How do I achieve something like this?
Unfortunally there is no cross-browser solution I know to do that using divs, but you could do that using tables like follows:
<table style="width: 100%; border-collapse: collapse;"><tr>
<td id="A"> <h1 style="white-space: nowrap;">...content...</h1> </td>
<td id="B"> ...content... </td>
</tr></table>
You should apply the "white-space: nowrap;" to all those elements that should rule the A column width.
This should do the trick in all common browsers.
Working demo (uses JavaScript): http://vidasp.net/tinydemos/layout-demo-2.html
However, you cannot set padding to the DIVs that represent the columns.
Also, for some reason setting exact widths doesn't work in IE - that's why I had to leave out 1px on the right.
I had same problem with my page but with 3 divs. My solutions was to use javascript code to get width and height of the page offsetHeight and offsetWidth.
For example use code bellow to get half of some element's width.
var midpoint = document.getElementById("MyElementId").offsetWidth/2; .
I think this is the simplest solution, only the left column may have a bug in IE6 if the content of the right column is longer. And also when the content of the left column is longer than the right column, the text wont fit. But you can fix this with a background image so you wont see that the text doesn't fit the div.
<style type="text/css">
* {
margin:0;
padding:0
}
#page {
background:red;
}
#left {
width:320px;
float:left
}
#right {
background:blue;
position:relative;
overflow:hidden
}
</style>
<div id="page">
<div id="left">
<ul><li>Lorem ipsum</li><li>Dolor sit amet</li><li>Consectetur adipiscing elit</li><li>Lorem ipsum</li><li>Dolor sit amet</li><li>Consectetur adipiscing elit</li><li>Lorem ipsum</li><li>Dolor sit amet</li><li>Consectetur adipiscing elit</li></ul>
</div>
<div id="right">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam laoreet, turpis nec mattis rhoncus, diam arcu dignissim turpis, vel interdum libero mi vitae lorem. Mauris placerat cursus odio at imperdiet. Integer pulvinar ante quis justo mattis mattis. Maecenas interdum mollis lacinia. Cras odio erat, pellentesque eu condimentum ut, ultricies vel neque. Morbi tristique diam elit, eget sagittis est. Nullam vestibulum elit sit amet odio dictum sodales. Duis elementum mollis elementum. Nulla purus elit, suscipit auctor sagittis eget, pretium vitae est. Suspendisse potenti. Integer sit amet ipsum sem. Vestibulum quis auctor leo. Suspendisse at elementum diam.</p>
</div>
</div>
(Tested in Safari 5, IE6, IE7 and IE8.)