Make CSS Grid item (that wraps) span full width of container? - html

If I have one grid item (child) it spans 100% of it's container. If I add another, they'll be 50% and side by side (as intended).
If I add another, so it wraps, it stays at 50%, aligning with the first child above. Is it possible for this item to span the width of the container unless another item is added to the grid?
The reason I'm using grid is because I have these responsive/scalable flip/flashcards on click. So if the heights vary they still align nicely (code included).
Also a CodePen which might be easier to view due to viewport width: https://codepen.io/moy/pen/JjvPRgz
It this possible or would I need to compromise/look at a solution using flex maybe?
$('.flashcard').click(function() {
$(this).toggleClass('flipped');
});
/**
* Mixin
*/
/**
* Properties
*/
:root {
--btn-primary-bg: rgb(41, 174, 229);
--btn-primary-color: rgb(255, 255, 255);
--btn-primary-box-shadow: inset -8px -4px 0 rgba(0, 0, 0, 8%), 2px 2px 0 rgba(0, 0, 0, 8%);
--btn-primary-text-shadow: 1px 1px 0 rgba(0, 0, 0, 24%);
}
/**
* Base
*/
body {
box-sizing: border-box;
font-family: helvetica;
margin: 0 auto;
padding: 24px;
max-width: 800px;
}
h4, p {
font-size: 14px;
margin: 0;
padding: 0;
}
/**
* Flashcards
*/
.flashcard-wrap {
display: grid;
grid-template-columns: 1fr;
grid-gap: 12px;
grid-auto-rows: 1fr;
margin-bottom: 24px;
}
#media (min-width : 64em) {
.flashcard-wrap {
grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
}
}
.flashcard {
cursor: -webkit-grab;
cursor: grab;
display: flex;
perspective: 40rem;
transition: z-index, transform 0.24s;
transition-delay: 0.24s, 0s;
z-index: 0;
}
.flashcard.flipped {
transition-delay: 0s;
z-index: 1;
}
.flashcard:active {
cursor: -webkit-grabbing;
cursor: grabbing;
transform: scale(0.8);
}
.flashcard :last-child {
margin-bottom: 0;
}
.flashcard .bubble {
margin-bottom: 12px;
}
.flashcard__inner {
display: flex;
flex: 1;
transform-style: preserve-3d;
transition: 0.24s transform;
}
.flashcard.flipped .flashcard__inner {
transform: rotateX(-180deg);
}
.flashcard__front,
.flashcard__back {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
background-color: white;
box-sizing: border-box;
padding: 1.5rem;
border-radius: 0.25rem;
background: var(--btn-primary-bg);
box-shadow: var(--btn-primary-box-shadow);
backface-visibility: hidden;
border-radius: 12px;
box-sizing: border-box;
color: var(--btn-primary-color);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 14px;
padding: 24px;
min-width: 100%;
}
.flashcard__back {
transform: rotateX(-180deg) translate(-100%, 0);
}
.flashcard__back--left-align {
align-items: flex-start;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="flashcard-wrap">
<div class="flashcard">
<div class="flashcard__inner">
<div class="flashcard__front">
<h4 class="flashcard__title">Heading #1</h4>
</div>
<div class="flashcard__back">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
</div>
<div class="flashcard">
<div class="flashcard__inner">
<div class="flashcard__front">
<h4 class="flashcard__title">Heading #2</h4>
</div>
<div class="flashcard__back">
<p>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>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>
</div>
<div class="flashcard">
<div class="flashcard__inner">
<div class="flashcard__front">
<h4 class="flashcard__title">Heading #3</h4>
</div>
<div class="flashcard__back">
<p>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>
</div>
</div>

Wanna show the divs beside together?
you can use flex-wrap property for container and set it to nowrap as the default is.
Hope it was helpful.

This is possible with CSS alone. You do not need to change much of your existing code – just tweaking your grid for desktop and adding an extra line.
As you want two columns in your grid when there is more than one card we can simplify your grid so it is fixed to two columns. The only time a card needs to span the whole width of the container is if there are an odd number of flashcards (including when there is just a single flashcard). You also know you only want the last flashcard to span the whole width. On that basis we target each of those in order. To your flashcard-wrap class you need to add the following:
.flashcard-wrap {
//existing code
#include bp(bp5) {
grid-template-columns: repeat(2,1fr); // change to existing code so we always have two columns available.
& > *:nth-child(odd):last-child { // this will target the last flashcard but only if there are an odd number of cards - that includes the situation of there only being one card
grid-column: span 2;
}
}
}
NB: I have used the universal selector * as that will give you the flexibility to add different elements there if you need to. You can just as easily swap out * for .flashcard though if you only want the rule applied to flashcards.

