Makes columns same height with one column having nested boxes - html

I'm trying to create 2 columns, one simply filled with text while the other contains three coloured boxes of equal height (33.33%) which then add up to the same height as the text. The overall size of the container can't be a fixed height unfortunately as the site is responsive and the amount of text may change so I need the height of the two columns to be flexible.
Now I've used display: table; and display: table-cell; elsewhere in the site to achieve equal height between just two columns but am struggling to make this one work with the three equally sized boxes within one of the columns.
I've made a JSFiddle to show you what I've got:
http://jsfiddle.net/56yFp/
And here's the html:
<div class="column-row">
<div class="column column-cell column-text">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="column column-cell column-boxes">
<div class="box green-box">Box 1</div>
<div class="box red-box">Box 2</div>
<div class="box blue-box">Box 3</div>
</div>
</div>
css:
.page-wrapper {
background-color: #FFFFFF;
}
/* Table */
.column-table {
display: table;
}
.column-row {
display: table-row;
}
.column-cell {
display: table-cell;
}
.column {
vertical-align: middle;
height: 100%;
}
.column-text {
width: 62.5%;
background-color: #e2e2e2;
}
.column-boxes {
width: 37.5%;
}
.box {
min-height: 33.33%;
width: 100%;
}
/* Colors */
.green-box {
background-color: #016354;
}
.red-box {
background-color: #eb5640;
}
.blue-box {
background-color: #93ceee;
}
Any thoughts SO community? Thanks

DEMO
.column {
display:inline-block
}

Related

How do I wrap row items using CSS Flexbox?

I'm fairly new to CSS Flexbox but I'm trying to create a horizontal card, where an image is on the left, and text/buttons are on the right. When the site is scaled down (for mobile use), the row items should wrap and the image should sit on top of the text. I've tried setting the wrap property to wrap but it wraps for large screens when it should only wrap for smaller screens. See code below:
* {
margin: 0;
padding: 0;
}
#box {
padding: 20px;
}
img {
width: 200px;
}
#outer-container {
display: flex;
flex-wrap: wrap;
border: solid 1px;
width: 70%;
margin: auto;
}
#inner-container {
border: solid 1px;
display: flex;
justify-content: space-between;
flex-direction: column;
}
<div id="outer-container">
<img src="https://icatcare.org/app/uploads/2018/07/Thinking-of-getting-a-cat.png" alt="cat">
<div id="inner-container">
<div>
<h3>Heading</h3>
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div>
Other stuff
</div>
</div>
</div>
Should I attempt to use another approach (like Bootstrap's card layouts) or is there something obvious I'm missing?
Set a flex-basis to the text container to control when the wrap should happen.
Open the below on full screen and resize to see:
* {
margin: 0;
padding: 0;
}
#box {
padding: 20px;
}
img {
width: 200px;
}
#outer-container {
display: flex;
flex-wrap: wrap;
border: solid 1px;
width: 70%;
margin: auto;
}
#inner-container {
border: solid 1px;
display: flex;
justify-content: space-between;
flex-direction: column;
flex-basis:500px;
flex-grow:1;
}
<div id="outer-container">
<img src="https://icatcare.org/app/uploads/2018/07/Thinking-of-getting-a-cat.png" alt="cat">
<div id="inner-container">
<div>
<h3>Heading</h3>
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div>
Other stuff
</div>
</div>
</div>
The image is on the left.
The text is on the right.
As soon as the first line of text reaches the right side of the container, the entire item will wrap.
It's tempting to think that once the first line reaches the right-side limit, just the text will wrap.
That's not how it works.
That touch will trigger the entire item to wrap.
Try it out: jsFiddle demo
#outer-container {
display: flex;
flex-wrap: wrap;
border: solid 1px;
}
#inner-container {
border: solid 1px;
display: flex;
min-width: 0;
}
<div id="outer-container">
<img src="https://icatcare.org/app/uploads/2018/07/Thinking-of-getting-a-cat.png" width=50 height=50 alt="cat">
<div id="inner-container">
<p>Re-size the screen. Once this text touches the right side, the item will wrap.</p>
</div>
</div>
Use a media query to control the wrapping behavior.
Assuming I understood your question correctly, I believe I've come up with something that resembles a solution.
I altered your code ever so slighty, and worked with the flex-direction attritube. Basically what I've done is, when you're on desktop version, your card used the attribute flex-direction: row to have your items inside of your div be aligned like you described.
When you swicth to mobile version, the only thing I've done is add a media query that tells the div to use the flex-direction: column, in order to have the items inside you div be aligned like you described.
In this solution, you avoid switching to Bootstrap, by utilizing flexbox and the use of media queries like #DevLover mentioned.
* {
margin: 0;
padding: 0;
}
#box {
padding: 20px;
}
img {
width: 200px;
}
#outer-container {
display: flex;
border: solid 1px;
width: 70%;
flex-direction: row;
}
#inner-container {
border: solid 1px;
}
#media only screen and (max-width: 768px) {
#outer-container {
flex-direction: column;
}
}
<div id="outer-container">
<img src="https://icatcare.org/app/uploads/2018/07/Thinking-of-getting-a-cat.png" alt="cat">
<div id="inner-container">
<h3>Heading</h3>
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<div>
Other stuff
</div>
</div>
</div>
I hope this solves your issue!
HTML:
<div id="outer-container">
<div class="content-wrapper">
<img src="https://icatcare.org/app/uploads/2018/07/Thinking-of-getting-a-cat.png" alt="cat">
<div id="inner-container">
<div>
<h3>Heading</h3>
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div>
Other stuff
</div>
</div>
</div>
</div>
CSS:
* {
margin: 0;
padding: 0;
}
#box {
padding: 20px;
}
img {
width: 100%;
object-fit: cover;
}
#outer-container {
display: flex;
flex-wrap: wrap;
border: solid 1px;
width: 70%;
margin: auto;
}
#inner-container {
border: solid 1px;
display: flex;
justify-content: space-between;
flex-direction: column;
}
.content-wrapper {
display: flex;
flex-direction: column;
}
#media only screen and (min-width: 767px) {
.content-wrapper {
flex-direction: row;
}
img {
width: 200px;
}
}

