CSS match height of other elements in row - html

I'm using Bootstrap, and I'm trying to make a row of boxes be the same height.
Here is a dumbed-down example:
CSS:
.col-md-4 {
border:1px solid black;
height:100%;
}
Html:
<div class="row">
<div class="col-md-4">Less text</div>
<div class="col-md-4">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a fringilla magna, nec vestibulum felis. Donec sollicitudin porta sem eu dignissim. Vivamus pellentesque leo vel pellentesque blandit</div>
<div class="col-md-4">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a fringilla magna, nec vestibulum felis. Donec sollicitudin porta sem eu dignissim. Vivamus pellentesque leo vel pellentesque blandit
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a fringilla magna, nec vestibulum felis. Donec sollicitudin porta sem eu dignissim. Vivamus pellentesque leo vel pellentesque blandit
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a fringilla magna, nec vestibulum felis. Donec sollicitudin porta sem eu dignissim. Vivamus pellentesque leo vel pellentesque blandit
</div>
</div>
This results in the first box in the row being small, and the third box being very large. I want them all to have the same height.
How do I make the height of all the boxes in the row match the tallest box without setting a static height? I don't know how big the largets box will be. I know I could do this with a table, but that would not be optimal. Is there a way to do this with CSS?
Here is a bootply example. I did some googling but couldn't find what I was looking for.

CSS Only solution
Note: Use carefully and target the styles to your specific .col-md-4 elements. But for your code sample:
.col-md-4 {
display: table-cell;
float: none;
border:1px solid black;
height:100%;
}
Demo http://www.bootply.com/JXL6MYXiWO

$(document).ready(function(){
var highestCol = Math.max($('.div01').outerHeight(),
$('.div02').outerHeight(),
$('.div03').outerHeight());
$('.col-md-4').outerHeight(highestCol);
})
jQuery example, quite fast and effective.
Just give those divs additional unique classes, e.g. div01, div02, div03.
Check out http://jsfiddle.net/a7jow8c3/

Flexbox is probably your best option at this point in time. See this article: http://css-tricks.com/snippets/css/a-guide-to-flexbox/
And current browser support: http://caniuse.com/#feat=flexbox

Related

How to change the vertical scrollbar position but keep the horizontal scrollbar scrollpostion (css only)

Firstly the definitions:
Scroll position is the current position of the scroll-handle on the scrollbar.
Position of the scrollbar is the side of the element(div) the scrollbar is positioned on (default for ltr is left)
I want to have the vertical scrollbar positioned on the right side of a div (representation of a tree), while still having the content ltr. I quickly found at least two ways to do it.
Now I have still a problem when applying any of the solution that the horizontal scrollbar position is initially set to the right. As my content is still ltr the scroll-position is at the end of the content, which is not at all what I wanted to achieve. Furthermore Users would have to "scroll back" to the all of the content, which is rather bad UX).
There is the possibility to set the scroll position with Javascript but sadly I can not use Javascript in this case.
.main {
width:150px;
height:150px;
direction: rtl;
overflow:scroll;
}
.inside {
direction: ltr;
width:300px;
}
<div class="main"><div class="inside">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed aliquam lectus vel erat feugiat, id maximus quam iaculis. Etiam vitae eleifend nisi. Phasellus pellentesque dui ex. Proin sit amet metus quis quam sagittis pretium at ac velit. Mauris ultricies metus nec tortor dignissim, in pellentesque libero consectetur. Nullam nec enim sit amet leo congue finibus. Curabitur ligula dolor, aliquet eget erat et, laoreet vehicula nibh. Suspendisse eu lacus sapien. Nulla facilisi. Nulla placerat mauris sit amet ultrices sollicitudin. Quisque sed bibendum ante. Integer id magna sollicitudin, scelerisque neque vitae, tincidunt quam. Integer et aliquam sem, at tempus dui. Etiam sit amet ornare lacus, at placerat leo. Donec pharetra diam sit amet nisl dapibus suscipit.Lorem ipsum dolor sit amet, consectetur adipiscing elit. SedNulla placerat mauris sit amet ultrices sollicitudin. Quisque sed bibendum ante. Integer id magna sollicitudin, scelerisque neque vitae, tincidunt quam. Integer et aliquam sem, at tempus dui. Etiam sit amet ornare lacus, at placerat leo. Donec pharetra diam sit amet nisl dapibus suscipit.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed</div></div>
Here is an Example Fiddle
Tested on Firefox:
Update:
I did achieve the effect I wanted in a fiddle but it does only work with fixed pixel values, which is not an option.
I found the answer today.
It is to use flex-direction: row-reverse and min-width.
So now I can delete the JS workaround hack which did never worked fully.
.main {
display: flex;
flex-direction: row-reverse;
width: 150px;
height: 150px;
direction: rtl;
overflow: auto;
}
.inside {
direction: ltr;
display: block;
min-width: 300px;
}
See Fiddle