Related

How to prevent element absolute position from overlap in css

I have a div element to show my blog post, each post have to load an image, a title and one paragraph inside it,
because I want to show title element at bottom of image with a simple background-color then I write the markup like this:
<div class="post">
<div class="thumb">
<img class="image" src="img">
<h3 class="title">title</h3>
</div>
<p class="content">Content</p>
</div>
I put the image and title element inside a div block to place them on each other(title overlap the image) and set thumb position to relative and two child element(image and title) to absolute to achieve the final result, but after that the image and title goes outside of it parent(post element) and overlap the other element above of it in the page.
.post {
.thumb {
position: relative;
.image {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%
}
.title {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: rgba(#000, .7);
color: #fff;
padding: .5rem;
}
}
.content {
}
}
I want to know why the parent element lose it's height block space and overlap on other elements.
I read some of the similar questions but non of them answer this.
I know if I just set the title position to absolute and fixed on the bottom of image keep the space of block, or use css grid's to achieve similar things but I want to find the real reason to this problem and how to prevent it?
The complete sample code is on codepen: https://codepen.io/anon/pen/GaMegN?editors=1100#0
.post .thumb {
position: relative;
}
.post .thumb .image {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
.post .thumb .title {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: rgba(0, 0, 0, 0.7);
color: #fff;
padding: .5rem;
}
<div class="page">
<div>
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 class="post">
<div class="thumb">
<img class="image" src="https://picsum.photos/400/200">
<h3 class="title">just a sample title</h3>
</div>
<p class="content">
CSS output is just like HTML, only there is no special formats you need to worry about. Just add the CSS you want to output (using newlines as needed) and it will output that way.
</p>
</div>
</div>
The thumb wont have a height because elements with position: absolute; does not take up relative space in it.
I would suggest to remove the position: absolute; on the image, that would give the thumb width and height, but keep absolute on the title
.post .thumb {
position: relative;
}
.post .thumb .image {
display: block;
max-width: 100%;
max-height: 100%;
}
.post .thumb .title {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: rgba(0, 0, 0, 0.7);
color: #fff;
padding: .5rem;
margin: 0;
}
<div class="post">
<div class="thumb">
<img class="image" src="https://picsum.photos/400/200">
<h3 class="title">title</h3>
</div>
<p class="content">Content</p>
</div>
Absolute positioned elements step out of the regular flow. The parent elements (position: relative) now don't know anything about the size of their child. For them it is just like the child has display: none. I won't affect their own size in any way.
How can you prevent this? There may be many ways.
Don't use absolute on every element: Here I set the .title to relative so that I can control the z-index. I needed the overflow: hidden on .thumb. I added some margins on .title so I can see more of the image
.post .thumb {
position: relative;
/* new */
overflow: hidden;
margin-top: 20px;
}
.post .thumb .image {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
}
.post .thumb .title {
display: block;
/* position: absolute; */
/* bottom: 0; */
/* left: 0; */
width: 100%;
background: rgba(0, 0, 0, 0.7);
color: #fff;
padding: .5rem;
/* new */
position: relative;
z-index: 1;
margin-bottom: 20px;
margin-top: 60px;
}
<div class="page">
<div>
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 class="post">
<div class="thumb">
<img class="image" src="https://picsum.photos/id/990/400/200">
<h3 class="title">just a sample title</h3>
</div>
<p class="content">
CSS output is just like HTML, only there is no special formats you need to worry about. Just add the CSS you want to output (using newlines as needed) and it will output that way.
</p>
</div>
</div>
Or use a background-image instead of an <img> element
.post .thumb {
position: relative;
overflow: hidden;
margin-top: 20px;
background-repeat: no-repeat;
background-size: cover;
background-position: center 40%;
}
.post .thumb .title {
display: block;
width: 100%;
background: rgba(0, 0, 0, 0.7);
color: #fff;
padding: .5rem;
position: relative;
z-index: 1;
margin-bottom: 20px;
margin-top: 60px;
}
<div class="page">
<div>
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 class="post">
<div class="thumb" style="background-image: url(https://picsum.photos/id/990/400/200)">
<h3 class="title">just a sample title</h3>
</div>
<p class="content">
CSS output is just like HTML, only there is no special formats you need to worry about. Just add the CSS you want to output (using newlines as needed) and it will output that way.
</p>
</div>
</div>
Change the position of the image and the title to relative and just add a top:-100px (or whatever) to your title
When you set any element to absolute they are taken out of normal document flow and thus other elements position themselves as the targeted absolute element does not exist.
*{
box-sizing:border-box;
}
.post .thumb {
position: relative;
}
.post .thumb .image {
display: block;
width: 100%;
}
.post .thumb .title {
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: rgba(0, 0, 0, 0.7);
color: #fff;
padding: .5rem;
margin:0;
}
<div class="page">
<div>
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 class="post">
<div class="thumb">
<img class="image" src="https://picsum.photos/400/200">
<h3 class="title">just a sample title</h3>
</div>
<p class="content">
CSS output is just like HTML, only there is no special formats you need to worry about. Just add the CSS you want to output (using newlines as needed) and it will output that way.
</p>
</div>
</div>

how to adjust margin and padding using width with percentage?

So I want to achieve this using css and html
So I wrote this code that sets the width of each box to 33.33%
/* Base style */
h1 {
text-align: center;
}
.row {
width: 100%;
height: auto;
padding: 10px;
}
* {
box-sizing: border-box;
font-family: sans-serif;
margin: 0px;
}
div > div {
background-color: gray;
border: 1px solid;
float: left;
}
.dummy_text {
clear: right;
padding: 10px;
}
/* Top right paragraphs*/
#chiken {
float: right;
background-color: pink;
border: 2px solid;
width: 150px;
text-align: center;
font-weight: bold;
position: relative;
left: 1px;
padding: 5px;
}
#beef {
float: right;
background-color: indianred;
color: white;
border: 2px solid black;
width: 150px;
text-align: center;
font-weight: bold;
left: 1px;
padding: 5px;
}
#sushi {
float: right;
background-color: lightgoldenrodyellow;
border: 2px solid;
width: 150px;
text-align: center;
font-weight: bold;
left: 1px;
padding: 5px;
}
/* Desktop */
#media (min-width: 992px) {
.col-dsk-3 {
float: left;
width: 33.33%;
}
}
<h1>Our menu</h1>
<div class="row">
<div class="col-dsk-3 col-tbl-2 col-mbl-1">
<p id="chiken">Chicken
<p>
<p class="dummy_text">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 class="col-dsk-3 col-tbl-2 col-mbl-1">
<p id="beef">Beef
<p>
<p class="dummy_text">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 class="col-dsk-3 col-tbl-1 col-mbl-1">
<p id="sushi">Sushi
<p>
<p class="dummy_text">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>
And the result is this:
The thing is that I need spacing between paragraphs, so what I though was to add some margin-left to the boxes, the thing is that when I add 10px, the result is that one of the three boxes goes to a new line, but I need the three in the same line.
This is what I did to add the margin, I modify the div > div part like this:
div > div {
background-color: gray;
border: 1px solid;
float: left;
margin-left: 10px;
}
And then result:
Use % values for all your layout widths.
Use :last-child to set the margin of the right div to zero.
div > div {
background-color: gray;
border: 1px solid;
float: left;
margin-right: 2%
}
div > div:last-child {
margin-right: 0;
}
/* Desktop */
#media (min-width: 992px) {
.col-dsk-3 {
float: left;
width: 32%;
}
}
Here's a codepen:http://codepen.io/prime8/pen/LRympm
Use calc for with
.col-dsk-3 {
float: left;
width: calc(33.33% - 20px);
margin-right: 10px;
}
.col-dsk-3:last-child {
margin-right: 0px;
}
But I suggest you use flexbox instead
When adding the margin-left: 10px to each paragraph you are making their widths larger than 33.33% which results in being greater than 100% pushing the last paragraph down.
Like all things in CSS, there is a couple of different ways you can solve this, but the easiest and most direct answer to your question is using the calc CSS function. The calc function calculates a numerical value in CSS using basic math operations.
Using the calc function you can then set the width of each paragraph to be:
width: calc(33.33% - 10px);
Which will result in a 100% fit.
There are a number of things you can do about this.
1 - Use calc to reduce the width of elements currently set to 33.33% by 10px, and use 10px margin:
.col-dsk-3 {
float: left;
width: calc(33.33% - 10px);
margin-right: 10px;
}
2 - Wrap the content of your columns in another element, and apply a padding to your columns:
<div class="col-dsk-3 col-tbl-2 col-mbl-1">
<div class="column-content">
<p id="chiken">Chicken<p>
<p class="dummy_text">Lorem ipsum dolor sit....</p>
</div>
</div>
.column-content {
background-color: gray;
}
.col-dsk-3 {
float: left;
width: 33.33%;
padding: 10px;
background: none;
}
3 - use flexbox instead of floats for your columns. Remove the floats and the width: 33.33%, and add:
.row {
display: flex;
flex-direction: row;
}
.col-dsk-3 {
margin: 10px;
}
You use percentages to define the width, but add absolute values to the margins. Your widths add up to (almost) 100%, yet you add more margins, resulting in more than 100%, therefore to a value that is bigger than the space that is available.
Adjust your margins to use percentages as well and make sure you end up with 100% or less.
Try this. To use additional div wrapper in HTML.
This way has a good compatibility.
/* Base style */
h1 {
text-align: center;
}
.row {
width: 100%;
height: auto;
padding: 10px;
}
* {
box-sizing: border-box;
font-family: sans-serif;
margin: 0px;
}
/* NOTE: `.row > div > div` is better than `div > div > div` */
div > div > div { /* changed */
background-color: gray;
border: 1px solid;
float: left;
}
.row > div > div { /* changed */
margin: 0 10px;
}
.dummy_text {
clear:right;
padding: 10px;
}
/* Top right paragraphs*/
#chiken {
float: right;
background-color: pink;
border: 2px solid;
width: 150px;
text-align: center;
font-weight: bold;
position: relative;
left: 1px;
padding: 5px;
}
#beef {
float: right;
background-color: indianred;
color: white;
border: 2px solid black;
width: 150px;
text-align: center;
font-weight: bold;
left: 1px;
padding: 5px;
}
#sushi {
float: right;
background-color: lightgoldenrodyellow;
border: 2px solid;
width: 150px;
text-align: center;
font-weight: bold;
left: 1px;
padding: 5px;
}
/* Desktop */
#media (min-width: 992px) {
.col-dsk-3 {
float: left;
width: 33.33%;
}
}
<h1>Our menu</h1>
<div class="row">
<div class="col-dsk-3 col-tbl-2 col-mbl-1">
<div>
<p id="chiken">Chicken<p>
<p class="dummy_text">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>
<div class="col-dsk-3 col-tbl-2 col-mbl-1">
<div>
<p id="beef">Beef<p>
<p class="dummy_text">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>
<div class="col-dsk-3 col-tbl-1 col-mbl-1">
<div>
<p id="sushi">Sushi<p>
<p class="dummy_text">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>
</div>