Make image take up the full height of a div that changes size?

I will try to make this sound as easy as possible.
I am trying to place 2 div containers, side by side, and have them be the same height at all times.
The right div will be regular text. The amount of text in here will vary since I plan on using this for different pages.
The left div will be composed of 2 smaller containers - a title block, and an image block beneath it.
Here is a visual example of what I'm trying to achieve. The green box is supposed to be the full photo
Example Photo
I would like the photo in the image block of the left side to take up the full height/width of the box - (similar to background-position: cover that is used in CSS). I'd prefer to use a regular img tag instead of setting it as a div background.
The issue that I am having is that the image height on the left takes priority over the text box on the right hand side, and causes both containers to appear much longer than I want. I want the text block on the right to be prioritized, and the image block changes height based on that.
I've tried using object-fit: contain, but it isn't working, unfortunately. The closest I've gotten is to use width: 100%, but then it makes the height way too big.
Here's what I have so far:
.main {
display: flex;
}
.main .left {
width: 40%;
float: left;
}
.main .left .title {
background-color: black;
text-align: center;
display: block;
height: 90px;
padding: 50px;
color: white;
font-size: 40px;
}
.photo {
height: auto;
width: 100%;
}
.photo img {
width: 100%;
}
.main .right {
width: 60%;
float: right;
}
<div class="main">
<div class="left">
<div class="title">This is my Title</div>
<div class="photo"><img src="https://image.shutterstock.com/z/stock-photo-pastoral-green-field-with-long-shadows-in-tuscany-italy-275372477.jpg"></div>
</div>
<div class="right">
<p>text goes here lalalalalala</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
<style>
.main {
display: flex;
}
.main .left {
width: 40%;
display: flex;
flex-direction: column;
}
.main .left .title {
background-color: black;
text-align: center;
display: block;
height: 90px;
padding: 50px;
color: white;
font-size: 40px;
}
.photo {
width: 100%;
overflow: hidden;
position: relative;
flex-grow: 1;
}
.photo img {
width: 100%;
position: absolute;
}
.main .right {
width: 60%;
}
</style>
Notes:
I made the image absolutely positioned so its own height won't stretch our flex row.
The image is being cropped by height. If the title is taller than the text (or the same height), you won't see the image at all.
I made the left column also display flex and the photo box flex grow so that the title can stay the same height and the photo box will stretch the rest of the way to match the right column.
We don't need float left/right for flex items.

CSS : How to make two column right fluid left fluid depend on right