How to group HTML elements so they move together within a div with a "columns" styling?

I'm using a basic Jekyll site with Minima CSS. I want to use a post format with two columns of content:
<div style="columns: 2;">...</div>
Each content group consists of a link, an image tag, a title enclosed with p-tags, and a break.
I want the group to move together. Each link/image/title/break construct should remain in the same column.
I've tried surrounding each group with divs and with section tags - no luck.
Suggestions?
In order to prevent children of a parent that's using columns from breaking across columns, you can wrap them in a container that is display: inline-block.
The specific tag you use for this container is up to you. If you want to use a section, go for it.
Example:
ul {
column-count: 2;
list-style: none;
padding-left: 0;
margin: 0;
}
li {
display: inline-block;
border-bottom: 1px solid gray;
padding-bottom: 12px;
}
<ul>
<li>
<div>
<p>I won't break across columns!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur ultrices suscipit. Etiam fringilla porta tellus. Phasellus vitae semper dui. In non massa non sapien porttitor feugiat a ac velit.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur ultrices suscipit. Etiam fringilla porta tellus. Phasellus vitae semper dui. In non massa non sapien porttitor feugiat a ac velit.</p>
</div>
</li>
<li>
<div>
<p>I won't break across columns!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur ultrices suscipit. Etiam fringilla porta tellus. Phasellus vitae semper dui. In non massa non sapien porttitor feugiat a ac velit.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur ultrices suscipit. Etiam fringilla porta tellus. Phasellus vitae semper dui. In non massa non sapien porttitor feugiat a ac velit.</p>
</div>
</li>
<li>
<div>
<p>I won't break across columns!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur ultrices suscipit. Etiam fringilla porta tellus. Phasellus vitae semper dui. In non massa non sapien porttitor feugiat a ac velit.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin consectetur ultrices suscipit. Etiam fringilla porta tellus. Phasellus vitae semper dui. In non massa non sapien porttitor feugiat a ac velit.</p>
</div>
</li>
</ul>

Mispositioning in CSS