Div with height % not collapsing into itself with overflow auto

Alright so this is the third time I've looked for help on a particular element I'm working on in an app so I apologize for the repetition.
I'm building a questionnaire for an application and I want all the questions to be contained in a div and the overflow hidden. The problem I'm currently running into is if the height doesn't exceed 80% of the window size the containing div doesn't collapse into itself and there is an unnecessary amount of whitespace left over.
I have tried to switch the questionnaire-box height style to max-height but this caused the overflow content of the .questions div to be hidden instead of scrollable.
I have a strong suspicion I may need to handle this with js but I prefer straight CSS and HTML if possible.
Anyone have any suggestions?
html, body {
height: 100%;
}
.questionnaire-container {
display: flex;
position: fixed;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 255, .1);
}
.questionnaire-box {
position: relative;
width: 80%;
height: 70%;
margin: 0 auto;
background-color: #ffffff;
overflow: hidden;
}
.questions {
height: 100%;
padding: 1rem 2rem;
overflow-y: auto;
}
<div class="questionnaire-container">
<div class="questionnaire-box">
<div class="questions">
<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>
</div>
You have to move the padding from .questions to .questionnaire-box. Also, .questions has no (...-)width attributes set anymore, but the .questionnaire-box's max-width is calc(70vh - 2rem).
Fiddle: https://jsfiddle.net/moor131j/2/

