I want to put two <div>
s next to each other. The right <div>
is about 200px; and the left <div>
must fill up the rest of the screen width? How can I do this?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
- Adding a timeout to a render function in ReactJS
I ran into this problem today. Based on the solutions above, this worked for me:
Simply make the parent div span the full width and float the divs contained within.
This will work OK as long as you set
clear: both
for the element that separates this two column block.To paraphrase one of my websites that does something similar:
Unfortunately, this is not a trivial thing to solve for the general case. The easiest thing would be to add a css-style property "float: right;" to your 200px div, however, this would also cause your "main"-div to actually be full width and any text in there would float around the edge of the 200px-div, which often looks weird, depending on the content (pretty much in all cases except if it's a floating image).
EDIT: As suggested by Dom, the wrapping problem could of course be solved with a margin. Silly me.
The method suggested by @roe and @MohitNanda work, but if the right div is set as
float:right;
, then it must come first in the HTML source. This breaks the left-to-right read order, which could be confusing if the page is displayed with styles turned off. If that's the case, it might be better to use a wrapper div and absolute positioning:Demonstrated:
left rightEdit: Hmm, interesting. The preview window shows the correctly formatted divs, but the rendered post item does not. Sorry then, you'll have to try it for yourself.
You can use flexbox to lay out your items:
This is basically just scraping the surface of flexbox. Flexbox can do pretty amazing things.
For older browser support, you can use CSS float and a width properties to solve it.