I am a CSS/HTML auto learner, apologies if my question is stupid.
I want a div which is 40% wide minimum with its content justified but when more items will be added in this div its width grows accordingly.
This is what I have so far:
.hcontainerbutton {
display: flex;
width: 40%;
background-color: blue;
align-items: center;
justify-content: space-around;
right: 30%;
left: 30%;
position: absolute;
bottom: 0!important;
}
both with width:40% or min-width:40% the div doesn't grow if I add more items into it
Wrap .hcontainerbutton in a container and apply flexbox and height properties to it. This can be used to position .hcontainerbutton instead of position: absolute.
Add min-width value to .hcontainerbutton
You can test this layout by adding and remove .content divs and viewing in full screen.
body {
margin: 0;
}
.container {
display: flex;
justify-content: center;
height: 100vh;
}
.hcontainerbutton {
min-width: 40%;
background-color: blue;
display: flex;
justify-content: space-around;
margin-top: auto;
}
.content {
background: pink;
width: 100px;
height: 100px;
}
<div class="container">
<div class="hcontainerbutton">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
</div>
Based on your requirements, this can be done with normal CSS itself, you need not go for flex, Here is an explanation on what is done.
First we set the width and height of html and body tag, then using margin:0px remove the margins set by the browser.
html,
body {
width: 100% height: auto;
margin: 0px;
}
Now the parent that will wrap the centered div will have to have the CSS property text-align:center, basically what this does is, it will center align elements with display property inline-block.
.parent {
text-align: center;
}
Then coming to the main div, which has the class hcontainerbutton, we can set the max-width(in the example I use 40%) and min-width(in the example I use 80%) to whatever is needed. The CSS property display:inline-block ensures it takes the width of the content alone. The CSS property word-wrap:break-word ensures the text is broken and maintains the widht of the div.
Below is a working snippet of the code.
html,
body {
width: 100% height: auto;
margin: 0px;
}
.parent {
text-align: center;
}
.hcontainerbutton {
word-wrap: break-word;
min-width: 40%;
max-width: 80%;
display: inline-block;
}
<div class="parent">
<div class="hcontainerbutton"> asdf
</div>
<div class="hcontainerbutton"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eleifend magna augue. Morbi sagittis eu urna et facilisis. Nam finibus erat justo, vel porta magna aliquam a. Pellentesque faucibus molestie libero vitae condimentum. Nunc condimentum tincidunt
nulla, id suscipit magna dignissim id. Nulla dapibus suscipit velit et viverra. Mauris non gravida justo. Sed efficitur eleifend elementum. Integer non mattis mi. Etiam vestibulum viverra erat, eget dapibus tellus iaculis ut. Mauris ullamcorper magna
sapien, ac gravida odio blandit varius. Fusce eu placerat enim. Etiam nec elementum dui. In fermentum massa sed augue interdum aliquam. Nunc lacinia blandit elit a iaculis.
</div>
</div>
Related
I have a situation in which I have a child div (.timeline) that needs to increase height as the parent divs (.tea-history) height increases. But when I tried using height:inherit; it did not work since the child div inherits height as auto from the parent div, when I tried doing it with height:100%; it would use the height of the entire page.
Anyone got an idea on how this could be fixed so the .timeline class will increase height when the parent div increases height.
.tea-history {
display: flex;
flex-direction: column;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
margin-bottom: 20px;
height: 800px; /*Currently i have set the height to 800 so the timeline is visible*/
width: 90%;
margin-top: 70px;
}
.tea-history .timeline {
position: absolute;
height: inherit;
width: 3px;
border-radius: 20px;
background-color: #7aaa62;
margin-top: 50px;
margin-left: 50px;
}
.tea-history .frame {
width: 80%;
display: grid;
grid-template-columns: 20px auto;
gap: 33px;
margin-top: 30px;
margin-left: 42px;
}
.tea-history .frame .timeline-dot {
display: flex;
align-items: center;
}
.tea-history .timeline-dot .outer-dot {
position: absolute;
height: 15px;
width: 15px;
border-radius: 50%;
border: #000 solid 3px;
}
.tea-history .timeline-dot .inner-dot {
position: absolute;
height: 10px;
width: 10px;
border-radius: 50%;
background-color: #000000;
margin-top: 2px;
margin-left: 2px;
}
<div class="tea-history">
<h3 class="heading">History</h3>
<div class="timeline"></div>
<div class="frame">
<div class="timeline-dot"><span class="outer-dot"><span class="inner-dot"></span></span>
</div>
<div class="content">
<h4>2035 - 2054</h4>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Metus aliquam eleifend mi in nulla posuere sollicitudin aliquam. Volutpat sed cras ornare arcu dui vivamus. Nec nam aliquam sem
et tortor consequat. Ac odio tempor orci dapibus ultrices in. Massa placerat duis ultricies lacus sed turpis tincidunt id. Egestas diam in arcu cursus euismod quis viverra nibh. Elit eget gravida cum sociis natoque. Nunc lobortis mattis aliquam
faucibus purus in. Turpis massa sed elementum tempus egestas. Sit amet nisl purus in mollis nunc sed id semper. Imperdiet nulla malesuada pellentesque elit.
</p>
</div>
</div>
</div>
Because absolute positioned elements are removed from the flow and ignored by other elements. So you can't set the parents height according to an absolutely positioned element that's why inherit didn't work.
You either have to use fixed heights or you need to involve JS.
And here is a tricky way to do it:
Duplicate the content of .tea-history and .timeline in relative divs with display:none value in parent div. So let's say .tea-history_duplicate and .timeline_duplicate. Put .timeline_duplicate on top and .tea-history_duplicate at the bottom.
When your jquery calls the absolute div, just set the according to relative div (.timeline_duplicate or .timeline_duplicate) with the property of display:block; and visibility:hidden;. The relative child will still be invisible but will make the parent's div higher.
What I am trying to do is have a fixed header, fixed footer with a section inbetween. The inbetween section would then get a scrollbar should the content not fit on screen. After much frustration I managed to get the main layout rendering correctly without using tables:
.main-container {
width: 50%;
height: 98vh;
flex-direction: column;
display: flex;
}
.main-container .main-view {
width: 100%;
overflow-y: scroll;
flex: 1 1 auto;
}
.main-container .top-bar {
width: 100%;
flex: 0 0 1em;
text-align: center;
}
.main-container .bottom-bar {
width: 100%;
flex: 0 0 1em;
}
.special {
display: inline;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<div class="main-container">
<div class="main-container top-bar">
SOMETHING FIXED HERE
</div>
<div class="main-container main-view">
<span class="special">Lorem</span><span class="special">ipsum</span> dolor sit amet, consectetur adipiscing elit. Pellentesque magna tellus, dictum et luctus ac, laoreet vel justo. Cras at pretium lectus. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Suspendisse potenti. Maecenas tincidunt efficitur neque, eu elementum purus tincidunt vel. Nunc id dolor bibendum, pharetra erat in, pretium lorem. Donec vitae nulla et lacus porta scelerisque. Praesent blandit, nibh nec vulputate
semper, arcu odio scelerisque velit, at rhoncus lacus dui luctus sapien. Donec venenatis erat libero, vitae lobortis velit finibus ut.
</div>
<div class="main-container bottom-bar" id="bottom-bar">
SOMETHING FIXED HERE
</div>
</div>
</body>
</html>
However elements in the middle area only render correctly if they are not wrapped in any kind of tag. As soon as I wrap them in a div or span, the browser (Chrome at least) insists on having each tag take up the entire line. They do not appear side-by-side as I might expect.
I have tried creating a 'special' class, as noted in the example above, which I have applied to both div and span. Both give the same result: 'Lorem' and 'ipsum' appear on their own lines instead of side-by-side. I tried various things from other stack overflow questions on somewhat related topics including "float: left" and additional nesting using "display: flex".
I simply want to apply some styling and perhaps make some items clickable. To do that they need to be wrapped in something like a div or span. Anyone know how I can get it to render them side-by-side instead of each tag on its own line?
Your particular issue is because your .main-container class has display: flex; on it and then you've added that class to the top, center and bottom divs, this flex property changes the way that child elements are positioned.
As it sounds like you dont want to mess with the positioning of children elements of the main (middle) div, you dont want to add the 'main-container' class to that div.
Actually, you can achieve what you want much more simply:
body {
display: flex;
flex-direction: column;
height: 100vh;
}
.main-view {
flex-grow: 1;
overflow: scroll;
}
Here we're making the body always 100vh (100% viewport height) and changing the display to flex, direction column. Setting these flex properties allows us to tell the main-view container to flex-grow which means fill the remaining space of the parent, this pushes the footer down to the bottom of the body element (which is set to 100vh).
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<style>
body {
display: flex;
flex-direction: column;
height: 100vh;
}
.main-view {
flex-grow: 1;
overflow: scroll;
}
</style>
</head>
<body>
<div class="top-bar">
SOMETHING FIXED HERE
</div>
<div class="main-view">
<span class="special">Lorem</span><span class="special">ipsum</span> dolor sit amet, consectetur adipiscing elit. Pellentesque magna tellus, dictum et luctus ac, laoreet vel justo. Cras at pretium lectus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse potenti. Maecenas tincidunt efficitur neque, eu elementum purus tincidunt vel. Nunc id dolor bibendum, pharetra erat in, pretium lorem. Donec vitae nulla et lacus porta scelerisque. Praesent blandit, nibh nec vulputate semper, arcu odio scelerisque velit, at rhoncus lacus dui luctus sapien. Donec venenatis erat libero, vitae lobortis velit finibus ut.
</div>
<div class="bottom-bar">
SOMETHING FIXED HERE
</div>
</div>
</body>
</html>
This is the nature of the flexbox. You gave the container the property of column for the flex-direction. The .special elements are being treated as flex items and getting arranged in a column. Simply wrap them all in a div so you have a single flex item so the inline display can kick in
.main-container {
width: 50%;
height: 98vh;
flex-direction: column;
display: flex;
}
.main-container .main-view {
width: 100%;
overflow-y: scroll;
flex: 1 1 auto;
}
.main-container .top-bar {
width: 100%;
flex: 0 0 1em;
text-align: center;
}
.main-container .bottom-bar {
width: 100%;
flex: 0 0 1em;
}
.special {
display: inline;
}
<div class="main-container">
<div class="main-container top-bar">
SOMETHING FIXED HERE
</div>
<div class="main-container main-view">
<div>
<span class="special">Lorem</span> <span class="special"> ipsum</span> dolor sit amet, consectetur adipiscing elit. Pellentesque magna tellus, dictum et luctus ac, laoreet vel justo. Cras at pretium lectus. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Suspendisse potenti. Maecenas tincidunt efficitur neque, eu elementum purus tincidunt vel. Nunc id dolor bibendum, pharetra erat in, pretium lorem. Donec vitae nulla et lacus porta scelerisque. Praesent blandit, nibh nec vulputate
semper, arcu odio scelerisque velit, at rhoncus lacus dui luctus sapien. Donec venenatis erat libero, vitae lobortis velit finibus ut.
</div>
</div>
<div class="main-container bottom-bar" id="bottom-bar">
SOMETHING FIXED HERE
</div>
</div>
Alternatively, you can utilize flex-direction: row on your flex container (in this case .main-view) so your flex items can display "side-by-side" instead of being stacked in a column. See sample below:
.main-container {
width: 50%;
height: 98vh;
flex-direction: column;
display: flex;
}
.main-container .main-view {
width: 100%;
overflow-y: scroll;
flex: 1 1 auto;
flex-direction: row;
}
.main-container .top-bar {
width: 100%;
flex: 0 0 1em;
text-align: center;
}
.main-container .bottom-bar {
width: 100%;
flex: 0 0 1em;
}
.special {
display: inline;
margin-right: 10px;
}
<div class="main-container">
<div class="main-container top-bar">
SOMETHING FIXED HERE
</div>
<div class="main-container main-view">
<span class="special">Lorem</span><span class="special">ipsum</span>Hello
</div>
<div class="main-container bottom-bar" id="bottom-bar">
SOMETHING FIXED HERE
</div>
</div>
I have been trying to write CSS for responsive two columns layout (text and images), but I am having hard time with that. Layout looks like this:
two column layout
Requirements:
Content within columns is generated dynamically based on the data from database (so the height of the columns is dynamic)
Columns must have equal width and height (height depends on content)
Content within columns must be horizontally and vertically aligned
Layout must be responsive, so when screen size is changed columns and content must resize accordingly without loosing the ratio and layout of images. In mobile screen the second column goes below the first one (width of the column is 90% of the screen)
Content position in layout could change, so text could be on the right column and images on the left column (configured in CMS). Such change must not affect layout at all
There may be more similar sections on the page, so the distance between them must not be too long and the content of one section cannot cover any other section
It must be displayed correctly on IE11
I have been playing with it for a while and it does not seem to work correctly for me. I have tried to play with position absolute and relative. Unfortunately, the problem is always with images. When I change the screen size two smaller images do not hold orignal position (they move to the left or right). I am not sure if my approach is good or not, I do not even know if something like this is possible in CSS (well, I could write a lot of media rules for different screen sizes, but I am looking for nicer solutions), I have never seen this images layout before. I would be very keen to know what the best approach is.
I created some code snippet in order to demonstrate the issue:
.section {
margin: 0;
display: block;
width: 100%;
height: auto;
padding: 0;
text-align: center;
}
.content-left {
position: relative;
display: inline-block;
width: 45%;
vertical-align: middle;
text-align: center;
float: left;
}
.content-right {
position: relative;
display: inline-block;
width: 45%;
vertical-align: middle;
text-align: center;
float: right;
}
.first-image-wrapper {
position: relative;
z-index: 1;
height: 10rem;
width: 10rem;
text-align: center;
margin: auto;
vertical-align: middle;
right: -2rem;
top: 7rem;
}
.content-image-1 {
vertical-align: middle;
border-radius: 0.2rem;
width: inherit;
height: inherit;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.second-image-wrapper {
position: relative;
right: -1rem;
bottom: 7rem;
border-radius: 0.2rem;
height: 8.4rem;
width: 8.4rem;
z-index: 4;
}
.content-image-2 {
max-width: 100%;
height: auto;
display: inline-block;
vertical-align: middle;
}
.third-image-wrapper {
position: relative;
bottom: 18rem;
right: -10rem;
border-radius: 0.2rem;
height: 5rem;
width: 5rem;
background-size: cover;
z-index: 5;
}
.content-image-3 {
max-width: 100%;
height: auto;
display: inline-block;
vertical-align: middle;
}
#media (max-width: 500px) {
.content-left, .content-right {
width: 100%;
display: block;
}
}
<div class="section">
<div class="content-left">
<div class="content-text">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Praesent sapien massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Praesent sapien massa
</p>
</div>
</div>
<div class="content-right">
<div class="first-image-wrapper">
<img class="content-image-1" src="https://i.postimg.cc/BtB3G5dz/P1000003.jpg" alt="Image 1">
</div>
<div class="second-image-wrapper">
<img class="content-image-2 " src="https://i.postimg.cc/SnJb8BJ0/P1000064.jpg" alt="Image 2">
</div>
<div class="third-image-wrapper">
<img class="content-image-3" src="https://i.postimg.cc/ykfzD16X/P1000071.jpg" alt="Image 3">
</div>
</div>
</div>
Any help would be appreciated.
display:flex works for a genuine IE11 (I run one) :
You could do :
.section {
align-items: center;
display: flex;
width: 100%;
}
.section>div {
width: 50%;
}
.content-right {
margin: auto;
}
img {
display: block;
margin: auto;
}
img:nth-child(1) {
width: 20%;
margin-left: 70%;
margin-bottom: -2rem;
}
img:nth-child(2) {
width: 45%;
margin-left: 10%;
position:relative;
}
img:nth-child(3) {
width: 50%;
margin: -2rem 0 0 40%;
;
}
#media (max-width: 500px) {
.section {
display: block;
}
.section>div {
width: auto;
}
}
<div class="section">
<div class="content-left">
<div class="content-text">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.
Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Praesent sapien massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Curabitur arcu erat, accumsan id
imperdiet et, porttitor at sem. Curabitur non nulla sit amet nisl tempus convallis quis ac lectus. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Praesent sapien massa
</p>
</div>
</div>
<div class="content-right">
<img class="content-image-1" src="https://i.postimg.cc/BtB3G5dz/P1000003.jpg" alt="Image 1">
<img class="content-image-2 " src="https://i.postimg.cc/SnJb8BJ0/P1000064.jpg" alt="Image 2">
<img class="content-image-3" src="https://i.postimg.cc/ykfzD16X/P1000071.jpg" alt="Image 3">
</div>
</div>
here is a jsbin that works and was made in IE11 https://jsbin.com/lemonopica/1/edit?html,css,output
If you don't fill okay with flex, you can use display:table and display:table-cell which allows vertical centering too , it is understood by every browsers. here is a table/table-cell demo https://jsbin.com/gecokurebe/1/edit?html,css,output
I try to ajust some dynamic content so it fit onto label to be printed.
The label has a row (.symbolContainer) that can contain 0 or more images. The objective is to shrink that .symbolContainer and those images if the content of .text box need more spaces.
EDIT: The row of images should not wrap, but shrink from 75px to a minimum of 25px.
Seem to me that flexbox is the way to go, and it ended up with 3 levels of nested flexbox, but the images inside the .symbolContainer won't shrink.
Content of .text div can overflow the .body div, but I will adjust the font-size with javascript after.
It is possible to acheive this with flexbox or other tricks?
Here is what I have done so far. Comment in CSS is what I wanted to do.
.container {
width: 3.5in;
height: 5in;
border: 1px solid black;
border-radius: 6px;
display: flex;
flex-direction: column;
}
.title {
font-weight: bolder;
font-size: 24px;
text-align: center;
}
.body {
background-color: #aad9fa;
flex: 1;
overflow: hidden;
display: flex;
flex-direction: column;
}
.symbolContainer {
display: flex;
justify-content: center;
background-color: #c1f1bf;
flex: 0 1 75px;
/* Height is 75px but shrink if need to */
/* No minimum height because can be empty */
}
.symbolContainer>img {
flex: 0 1 75px;
/* Size start at 75 px then shrink */
min-width: 25px;
/* but don't shrink pass 25px */
align-self: flex-start;
}
.text {
font-size: 22px;
flex: 1;
/* Take maximum possible space */
}
.footer {
text-align: center;
height: 30px;
background-color: green;
}
<div class='container'>
<div class='title'>
A title that can be multiline because of his variable length
</div>
<div class='body'>
<div class='symbolContainer'>
<img src="https://simdut.claurendeau.qc.ca/public/img/vector/flamme.svg">
<img src="https://simdut.claurendeau.qc.ca/public/img/vector/nocif.svg">
</div>
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam bibendum risus ex, nec gravida augue iaculis vel. Nam malesuada vitae libero ac tempus. Aenean et ipsum ac justo malesuada venenatis. Proin consequat tellus et varius mattis. Vestibulum
cursus dui in tincidunt pellentesque. Nullam feugiat lacus sem, et dapibus sapien maximus eu.
</p>
<p>Vivamus ullamcorper odio ex, sed rhoncus tellus sagittis eu. Proin egestas erat metus, sed congue dolor efficitur ac. Fusce ultrices quis urna vel tristique. Ut fermentum ipsum tellus, vel accumsan dui malesuada nec. Vivamus aliquam justo vel tortor
luctus, non venenatis lectus sagittis. Morbi feugiat sem nec elit varius ultricies.</p>
</div>
</div>
<div class='footer'>
This is the footer. Can be fixed height
</div>
</div>
You don't need those layers for the Flex Containers in order to do the images responsive.
Symbol Container should be:
.symbolContainer{
min-width: 0; /* resize as what you want */
margin: 5px; /* resize as what you want */
}
img {
width: 450px; /* resize as what you want */
max-width: 100%; /* resize as what you want */
max-height: 450px; /* resize as what you want */
}
.imgContainer{
display: flex;
justify-content: center;
flex-wrap: wrap;
}
Now the html should change to:
<div class='body'>
<div class='imgContainer'>
<div class='symbolContainer'>
<img src="https://simdut.claurendeau.qc.ca/public/img/vector/flamme.svg">
<img src="https://simdut.claurendeau.qc.ca/public/img/vector/nocif.svg">
</div>
</div>
...
That should do what you want. Be aware to resize to what you want.
Hope it helps!
pd. It's based on this post:
https://medium.com/#sashatran/check-out-the-page-here-7d71a2c43a10
I've got the following code:
* {
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 60rem;
/* 960 */
margin: 0 auto;
}
.item {
width: 100%;
overflow: hidden;
margin-bottom: 5rem;
/* 80 */
}
.item__img,
.item__info {
width: 50%;
float: right;
}
.item__img {} .item__img .img-map {
width: 95%;
height: 18.750rem;
/* 300 */
}
.item__img img {
width: 95%;
height: 18.750rem;
/* 300 */
}
<div class="container" role="main">
<article class="item">
<div class="item__info">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac sodales orci. Praesent sit amet consequat purus. Praesent lobortis mi quis rutrum fringilla. Phasellus velit arcu, ultricies vestibulum varius sed, convallis ut eros. Vestibulum
vel congue felis, ut lacinia tellus. Integer ullamcorper gravida ligula non convallis. Ut suscipit vulputate erat eu porttitor. Morbi sagittis vulputate bibendum. Aliquam ultricies finibus tortor, a elementum nisl aliquet at. In sed dui id mauris
rutrum ornare.</p>
</div>
<div class="item__img">
<div class="img-map">
<img src="http://biologypop.com/wp-content/uploads/2014/11/dog1.jpg" />
</div>
</div>
</article>
</div>
sorry for bad style, I've just started to learn CSS...
Now, after seeing that in the browser, I see the picture of a dog and next to it there's some text. I would like to have this text aligned in the center (vertically). Basically, currently it looks like this, and I would like to set it up like this. How should I modify my CSS code to display it as it is? Thanks!
EDIT My other question is - why the text is not lined up on the top to the top layer of the picture? I don't see any constraint for that in my css code, does anybody know how it works?
My suggestion is to ignore anyone that suggests using display:flex, because it doesn't have the browser support it needs for public domain. (currently as of 14/04/15. This will get better as time goes on and will probably be a more serious consideration once Windows 10 comes out later this year)
What you are wanting can be achieved with display:table; on the parent and display:table-cell; on the children. In the code below I have rearranged the HTML so the image is first and removed the float:right; (my experience leads me to not use float anymore as it causes so many headaches that can be avoided, but that's a much bigger discussion).
Adding vertical-align:middle; to the children will make them vertically align in their "cell".
The reason you were previously seeing space above your text is because each browser has a default style-sheet that is applied. For example Firefox has this:
p, dl, multicol {
display: block;
margin: 1em 0;
}
To aid your understanding of such things I suggest to use Mozilla Firefox and download the Firebug add-on.
Here's the full code:
* {
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 60rem;
/* 960 */
margin: 0 auto;
}
.item {
width: 100%;
overflow: hidden;
margin-bottom: 5rem;
display:table;
/* 80 */
}
.item__img,
.item__info {
width: 50%;
display:table-cell;
vertical-align:middle;
}
.item__img {} .item__img .img-map {
width: 95%;
height: 18.750rem;
/* 300 */
}
.item__img img {
width: 95%;
height: 18.750rem;
/* 300 */
}
<div class="container" role="main">
<article class="item">
<div class="item__img">
<div class="img-map">
<img src="http://biologypop.com/wp-content/uploads/2014/11/dog1.jpg" />
</div>
</div>
<div class="item__info">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ac sodales orci. Praesent sit amet consequat purus. Praesent lobortis mi quis rutrum fringilla. Phasellus velit arcu, ultricies vestibulum varius sed, convallis ut eros. Vestibulum
vel congue felis, ut lacinia tellus. Integer ullamcorper gravida ligula non convallis. Ut suscipit vulputate erat eu porttitor. Morbi sagittis vulputate bibendum. Aliquam ultricies finibus tortor, a elementum nisl aliquet at. In sed dui id mauris
rutrum ornare.</p>
</div>
</article>
</div>
This link might help you, I use this trick very often when it comes to vertically aligning:
http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/
Add this code:
position: relative;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
to a container around the text (in your case the 'p'), and make sure to set the height of the container (article.item) that wraps around both the image and the text.
You want to set a height of your div and line-height aswell.
Like:
.div{ height: 100px;
line-height: 100px;}
See an example here: http://jsfiddle.net/BRxKX/
Use flexbox if you can, it allows you to do this without any odd rules or hacks.
For example:
HTML
<div class="container">
<div class="image">200 x 200</div>
<p>Lots of text here...</p>
</div>
CSS
* {
box-sizing: border-box;
}
.container {
display: flex;
align-items: center;
}
.image {
height: 200px;
width: 200px;
min-width: 200px;
}
See it here in action. Try editing the text within the p tag to see how it works.