How to get div to fill parent on auto resize

I am trying to make a ticket system, and it's designed to be similar to a forum thread system, ie have the user info on the left side like avatar and username, and then have the post data on the right hand side, I have managed to make a design for this in html/css and it works perfectly but there is an issue
As you can see when the right hand column stretches (due to it being filled with content, the left hand column doesnt stretch with it)
I have tried setting the height of the left-hand column to 100% to effectively fill its container but it doesn't seem to work
HTML:
<div class="ticket_content">
<div class="tickets_left"><img src="images/avatar_admin.png"/>
<div class="usernameinfo">ADMINISTRATOR</div>
<div clas="clear"></div>
</div>
<div class="tickets_right_admin"><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 class="clear"/></div>
</div>
CSS
.ticket_content {
width: 900px;
display: block;
border: 2px solid #171B1E;
border-radius: 6px;
background: none repeat scroll 0% 0% #121416;
margin-bottom: 22px;
box-shadow: 0px 0px 7px rgba(212, 198, 198, 0.79);
}
.tickets_right {
float: left;
width: 750px;
min-height: 185px;
background: none repeat scroll 0% 0% #121416;
}
.tickets_right_admin {
background: #353018;
float: left;
width: 750px;
min-height: 185px;
}
.tickets_right_admin p{
padding:18px;
}
.tickets_left {
float:left;
width: 141px;
background:red;
min-height: 185px;
background: url('../images/leftsiderepeat.png') repeat-y;
}
Again what i'm trying to achieve is have tickets_left fill ticket_content vertically when tickets_right stretches it (as you can see in the image the background of tickets_left does not follow the same height as the right hand side)
Fixed by using table cell display, for the inner-divs and table display for the outer div, also added
vertical-align:top
to the inner div's
Fixed css:
.tickets_left {
display: table-cell;
vertical-align: top;
width: 141px;
background:red;
min-height: 185px;
background: url('../images/leftsiderepeat.png') repeat-y;
}
.tickets_right {
display:table-cell;
float: left;
width: 750px;
min-height: 185px;
background: none repeat scroll 0% 0% #121416;
}
.tickets_right_admin {
display: table-cell;
background: #353018;
float: left;
width: 750px;
min-height: 185px;
}
.ticket_content {
display: table;
width: 900px;
border: 2px solid #171B1E;
border-radius: 6px;
background: none repeat scroll 0% 0% #121416;
margin-bottom: 22px;
box-shadow: 0px 0px 7px rgba(212, 198, 198, 0.79);
}
try the following style for inner div:
{
position: relative;
left: 0;
top: 0;
width100%;
height:100%;
}

