A basic sounding question I can't find an answer for.
Making an element stretch to use the remaining width of a page is nothing new. Same with changing side by side elements to be stacked on small screens. These are both situations that allow you to pick the element order/composition (E.g. float: direction; and DOM element order for top/bottom) but how do you set the order when doing both? I guess you could say I want to control my element stack overflow. wink wink nudge nudge
The "block formatting context" trick has gotten me so close to what I want.
html:
<div class="blue">Some navigation list items.</div>
<div class="red">Search box expanding to cover empty space.</div>
css:
.red {
width:auto;
height:150px;
background:red;
min-width:200px;
overflow:hidden;
}
.blue {
height:150px;
width:300px;
background:blue;
float:left;
}
http://jsfiddle.net/A8zLY/5503/
In my case, how do I get "red" (the dynamicly sized box) to be on top when it meets its threshold (min-width)? I can't use a media query as navigation list items can change.
Well, here goes.
Although I am not sure what you are trying to accomplish and this solution might not fit your layout needs, here is a solution to the problem - switch the position of the two elements and add this css:
html, body {
padding:0;
margin:0;
}
.red {
position:relative;
margin-left:300px;
height:150px;
background:red;
}
.blue {
position:absolute;
left:0;
top:0;
height: 150px;
width: 300px;
background: blue;
}
#media (max-width:300px) {
.blue {
position:static;
width:100%;
}
.red {
margin-left:0;
}
}
http://jsfiddle.net/A8zLY/5506/
I used a media query breakpoint to wrap the two elements.
The only way for elements to be placed on top of others when they are wrapping is to be placed first in the HTML markup.
Related
I'm trying to understand how to change a small thing in a website, but I can't figure out how to do it.
I have a grid of articles organized in two columns, and I would like the various blocks to be separated avoiding the blank space as in figure http://i.stack.imgur.com/tNCFd.png
But I don't know which kind of properties I should set.
EDIT - Clarified answer (to clarified question in comments)
There's a rule in the parent theme:
#content .post { margin-bottom: 12px; }
You need to override this rule in your child theme and set
#content > div.articolo .post { margin-bottom:0; }
ORIGINAL ANSWER
First off, I strongly suggest that you don't just throw a heavy jQuery library (i.e. masonry) at a project that can be fixed with simple CSS.
Secondly, from the code in your comments - which is this:
#content div.articolo { display:inline-block; clear:none; min-height: 10px; }
#content > div.articolo:nth-child(even) { width:48%; float:left; clear:both; }
#content > div.articolo:nth-child(odd) { width:48%; float:right; }
#content > div.articolo:first-child { width:100%; float:none; clear:both; }
You should change it to this:
#content div.articolo { display:block; clear:none; min-height: 10px; }
#content > div.articolo:nth-child(even) { width:50%; float:left; clear:both; }
#content > div.articolo:nth-child(odd) { width:50%; float:right; }
#content > div.articolo:first-child { width:100%; float:none; clear:both; }
Note the only things that I changed were the width (changed to 50%) and I changed display: inline-block to display: block
display: inline-block preserves whitespace (converts many to one) in the markup, so if you have a space in your markup after a closing div that is display: inline-block, you'll see a space in your browser. Chances are, that is why the developer set the widths to 48%, to (poorly) account for the fact that there was a space appearing after each article block (because it was display: inline-block) meaning that each block couldn't be set to 50% width, because then they wouldn't appear next to each other (because 50% + 50% + a space > 100%)
Try setting the height of each article to 'auto' with suitable margin-bottom. You'll still get some space below where two articles height are less than the corresponding articles in the other column.
Look at the item columns on http://www.ebuyer.com/ - this illustrates the effect.
Pretty difficult to say from just an image. If the margin is in the html elements, you can try to set margin and padding to 0px; if the whitespace is in the bitmaps, crop them.
This may not be possible without Flexbox, but is worth a shout.
I would like to have elements inside a container to be elastic and take all the lateral space available but when the window resizes and they reach a min-width, they wrap into a second line.
this fiddle has two lines of investigation: inline-blocks and tables.
http://jsfiddle.net/48HMj/
relevant code here:
.container{
width:100%;
background-color: yellow;
}
.container2{
width:100%;
background-color: lightblue;
display:table;
}
.block {
border:1px solid;
display:inline-block;
min-width:100px;
width:auto;
height:50px;
}
.cell {
border:1px solid;
display:table-cell;
min-width:100px;
width:auto;
height:50px;
}
Table-cells behave quite in that manner, but as table cells, they are not supposed to wrap...
Thanks
I'm not sure if I'm understanding your question right but I made a FIDDLE for you to examine.
Essentially I forked the "Live Demo" fiddle from User3660695 added the .flexible class to all the divs and added a media query rule to the container:
#media screen and (max-width:480px) {
.container { display: block }
}
Hopefully that is the behavior you were looking for. Cheers!
I want to align several div's into one line and also center the content vertically and horizontally.
The text to align vertically could be a single line, or a <p> paragraph.
To show n-number of divs in one line, there are 3 approaches
use display:table;
This method is supported IE8 and above and comes in pretty handy if you have large amount of css and text and divs to align
use float:left;
All time favorite, the old school approach, this method is most recommended when old browser support has to be considered, requires clearing of the float at the end
use display:inline-block;
never used this method personally float method was considered instead of using this by me
Base CSS
/************Supported by IE8 and above *******************/
div.table {
width:100%; /* important */
display:table;
text-align:center;
}
.table-cell {
display:table-cell;
vertical-align:middle;
}
/************ Method 2 *******************/
div.inline {
width:100%;
display:inline-block;
text-align:center;
}
div.inline-div {
width:32%;
display:inline-block;
}
/************ Method 3 *******************/
.float-class {
width:100%;
text-align:center;
}
div.floatdiv {
float:left;
width:32%;
border:1px solid black;
}
.clearfloat {
clear:both;
}
fiddle showing all three methods in 1 place
To vertically center one line in a div
again 3 approaches :
keep in mind, solution has to be responive, so margin-top:25% or 50% is not gonna work!!!
line-height
this approach is usefull when the dimesnion of the parent div is known, then you can simply use the trick line-height:equal to height of parent div
position
idea is to make the parent positioned relative and the text span class an absolute, then center the absolute text using positioning like top/bottom
display:table-cell
highly recommended if IE7 and older support is not required, simply use vertical-align:middle;
Base css
div.fixed-div-height {
height:200px;
width:200px;
text-align:center;
}
div.fixed-div-height span {
line-height:200px; /* equal to height of the fixed div*/
}
div.unknown-div-height {
height:100%;
text-align:center;
position: relative;
}
div.unknown-div-height > span.unknown-div-margin {
display:inline-block;
height:20px;
position: absolute;
top: 50%;
left:0;
right:0;
}
div.for-ie8-and-above{
width:100%;
display:table;
height:400px;
text-align:center;
}
div.for-ie8-and-above > div{
height:400px;
width:100%;
display:table-cell;
vertical-align:middle; /* key here */
}
fiddle showing all three methods
To center a paragraph vertically in center
this is the tricky part
Practically there is no possible way to center a parapgraph whose height and the containers height is unknown unless you gor for some hacks....one such hack has been quoted at the end of this answer from css tricks!!
Simplest, use :
div.table-cell {
height:400px; /* can be anything, even in percentage*/
width:100%;
display:table-cell;
vertical-align:middle; /* key here */
}
fiddle showing remaining 2 possible cases
Another solution posted here :
How do I vertically center text with CSS?
IE hack for display:tables : CSS Tricks
I aligned multiple divs within a table cell (td) by creating a container DIV, as follows:
<td>
<div class="containingDIV"> // container DIV with CSS as below
<div></div>
<div></div>
<div></div>
</div>
</td>
where css for containingDIV is:
.containingDIV {
display: flex;
}
So I have divs that I have within my webpage .. like header , or div boxes .. they adjust fine on bigger screen sizes so that they dont look too tiny on a big monitor , but the issue is that when I resize the window or browser to make it small , all the elements move along till they reach a point where they all meet and it gets ugly .. How can I make it so the divs I have adjust to bigger screen sizes becoming bigger as well , but then stop them from moving along with the window when resizing the window making it smaller ??? I used percentages from all the elements I want to readjust and make bigger on bigger /wider screens
Below is an example of my code .. my header and other elements with these classes move to the point where they overlap when resizing the window
.header{
position:absolute;
top:0px;
width:100%;
height:100px;
left:0;
background:#EB6A4A;
}
.slogan{
position:absolute;
top:60%;
left:40.5%;
}
.login{
position:absolute;
top:15%;
left:90%;
}
.whitebackground{
background:#FFFFFF;
}
I'm not sure about your question because you didn't post any code but i think that your solution can be using css style:
max-width:50%;
min-width:800px;
max-height:500px;
min-height:21%;
properties in pecentage or pixel as you prefer, so you can tell divs how much expand and how much get smaller.
Hope it helps, if you post your code maybe i can be more useful.
Regards
EDIT 1:
This should resolve your problem:
*{
margin: 0;
padding: 0;
text-decoration: none;
color: inherit;
}
.header{
position:relative;
float:left;
top:0px;
width:100%;
height:100px;
left:0;
background:#EB6A4A;
}
.slogan{
position:relative;
float:left;
top:60%;
left:40.5%;
}
.login{
position:relative;
float:left;
top:15%;
left:90%;
}
.whitebackground{
background:#FFFFFF;
}
Just do the same with the class you didn't poste in css. The idea is having all items with position relative and floated on the left so they don't move. Should work!
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Make Div on right side fill out all available space
I'm designing a theme for a blog and I'm having some trouble trying to get a layout working. Here's an image of what I want.
This diagram represents the individual posts and not the website itself, so it will be contained in a box of it's own, lets call it .container. Also the purple and green are in another box, let's call it .content. The other elements will be called by their color for now.
so here's more or less what the CSS looks like:
.container {
display:block;
margin:0 25px;
}
.gray, .blue, .content {
display:block;
width:100%;
}
.purple {
display:inline-block;
width:125px;
height:100%;
text-align:center;
}
.green {
display:inline-block;
}
That's all there is at the moment. I tried float but that made no effect. What's happening is something like this.
Here's a few more things you should know:
.container's width is NOT set it is auto
.purple and .green don't necessarily need to be the same size as long as .green doesn't go to that side.
.purple CAN have a set height
.green is where the meat is, that's where the actual post goes, keep that in mind.
I don't think tables will help, the problem is inside .content.
Use answers in this post to get a solution:
Make Div on right side fill out all available space
I am recommending tables-directed one because it is most valid/working approach on almost every browser.
I assume that all of your sections are <div> elements. Use:
.container {
display:block;
margin:0 25px;
}
.gray, .blue, .content {
display:block;
clear:both;
width:100%;
}
.purple {
float:left;
width:125px;
height:100%;
text-align:center;
}
.green {
float:left;
}
You may also need to add <br clear="all" /> immediately after the green div and before the closing of the content div, and another one right after your content div.
Assuming all is set in div you need to write like this:
.container {
display:block;
margin:0 25px;
}
.gray, .blue, .content {
display:block;
clear:both;
width:100%;
}
.purple {
float:left;
width:125px;
height:100%;
text-align:center;
}
.green {
float:left;
min-width: 125px;
}