I'm quite new into HTML&CSS and I'm having troubles with the model box I think.
Here both elements below "Personal data" aren't at the same height and I can't find the reason. Can anyone help me?
jsfiddle.net/jbzgmqns/
PS: Don't worry about being ugly, everything included the borders are just placeholders.
this is happening because <P>...</p> itself is taking margin.
Set its margin value '0' i.e. margin:0; to keep it in same level of image.
And take <p> inside <div class="cuadro">...</div> as shown below
<div class="cuadro">
<h1>Personal Data</h1>
<div class="imagen">
<img src="http://gobierno.morelos.gob.mx/sites/default/files/images/transparencia/placeholder-transparencia.jpg" />
</div>
<p style="margin: 0;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<br> Donec efficitur eros quis sapien congue, hendrerit rhoncus magna cursus.
<br> Nam a blandit diam. Curabitur auctor, ipsum eget mattis vulputate, elit ex egestas nunc, sit amet molestie
<br> ante felis porta ligula. Aenean elementum justo sed placerat finibus.</p>
</div></div>
It's because in your code you defined the block height, when you shouldn't:
.block {
height: 700px;
Just remove that and all will be fine.

CSS div is not floating next to image

I'm trying to make responsive design. When screen is small comments should be below "Slikica"(Cyan DIV). But when I'm on the desktop version I want comments (Gray divs) to be warped around image.
Cyan div has fixed width, and float left.
Gray divs has unknown length (max 200chars), and they should be right to Cyan div. They are also floated left.
If I set them width, 300px for example everything will work fine.
Look at image below, worth thousand of words.
<div id="content">
<div id="slikica">Slikica</div>
<div class="gray">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec elementum dui ut enim rutrum congue. Nulla ut odio vel metus pharetra aliquet. Proin nec erat non nisl semper sagittis. Pellentesque sed.</div>
<div class="gray">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris imperdiet interdum enim eget sollicitudin. Praesent eleifend interdum odio sit amet luctus. Nulla egestas eros vitae dui tincidunt amet.</div>
<div class="gray">Quisque non ligula id dolor tincidunt imperdiet at et libero. Cras eu sapien mi. Phasellus sollicitudin accumsan vehicula. In fermentum, sapien vitae ullamcorper porttitor, felis sem dapibus est amet.</div>
<div class="gray">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec elementum dui ut enim rutrum congue. Nulla ut odio vel metus pharetra aliquet. Proin nec erat non nisl semper sagittis. Pellentesque sed.</div>
<div class="gray">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris imperdiet interdum enim eget sollicitudin. Praesent eleifend interdum odio sit amet luctus. Nulla egestas eros vitae dui tincidunt amet.</div>
<div class="gray">Quisque non ligula id dolor tincidunt imperdiet at et libero. Cras eu sapien mi. Phasellus sollicitudin accumsan vehicula. In fermentum, sapien vitae ullamcorper porttitor, felis sem dapibus est amet.</div>
<br class="clrfix" />
</div>
jsFiddle link
Just remove the float: left; on the comment DIVs. When floating each comment left to previous one, they won't fit into the viewport.
http://jsfiddle.net/feeela/Xtuc9/1/
Try adding the following CSS to the comments' div element:
display:inline;
If you remove float: left; from your gray divs and add a left margin equal to (or larger) than the cyan div width they will occupy the space to the right. If there are more gray divs they will however not wrap around the cyan div because of the margin. I don't know if this behavior is wanted. Otherwise you could just skip both the margin and the floating and have them wrap around the cyan div.
The problem is that your divs will expand to reach at maximum the width of their container (in that case, the <div id="content">). When they reach a width too big to fit aside the blue, they get clip down. What you need is to put something that prevent them from reaching that width.
You have two option to do this.
Put a div with a width: 600px (or whatever fit in that space) and put every gray div in it. JSFiddle (You'll need to expand the result window to see that it work)
Put a max-width on every div (example: max-width: 600px)

CSS: Floated element after the content in code

I need to have a floated element after the content/text that's supposed to flow around it in my code for SEO reasons. Usually floats are done like so:
CSS:
#menu {
float: right;
width: 180px;
padding: 10px;
background: #fcc;
margin: 0 0 15px 15px;
}
HTML:
<div id="menu">This is a right float. The long text flows around it.</div>
<div id="content"><p>This is a long text. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Praesent nec risus.
Praesent adipiscing aliquet magna. Proin bibendum velit
vitae tortor. Vestibulum a dui quis urna feugiat viverra.
Vestinbulum diam dui, ullamcorper in, rhoncus at, facilisis at,
lorem. Phasellus turpis metus, sodales sit amet, laoreet nec,
aliquet sit amet, tortor. Vivamus massa orci, gravida sit amet,
dictum quis, euismod a, est. Aenean pretium facilisis nunc.</p>
<p>Nulla eros mauris, egestas eget, ullamcorper sed, aliquam ut,
nulla. Phasellus facilisis eros vel quam. Etiam rutrum turpis
a nibh. Integer ipsum. Vestibulum lacus diam, varius in,
blandit non, viverra sit amet, sapien. Sed porta sollicitudin
nibh. Nam eget metus nec arcu ultricies dapibus.</p></div>
But I need to have the HTML like this:
<div id="content"><p>This is a long text. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Praesent nec risus.
Praesent adipiscing aliquet magna. Proin bibendum velit
vitae tortor. Vestibulum a dui quis urna feugiat viverra.
Vestinbulum diam dui, ullamcorper in, rhoncus at, facilisis at,
lorem. Phasellus turpis metus, sodales sit amet, laoreet nec,
aliquet sit amet, tortor. Vivamus massa orci, gravida sit amet,
dictum quis, euismod a, est. Aenean pretium facilisis nunc.</p>
<p>Nulla eros mauris, egestas eget, ullamcorper sed, aliquam ut,
nulla. Phasellus facilisis eros vel quam. Etiam rutrum turpis
a nibh. Integer ipsum. Vestibulum lacus diam, varius in,
blandit non, viverra sit amet, sapien. Sed porta sollicitudin
nibh. Nam eget metus nec arcu ultricies dapibus.</p></div>
<p id="menu">This is a right float. Because it's placed below the text in code,
it also appears that way.</p>
Basically, I need this HTML to look like the previous example (HTML and CSS). How can I do this?
The width of the floated element is constant, but the height can change. The content has to flow around it. The reason I need to have it this way is because the floated element is the menu, which doesn't contain any important text and is usually the same for many pages, so the content should be topmost in the code.
This recent question may be the same
Wrap text around right floated column where left column appears first in html
the solution involves floating a empty "spacer" div right , this spacer is first in source, it should have the width and height of the content to be in the right side - in the link a solution including a bit of jQuery to get the height - the position the actual menu over the top of the floated spacer
a JS fiddle example produced from that link : HERE
Simple you have add the following css
#content {
float: left;
width: 300px; /* put here the width you want */
}
demo: http://jsfiddle.net/qTDLr/1/
Edit: make sure that the sum of #content and #menu width is less than the container width.
You could just use a table. This 'sidebar before content' problem of CSS has been a huge step backwards in terms of accessibility.