DIV positioning issue when resizing web browser window

As you can see on the picture below and on this JSFiddle http://jsfiddle.net/w2Njv/, my issue is that my text won't stay aligned to the right of the picture and at the same level when I reduce the width of my webbrowser window. It actually moves below the picture.
I don't understand why because .pt-intro-text has a width of 60% no matter what the size of the screen is so to me it should always look good as on the first picture and never move below the picture.
Thanks for your help
Looks OK with wide width:
Looks bas when resizing window (text won't stick to the right of the picture):
http://jsfiddle.net/w2Njv/
HTML
<div class="wrapper">
<section class="intro-personal-training clearfix">
<div class="pt-intro-header clearfix">
<h2 class="_text">Nous fdfds en place un dfdsfdsfds qui vous dfds</h2>
<h3 class="_text">dfsf soit votredfdsd dfds</h3>
</div>
<div class="intro-pic-container"></div>
<div class="pt-intro-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>
<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>
</section>
</div>
CSS:
section {
position: relative;
}
.wrapper {
width: 90%;
max-width: 1200px;
margin-right: auto;
margin-left: auto;
background-color: rgb(255, 255, 255);
}
.intro-personal-training img {
float: left;
clear: both;
width: 120px;
margin-top: 21px;
margin-left: 75.02759%;
}
.pt-intro-header h3 {
margin-top: 3px;
font-size: 26px;
color: #3a7cdb;
}
.pt-types-de-coaching-header h3,
.restons-en-contact h3 {
max-width: 700px;
font-size: 18px;
color: rgb(45, 125, 223);
}
.intro-personal-training {
margin-top: 70px;
margin-right: auto;
margin-left: auto;
}
.intro-pic-container {
float: left;
clear: both;
width: 329px;
height: 262px;
margin-top: 59px;
margin-left: 2.88%;
background-image: url('http://lorempixel.com/output/fashion-q-g-329-262-5.jpg');
background-repeat: no-repeat;
background-size: auto auto;
background-position: center center;
}
.pt-intro-text {
display: inline-block;
float: right;
width: 60%;
margin-top: 59px;
margin-right: 4.6671699999%;
padding-left: 15px;
border-left-width: 1px;
border-left-color: rgb(0, 0, 0);
border-left-style: dotted;
text-align: justify;
letter-spacing: 1px;
color: #1a1a1a;
}
._text {
margin-right: auto;
margin-left: auto;
}
.pt-intro-text has a width of 60%, but .intro-pic-container has in small resolution more than 40% and then text won't stay aligned to the right.
Put img element into this div and give him max width 40% (or 37% width + 3% margin).
.intro-pic-container {
float: left;
width: 329px;
max-width:37%;
height: auto;
margin-top: 59px;
margin-left: 2.88%;
}
.intro-pic-container img{
width: 100%;
}
And element .pt-intro-text must have 60% width (or width + margin + padding = 60%).
If you want responsive design dont use size (width, margin and padding) in pixels only percentage.
Fiddle: http://jsfiddle.net/w2Njv/10/
PS: Sorry for my bad english
Actually, if you set up the pt-intro-text div with a float:left it would more "responsive" as it allows for a nicer view when seen on a smaller device for instance.
if you really want to avoid that behaviour, use a fixed min-width like:
.wrapper{ min-width: 1100px; ... }
See http://jsfiddle.net/zHVHL/1/