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%;
}
Related
I want to show a number of text blocks, at first just showing the title and a few lines, and after clicking a 'more' tag show it all, or hide it again.
I used the CSS trick of hidden checkbox and label, and it looked almost correct.
label {
width: 50%;
border-radius: 5px;
background: linear-gradient(to bottom, rgba(255,255,255,0.0) 0%, rgba(0,0,128,0.7) 100%);
cursor: pointer;
}
label:after {
content: "see more...";
margin-left: 1%;
font-style: italic;
font-weight: bold;
font-size: smaller;
}
.lbl1 {
// display:inline-block;
padding-top: 40px;
color: white;
font-style: italic;
}
input[id^="more"] {
display: none;
}
input[id^="more"]:checked ~ .lbl1:after {
content: "show less";
}
input[id^="more"]:checked ~ .arttxt1{
height: 100%;
}
.arttxt1{
margin-left:1%;
width: 50%;
margin-bottom:2px;
line-height: 2.5ex;
height: 8.4ex; /* 2.5ex for each visible line */
overflow: hidden;
}
<article>
<h1>De regels</h1>
<input id='more20' type='checkbox'/>
<div class='arttxt1'>
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>
<label for='more20' class='lbl1'> </label>
</article>
The label to click on only had the width of the text, whereas I wanted it streteched over the full width.
Searching suggested adding 'display: inline-block' which I did. It indeed stretched the label over the full width, but I also lost the transparency: it sort of lies in front of the text.
I tried and I searched but could not find a proper solution. Hope someone can help me.
Is this the effect you want?
using negative margin to move div up
label {
width: 50%;
border-radius: 5px;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.0) 0%, rgba(0, 0, 128, 0.7) 100%);
cursor: pointer;
}
label:after {
content: "see more...";
margin-left: 1%;
font-style: italic;
font-weight: bold;
font-size: smaller;
}
.lbl1 {
display: inline-block;
padding-top: 40px;
color: white;
font-style: italic;
margin-top: -40px;
padding-left: 1%;
}
input[id^="more"] {
display: none;
}
input[id^="more"]:checked~.lbl1:after {
content: "show less";
}
input[id^="more"]:checked~.arttxt1 {
height: 100%;
}
.arttxt1 {
margin-left: 1%;
width: 50%;
margin-bottom: 2px;
line-height: 2.5ex;
height: 8.4ex;
/* 2.5ex for each visible line */
overflow: hidden;
}
<article>
<h1>De regels</h1>
<input id='more20' type='checkbox' />
<div class='arttxt1'>
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>
<label for='more20' class='lbl1'> </label>
</article>
To clarify, it doesn't lose the transparency - what is actually happening is that because your <div class="arttxt1"> is a block element, the label is being pushed down to below the text.
As such, you can either use margin-top as per Chris Li's answer, or position:relative and top to push the label up over the top of your text.
label {
width: 50%;
border-radius: 5px;
background: linear-gradient(to bottom, rgba(255,255,255,0.0) 0%, rgba(0,0,128,0.7) 100%);
cursor: pointer;
}
label:after {
content: "see more...";
margin-left: 1%;
font-style: italic;
font-weight: bold;
font-size: smaller;
}
.lbl1 {
display:inline-block;
padding-top: 40px;
color: white;
font-style: italic;
position:relative;
top: -40px;
}
input[id^="more"] {
display: none;
}
input[id^="more"]:checked ~ .lbl1:after {
content: "show less";
}
input[id^="more"]:checked ~ .arttxt1{
height: 100%;
}
.arttxt1{
margin-left:1%;
width: 50%;
margin-bottom:2px;
line-height: 2.5ex;
height: 8.4ex; /* 2.5ex for each visible line */
overflow: hidden;
}
<article>
<h1>De regels</h1>
<input id='more20' type='checkbox'/>
<div class='arttxt1'>
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>
<label for='more20' class='lbl1'> </label>
</article>
I am trying to do this shape in HTML/CSS for my mobile app:
https://embed.plnkr.co/9k8jbJyzUiSMSoSHlOti/
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
}
<div class="boundary"></div>
<div class="inner">
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 auteirure 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>
In my browser, when I inspect the element and change the zoom (to 75%), there is a gap between 2 <div>. When I deploy my application in my device, I can see this same gap.
What is going on ?
This is how I make the shape:
I create a first div to do the inclined line. I make a responsive triangle (I picked some information from this Question)
1) In my div, I insert a first pseudo-element and give it 100% width and height of parent. I apply a rotation : I define a transform origin in the top left, and rotate the pseudo element 3 degrees clockwise with transform: rotate(3deg)
2) I have to adjust width and height: I use percentages and padding-bottom to maintain the aspect ratio (more information here) so:
[rectangle height] : padding-bottom = tan(3deg) * 100% = 100.13723% (100% is the screen width)[hypotenuse of triangle = new rectangle width] : width = tan(3deg) * 100% / sin(3deg) = 5.24078%.
3) To hide the unwanted parts of the pseudo element (everything that overflows the <div> with the red border) I set overflow: hidden on the container.
I make a second <div> after the first inclined <div>. This <div> is simple, without special transformation, and contains Lorem ipsum.
This usually happens while transforming elements because browser starts doing antialiasing with elements' edges.
Antialiasing is something of an unsung hero in web graphics; it’s the
reason we have clear text and smooth vector shapes on our screens.
While zooming out/in browser doesn't rescale element properly, e.g. if you zoom out an element of 1px height to 0.75%, browser should redraw element to 0.75px but browser cannot draw 0.75px, it either can create it 1 or it will try to make edges smooth with making pixel blur or 50% opacity.
In above picture you can see the same triangle being drawn, but on the left it has antialiasing enabled and on the right it’s been disabled. As you can see, when antialiasing is enabled the pixels are shades of gray when the triangle only passes through part of the pixel. When disabled, however, the pixel is filled in as either solid black or solid white and the shape looks jagged.
Using backface-visibility: hidden; or overlapping elements with negative margins while scaling/transforming is the better option to avoid this issue.
Demo without using backface-visibility: hidden;
html,
body {
transform: scale(.8);
}
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
}
<div class="boundary"></div>
<div class="inner">
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>
Demo with using backface-visibility: hidden;
html,
body {
transform: scale(.8);
}
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
<div class="boundary"></div>
<div class="inner">
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>
Demo provided by OP in comment solved by using backface-visibility: hidden; and overlapping elements with negative margin
html,
body {
transform: scale(.75);
}
.inner {
height: 100%;
width: 100%;
background-color: green;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.inner-2 {
background-color: red;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.inner-3 {
background-color: blue;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
margin-top: -2px;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
backface-visibility: hidden;
}
.boundary-2 {
background-color: green;
}
.boundary-2:before {
transform-origin: top right;
transform: rotate(-3deg);
background-color: red;
}
.boundary-3 {
background-color: red;
}
.boundary-3:before {
transform-origin: top left;
transform: rotate(3deg);
background-color: blue;
}
<div class="boundary"></div>
<div class="inner">
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="boundary boundary-2"></div>
<div class="inner inner-2">
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="boundary boundary-3"></div>
<div class="inner inner-3">
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>
PS: Don't forget to use viewport meta tag for responsiveness.
Source Antialiasing-101
I think I have fixed it by using skew and adding a border and a negative margin at the top.
Here's a CodePen and below is my CSS:
.boundary {
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 105%;
height: 105%;
transform-origin: top left;
background-color: green;
transform: skew(0, 3deg);
z-index: 10;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
color: #fff;
z-index: 50;
position: relative;
border-top: 1px solid green;
margin-top: -1px;
}
Gap is still there even if you do not apply any transformation.
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/*transform-origin: top left;*/
/*transform: rotate(3deg);*/
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
}
<div class="boundary"></div>
<div class="inner">
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 auteirure 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>
So transform:rotate() or something are not causing any troubles.
Now your problem can be solved by
.inner {
margin-top: -2px;
/* experiment different value or unit for different zoom levels*/
height: 100%;
width: 100%;
background-color: green;
}
For me it is rendering problem. If you change
top: 0px;
to
top: 1px;
everything should be fine.
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>
So here is what i was trying to do
i wanted to have a div with z-index -1 somewhere between 2 other divs to test the parallax effect on it i put everything on the center with margin : 0 auto . but when i changed the parallax div position to absolute, it moved to the left side of the page . next i tried moving it back to center with left :50% it didn't work so what i changed it to left :12.5% and it worked !
But here is my question : could i do it in any other way ?! and is what i did now right or is it gonna cause some problems in the future ?!
here are the codes :
Html :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Meaningless Pap</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="content1">
<h1>Welcome! </h1>
<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="breaker" data-0="background-position:0px 0px;" data-700="background-position:0px -300px;">
<h2> this is a text </h2>
</div>
<div class="content2">
<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>
<script type="text/javascript" src="skrollr.min.js"></script>
<script type="text/javascript">
skrollr.init();
</script>
</body>
</html>
Css :
body {
font-family: 'lato';
background: url("http://habrastorage.org/files/90a/010/3e8/90a0103e8ec749c4843ffdd8697b10e2.jpg") #000;
background-size: cover;
background-position: center;
background-attachment: fixed;
font-size: 100%;
line-height: 1.7;
color: #000;
}
.container {
width: 100%;
margin: 0 auto;
}
.content1 {
position: relative;
background: #fff;
width: 75%;
margin: 0 auto;
border-radius: 5px;
border: 1px solid #000;
box-shadow: 0px 7px 15px #333;
padding: 10px;
z-index: 1;
}
.content2 {
position: relative;
background: #fff;
width: 75%;
margin: 0 auto;
border-radius: 5px;
border: 1px solid #000;
box-shadow: 0px -7px 15px #333;
padding: 10px;
z-index: 1;
margin-top: 200px;
}
.breaker {
position: absolute;
left: 12.5%;
width: 75%;
height: 250px;
background: url('bg.jpg');
z-index: -1;
}
.breaker h2 {
padding-top: 50px;
text-align: center;
color: #fff;
}
There is nothing wrong with your approach. The width percentage and the left percentage are calculated in the same way when absolutely positioned - relative to the first parent element that has a position other than static.
An alternative method for an absolutely positioned element would be to specify both left and right positions. This has the advantage of being unaffected by any borders or padding.
.breaker {
position: absolute;
left: 12.5%;
right: 12.5%;
height: 250px;
background: url('bg.jpg');
z-index: -1;
}
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/