I am working on a project that has popup boxes for the user to interact with. I am trying to put 2 blocks of content next to each other in the popup box.
I've been looking around for answers, but none of the common solutions seem to be working here. I've tried float:left, display: inline-block, etc. The only thing that has worked is to set the exact width/heights and apply a margin to the second container, but I'd like to avoid this hack-y solution.
HTML:
<div id="equip-robot-modal" class="modal">
<div id="equip-robot-modal-content" class="modal-content">
<div id="equip-modal-content-inner" class="modal-content-inner">
<div id="robot-info-content">
<header id="equip-header">
<h2 id="equip-header-text">Robot Name Header</h2>
</header>
</div><!-- #robot-info-content -->
<div id="inventory-list-content">
<div id="inventory-list-container">
<p>
put more content here
</p>
</div><!-- #inventory-list-container -->
<div id="auto-match-container">
<button type="button" style="width: 50%; height: 50px; margin-top: 20px;" class="button">
<?php //echo langMatch(
//'PLAYER_SELECTOR_AUTO_MATCH'); ?>
Go to Store
</button>
</div><!-- #auto-match-container -->
</div><!-- #inventory-list-content -->
</div><!-- #equip-modal-content-inner -->
</div><!-- #equip-robot-modal-content -->
CSS:
#robot-info-content {
min-width: 500px;
padding: 10px;
position: relative;
float: left;
background-color: red;
}
#robot-image {
padding: 20px 0;
}
#modal-progress-bars {
min-height: 75%;
}
#inventory-list-content {
min-width: 400px;
padding: 10px;
display: inline-block;
float: left;
background-color: purple;
}
#inventory-list-container {
width: 100%;
height: 430px;
border: 1px solid black;
overflow-y: scroll;
}
.modal-content {
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
min-width: 350px;
height: auto;
transform: translate(-50%, -50%);
background-color: #f7f7f7;
color: black;
border: 2px solid black;
overflow: visible;
}
.modal-content-inner {
margin: 20px 50px;
text-align: center;
}
.modal-content-inner header {
background-color: white;
border: 1px solid black;
padding: 10px 50px;
margin: 0 auto;
}
See the fiddle: https://jsfiddle.net/kqa25wgv/
I'd like to float the 2 content divs within the modal-content inner div. Any suggestions?
Here are some values that worked for me. I stripped out all the superfluous ones:
.modal-content {
width: 800px;}
#robot-info-content {
width: 50%;
float: left;
background-color: red;
}
#inventory-list-content {
width: 50%;
float: left;
background-color: purple;
}
#inventory-list-container {
height: 430px;
border: 1px solid black;
}
.modal-content-inner {
margin: 20px 50px;
text-align: center;
}
.modal-content-inner header {
background-color: white;
border: 1px solid black;
}
You'll notice that I set the width of the .modal-content class to 800px. That's arbitrary and you can change it to what you want (or set it as a percentage of its containing div, if you have one). The important change is to replace your minimum-width settings with width settings, and set them to a percentage. The problem that you have is that your two inner divs are too wide for their container, so the second one wraps to the next line, so to speak.
Of course, if you use padding and/or margins on the inner content divs, you won't be able to set them at 50% without having the same problem.
The other thing that you'll want to experiment with is floating one content div to the left and the other to the right. If you float them both to the left, it won't make a difference so long as they take up the entire width of their container (and no more than the entire width). This can get tricky when you start using static values for your margins and padding, so you'll need to experiment. (You can also use percent values for margins and padding, which can be less tricky.)
Related
I have a set of divs that vary in size depending on an image inside it. Inside each div I would like two more divs, one is floated left and the other is floated right, like so:
I sort of accomplished it this way ... html:
<div class="image-wrap">
<img src="{{ img }}">
<div class="lookbook-title"><h5 >{{ title }}</h5></div>
<div class="item-buy">{{ theme:partial src="_buynow" }}</div>
</div>
and css:
div.image-wrap {
max-height: 1000px;
max-width: 100%;
border: 0;
display: inline-block;
height: auto;
box-sizing: border-box;
}
.lookbook-title {
position: relative;
top: -36px;
float: left;
padding-left: 10px;
padding-right: 10px;
color: #f7f7f7;
}
.item-buy {
position: relative;
top: -56px;
float: right;
padding-right: 20px;
pointer-events: none;
-webkit-font-smoothing: antialiased;
fill: #f7f7f7;
}
The reason I say "sort of" is because it initially was working just fine, but now the floated divs are appearing on above and outside their parent divs. What is interesting is that if I inspect the problem with dev tools and uncheck and recheck the "float" on either div both go back to where I want them to go...
You need to clear your floats.
Here is a interesting article that explains it in detail: http://css-tricks.com/snippets/css/clear-fix/
Hope this helps.
You should use position: absolute; for your 'floating' elements instead of float.
You'll need to add position: relative; to the parent wrap element - this will tell the children to respect the bounds of this element instead of floating somewhere outside of it. Then you can add position: absolute; to each of the children that you want to float and use top, bottom, left, right to control where the box is positioned. Experiment with different values to get the hang of it.
div.image-wrap {
height: 300px;
width: 400px;
position: relative;
border: 1px solid red;
}
.lookbook-title,
.item-buy {
background: white;
position: absolute;
bottom: 10px;
height: 100px;
width: 100px;
}
.lookbook-title {
border: 1px solid lime;
left: 10px;
}
.item-buy {
border: 1px solid blue;
right: 10px;
}
<div class="image-wrap">
<img src="http://www.placehold.it/400x300.jpg">
<div class="lookbook-title"><h5>Div 1</h5></div>
<div class="item-buy">Div 2</div>
</div>
I've got a div within a div, both are percentage based for the page but the nested div overlaps slightly to the right.
I'm actually trying to get the white box sit inside the first light blue div with a small margin on all sides so you can see a bit of the darker backround color, making it stand out more.
Editing to point out that the point of the position:fixed is to make the white box move as you scroll.
A solution was posted that involved chaning the position to relative, although this obviously stops the box from moving.
JSFiddle
div {
border-radius: 5px;
}
#header {
height: 50px;
background-color: #F38630;
margin-bottom: 10px;
}
.left {
height: 1300px;
width: 25%;
background-color: #A7DBD8;
float: left;
margin-bottom: 10px;
}
.right {
height: 1300px;
width: 75%;
background-color: #E0E4CC;
float: right;
margin-bottom: 10px;
}
#footer {
height: 50px;
background-color: #69D2E7;
clear: both;
}
#fixedleft {
height: 50px;
width: 25%;
background-color: #FFFFFF;
position: fixed;
margin: 1px 1px 1px 1px;
}
<html>
<head>
<title>Result</title>
</head>
<body>
<div id="header"></div>
<div class="left"><div id="fixedleft"></div></div>
<div class="right"></div>
<div id="footer"></div>
</body>
</html>
Your margin is increasing with the width.
Try:
#fixedleft {
height: 50px;
width: calc(25% - 2px);
background-color: #FFFFFF;
position: fixed;
margin: 1px;
}
I guess that this issue is due to default body margin as it doesn't affect the width of your fixed div(as you can see in the example, it's width is always the same, no matter what margin value you set, unlike it's container's width) :
body { margin:0; }
There is still a problem with the inner margin (1px) that pushes it out of the container, you can use calc for it, here is an example:
JSFiddle
#fixedleft {
background-color: #ffffff;
height: 50px;
margin: 2px;
position: relative;
width: 98%;
}
Please try this instear of
#fixedleft {
height: 50px;
width: 25%;
background-color: #FFFFFF;
position: fixed;
margin: 1px 1px 1px 1px;
}
if you load jQuery..
$(window).bind("resize", function(){
$("#fixedleft").width( parseInt($(".left").width()) -2)
})
$(function(){$(window).resize()})
This is for a standard centered responsive .content div with various breakpoints to set its width.
The design requirements is part of the right side of .content has a div with a colored background - black in this case - and that background color "bleeds" all the way to the right edge of the viewport. Likewise, it could be used on the left side also.
What I came up with involves tables, but I was wondering if there was a non-table version I wasn't able to figure out.
<div id="contain">
<div id="left"><!-- nothing can go here to spacing breaks --></div>
<div id="content">
<div id="rightfloat">status</div>
<div id="somecontent">content<br>blue borders for dev only</div>
</div>
<div id="right"><!-- nothing can go here to spacing breaks --></div>
</div>
#contain {
width: 100%;
padding: 0;
margin: 0;
display: table;
}
#left, #right {
text-decoration: none;
display: table-cell;
width: auto;
text-align: center;
padding: 0;
}
#left {
background: white;
}
#right {
background: black;
color: white;
}
#content {
display: table-cell;
width: 360px;
background: #F00;
height: 4em;
border-right: 1px solid blue;
border-left: 1px solid blue;
}
#rightfloat {
float: right;
width: 20%;
background: black;
color: white;
height: 100%;
}
I've created a js fiddle:
http://jsfiddle.net/toddzebert/5DWFh/
Thanks!
I want to create a two column layout with the right floated column containing a div that becomes scrollable once its content overflows the browser window height.
This is the html code that I am working on:
<div class=container>
<div class=column_A>A</div>
<div class=column_B>B
<div class=content>C<br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>C
</div>B
</div>
</div>
And this is the css code:
.column_A {
float: left;
border: black solid 2px;
height: 500px;
width: 65%;
background: red;
}
.column_B {
float: right;
border: black solid 2px;
width: 30%;
background: blue;
}
.content {
border: white solid 3px;
overflow: auto;
background: green;
}
The scroll is currently on the browser window, how do I transfer it to the content?
You use overflow: auto like this:
.column_B {
float: right;
border: black solid 2px;
width: 30%;
background: blue;
overflow: auto;
height: 600px; /* ? */
}
You need to specify the height for your right column, though.
EDIT: To answer your comment, the easy way to go about it is if you set your document body's height to 100%, like this:
body {
height: 100%;
}
Then use a custom percentage to set the column's height to your liking.
.column_B {
...
height: 99%; /* or whatever you need */
...
}
I'm trying to make liquid HTML layout with header (taking all available width and 130px height), 2 columns (1: 300px width all possible height, 2: all available width after column 2 took its 300px and 15-20px margin between them).
Atm I've got this:
HTML:
<div class="wrapper">
<div class="header">
<!-- .... -->
</div>
<div class="content">
<div class="left-column">
<!-- ... -->
</div>
<div class="right-column">
<!-- ... -->
</div>
</div>
</div>
CSS:
html, body {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
min-width: 1000px;
min-height: 500px;
}
body {
font: 12px sans-serif;
background-color: #fff;
color: #000;
}
.wrapper {
height: 100%;
width: 100%;
position: relative;
}
.header {
padding: 0 30px;
height: 100px;
left: 0px;
right: 0px;
position: absolute;
border: 1px solid black;
border-top: none;
}
.content {
position: absolute;
top: 120px;
left: 0;
right: 0;
bottom: 0px;
margin: 10px 20px;
border: 1px solid black;
}
.left-column {
float: left;
width: 300px;
border: 1px solid black;
}
.right-column {
margin-left: 315px;
border: 1px solid black;
}
The question is: are there any better solutions?
Thanks.
I took your HTML and created this fiddle for you: http://jsfiddle.net/RdQJY/1/. I didn't use any of your CSS though - I just don't like positioning used in the way you are using it, so decided to write it from scratch (sorry about that). The lorem ipsum text is just there as a placeholder - if you remove it, you'll see that the divs will occupy the whole window. Hope this helps!
P.S.: the only drawback to my method of having equal-height columns is that there is no easy way to apply a bottom border to them.