I already search and there is no exactly solution for me. I am trying to making Two Columns:
Left fluid + Right fluid.
Left column is contain input box with 100% width and the left column width is depend on right column width.
B is just a text div but I don't know a text's length. It is dynamic length.
A is just input box.
So if B is longer text, A should be shorter.
Please take look at the below image
Any suggestion?
You can use Flexbox and just set flex: 1 on input.
.el {
display: flex;
}
input {
flex: 1;
background: #A3FF9A;
}
p {
background: #FF87DE;
margin: 0;
}
<div class="el">
<input type="text">
<p>Lorem ipsum dolor.</p>
</div>
Try this
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Site name</title>
</head>
<style>
#container{
width: 900px;
}
#container:after{clear: both; display: table; content: "";}
#container:before{ display: table; content: "";}
.left-column{
width: 400px;
float: left;
padding: 5px;
background: green;
box-sizing: border-box;
}
.left-column input{width: 100%;}
.right-column{
float: right;
padding: 5px;
width: 500px;
background: violet;
box-sizing: border-box;
}
</style>
<body>
<div id="container">
<div class="left-column">
<input name="f-name" type="text"></input>
</div>
<div class="right-column">
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit
anim id est laborum.
</div>
</div>
</body>
</html>

How to wrap text around image in HTML/CSS like MS Word does it when choosing "Top and Bottom"

I'm trying to implement the following text wrapping in HTML. I want the image to always appear below the first line of text, whatever the width of the page is.
Illustration:
And when the page is resized to be a bit narrower, it should look like this:
Basically the same way Word does it when you choose "Top and Bottom" in the image text wrapping options.
I'm pretty sure there's no built-in CSS feature for this layout. I think it could be implemented with text-measurements in JS - but it doesn't seem like a very elegant solution.
Any ideas?
Edit
The solution should also work for placing the at the n-th line, not just the first line.
This seems to work - FIDDLE.
CSS
.bigdiv {
border: 1px solid black;
width: 80%;
}
.picturediv {
width: 100%;
float: right;
}
.picturediv img {
width: 100%;
}
I've adapted TimSPQR's answer to allow placing the image on any line.
This is achieved by adding a narrow div that floats above the image, the line-height of which controls how many lines of text appear before the image.
HTML:
<div class='bigdiv'>
Lorem
<div class="clear">
</div>
<div class='picturediv'>
<img src='http://www.hdpaperwall.com/wp-content/uploads/2013/11/Mickey-Mouse-Wallpaper-disney-6628369-1024-768.jpg'/>
</div>
ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
CSS:
.bigdiv {
border: 1px solid black;
width: 80%;
line-height: 1em;
}
.picturediv {
width: 100%;
float: right;
}
.picturediv img {
width: 100%;
}
.clear
{
float: right;
line-height: 2em;
}
Fiddle

Applying wrapper class directly on elements instead of surrounding div?

First, this is my HTML
<div class="header">
<div class="wrapper">
<div class="navi">
Logo
<ul><!--
--><li>Link 1</li><!--
--><li>Link 2</li><!--
--></ul>
</div>
</div>
</div>
<div class="wrapper">
<div class="content">
<p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
</div>
and CSS
.wrapper {
width: 90%;
max-width: 50em;
margin: 0 auto;
}
.header,
.navi {
width: 100%;
}
.header {
background: grey;
}
.navi {
background: green;
display: table;
text-align: center;
}
.navi ul {
display: table-cell;
vertical-align: middle;
text-align: right;
}
.navi li {
background: orange;
display: inline;
margin-left: 10px;
}
.navilink {
display: inline-block;
width: auto;
}
.logo {
background: red;
float: left;
}
.content {
width: 100%;
background: fuchsia;
}
Fiddle
Fullscreen Fiddle
You see, the wrapper ensures that there is always some kind of gap between content and edge of the viewport and beyond a certain point (50 em), the .wrapper doesn't exceeds any further.
The code I posted here works, but I would like to know if there is any chance to get rid of <div class="wrapper"> achieving the same result. I already tried to apply the .wrapper class directly to the elements, but that isn't working - why?
To clarify: My aim is it to make the markup cleaner. That's why I am interested in a solution then ensures that the elements behave like in the example I posted, but without the use of <div class="wrapper">. The class .wrapper has to stay of course, it's just that div that strikes me. Thats why I tried to add .wrapper directly to the elements.
Remove the wrapper div, and add the two CSS properties to the content div..
.content {
margin: 0 auto;
max-width: 50em;
}