I have problem with position: absolute and floats...
As you can see in fiddle, when you resize browser, text from left side goes below the image, but what I want is to go above the image.
When I remove position: absolute on .image-ipad, it works like that, but in my project I need image to stick on left side, and text on right side (normal)
Code:
HTML
<section class="case eat-login">
<div class="row">
<h3 class="stick-right">Login Screen</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<img class="image-ipad" src="http://www2.pcmag.com/media/images/362825-apple-ipad-mini.jpg?thumb=y" width="300px">
<div style="clear:both;"></div>
</div>
</section>
CSS
.stick-right{
float:right;
clear:both;
}
.eat-login {
position: relative;
padding: 130px 0 130px;
clear: both;
}
.eat-login p{
text-align: right;
float: right;
clear: both;
width: 45%;
font-size: 15px;
font-family: "Proxima Nova";
color:#9e9d9d;
line-height: 25px;
}
img.image-ipad {
left:0px;
top:40px;
}
JSFiddle: http://jsfiddle.net/jt9jk2g0/6/
Thanks!
You could do it by using css #media queries for small screen size:
JSFiddle - DEMO
HTML:
<section class="case eat-login">
<div class="row">
<img class="image-ipad" src="http://www2.pcmag.com/media/images/362825-apple-ipad-mini.jpg?thumb=y" width="300px">
<h3 class="stick-right">Login Screen</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<div style="clear:both;"></div>
</div>
</section>
CSS:
.stick-right {
float:right;
clear:both;
}
.eat-login {
position: relative;
padding: 130px 0 130px;
clear: both;
}
img {
position: absolute;
}
.eat-login p {
text-align: right;
float: right;
clear: both;
width: 45%;
font-size: 15px;
font-family:"Proxima Nova";
color:#9e9d9d;
line-height: 25px;
}
#media (max-width: 500px) {
h3 {
margin-top:300px;
}
}
Related
I would like to darken the background images however text colors change, as well how Can I avoid it? I tried with background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.7) 100%), url(./img/1,jpeg) But in this case I have to add url at the end but it is not effiecent way since I have 4 images in this case.
HTML
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
crossorigin="anonymous">
<div class="card-group">
<div class="card img1">
<div class="info">
<h5 class="card-title">Planning</h5>
<p class="card-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
</div>
</div>
<div class="card img2">
<div class="info">
<h5 class="card-title">Customer Satisfaction</h5>
<p class="card-text">Lorem ipsum dolor .</p>
</div>
</div>
<div class="card img3">
<div class="info">
<h5 class="card-title">Build</h5>
<p class="card-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
</div>
</div>
<div class="card img4">
<div class="info">
<h5 class="card-title">Analyse</h5>
<p class="card-text">Lorem ipsum dolor sit amet, consetetur.</p>
</div>
</div>
</div>
CSS
.card{
min-height:30vh;
display: inline-block;
}
.card .info {
position:absolute;;
padding:0em 1em;
bottom:0.5em;
visibility:hidden;
color:#5383d3;
}
.card-title {
font-size:1.5em;
margin-bottom: .1em;
}
.card-text {
font-size:1em;
}
.card:hover{
-webkit-filter: grayscale(150%); /* Safari 6.0 - 9.0 */
filter: grayscale(150%);
}
.card:hover .info {
visibility:visible;
}
.img1{
background: url("./img/1.jpeg") no-repeat center center;
}
.img2{
background: url("./img/2.jpg") no-repeat center center;
}
.img3{
background: url("./img/3.jpeg") no-repeat center center;
}
.img4{
background: url("./img/4.jpg") no-repeat center center;
}
ANother problem is the white spacing between images even there is no border in my cs somehow it looks like there is
To use filters you will have to alter your html a bit.
<div class="card">
<div class="img1 img"></div>
<div class="info">
<h5 class="card-title">Planning</h5>
<p class="card-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr.</p>
</div>
</div>
Now you can use your css like that:
.card {
position: relative;
}
.card .img {
position: absolute;
left: 0px;
top: 0px;
bottom: 0px;
right: 0px;
}
.card:hover .img {
filter: grayscale(100%);
}
You can't just change the background image without changing its content. You can use a pseude element as an overlay though. This has another advantage as you can animate more easily this way.
.card {
position: relative;
}
.card:before {
content: '';
position: absolute;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
background: rgba(96, 69, 56, 0.5);
pointer-events: none;
}
The Problem for your second problem is an easy mistake that happens quite often. Display inline-block interprets white spaces between elements as it is expecting some inline behaviour. You can either get rid of all white spaces in your code between the div class="card" (sounds strange but works), or even better you use display: flex
.card-group {
display: flex;
justify-content: center;
}
.card {
flex-basis: 25%;
}
I want the green element to be under the text box and also under image.
I tried to set the z-index for each element, but nothing has changed.
Can I reach this through the z-index property?
I can't change html. And I also want the pseudo-element to be a child of the text block for the adaptive height
.item {
display: flex;
align-items: flex-start;
width: 400px;
height: 250px;
}
.col1 {
margin-right: 20px;
}
.col2 {
position: relative;
z-index: 1;
width: 200px;
height: auto;
padding: 5px;
background-color: gray;
}
.col2::before {
content: "";
position: absolute;
bottom: -20px;
left: -60px;
width: 150px;
min-height: 100px;
height: 100%;
z-index: -1;
background-color: seagreen;
}
.image {
position: relative;
z-index: 2;
width: 200px;
height: 150px;
}
<div class="item">
<div class="col1">
<img class="image" src="http://satyr.io/200x150/1" />
</div>
<div class="col2">
<p class="title">Lorem ipsum dolor</p>
<p class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima esse ipsam error repudiandae ut amet.</p>
</div>
</div>
Remove z-index: 1 from class .col2. So, the green block will appear under the image as well as the text box.
You could place an element inside <div class="col2"> because the pseudo element cannot have a lower z-index that the element itself. And then place an div inside of <div class="col2"> which you could apply the z-index and the gray background on.
I have a difference of box sizing interpretation between webkit and Firefox using height 100% on a parent.
HTML:
<header>
Lorem ipsum dolor amet
</header>
<div class="wrapper">
<div class="content">
My background depends on my ancestor sibling
</div>
</div>
<div class="red">
<p class="white">
Amet ipsum dolor
</p>
</div>
CSS:
header {
height: 150px;
background: #fff;
}
.red {
background: red;
padding: 6em 0;
}
.content {
background: rgba(28,28,28, .3);
margin-bottom: -100%;
}
.wrapper {
position: relative;
height: 100%;
}
p.white {
background: #fff;
width: 70%;
margin: 0 auto;
}
JS fiddle here https://jsfiddle.net/m1fobvwv/
Result on Chrome (expected):
Wrong result on FF:
A colleague of mine found a workaround:
Add position: absolute; width: 100%; to .content
Updated fiddle https://jsfiddle.net/m1fobvwv/3/
I have two columns, in the left column I have made the .title extend the full width of the screen using negative margins.
On the right column I have .sidebar I would like this to appear below the extented .title div. Run the code snippet below and you'll see it starts on the same line. In other words I want the orange div to fall below the yellow div.
I don't want to use margin-top on the .sidebar because the height of .title in the left column varies.
I realise this is possible with javascript but I'm looking for a more robust solution just using html and css, is this possible?
I also created a fiddle if that's more convenient http://jsfiddle.net/2dLaw17r/1/
.container {
width:600px;
margin:0 auto;
clear:both;
padding:1em;
background:grey;
}
.left {
float:left;
width:60%;
}
.left .title {
margin:0 -500%;
padding:0 500%;
background: yellow;
}
.right{
float:right;
width:40%;
background:orange;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<div class="container clearfix">
<div class="left">
<article>
<div class="title">Title extends beyond container</div>
<p>lorem ipsum someip orlem lorem ipsum someip orlem lorem ipsum someip orlem</p>
<article>
</div>
<div class="right">
<div class="sidebar">items in this sidebar div should fall below the title div. Currently it starts on the same line.</div>
</div>
</div>
Place a div inside the article that contains the article content. This way the title and content both remain inside the article. Next, float the article content left and the sidebar towards the right. The negative margin trick is no longer required:
.container {
width: 600px;
margin: 0 auto;
clear: both;
padding: 1em;
background: grey;
}
.title {
background: yellow;
/* eye candy only */
margin: 0 -1em;
padding: 0 1em;
}
.left {
float: left;
width: 60%;
}
.right {
float: right;
width: 40%;
background: orange;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<div class="container clearfix">
<article>
<div class="title">Title extends beyond container<br>And can grow in height</div>
<div class="content left">
<p>lorem ipsum someip orlem lorem ipsum someip orlem lorem ipsum someip orlem</p>
</div>
</article>
<div class="sidebar right">
<p>items in this sidebar div should fall below the title div. Currently it starts on the same line.</p>
</div>
</div>
Issue is with your design and not CSS...if you plan your layout carefully you can avoid those negative margins altogether.Possible solution is suggested from my side is as below :
Redesign your markup and rename classes in more helpful manner :
working fiddle with updated markup
HTML
<div class="container clearfix">
<div class="left">
<div class="title">Title extends beyond container</div>
<div class="right">
<div class="sidebar">items in this sidebar div should fall below the title div. Currently it starts on the same line.</div>
</div>
<p>lorem ipsum someip orlem lorem ipsum someip orlem lorem ipsum someip orlem</p>
</div>
</div>
CSS
html, body { /* always mention this in you CSS - rule of Thumb for CSS */
width:100%;
height:100%;
margin:0;
padding:0
}
.container {
width:100%; /* stretch div to take full width of parent - HTML, BODY*/
margin:0 auto;
clear:both;
padding:1em;
background:grey;
}
.left {
/* float:left;*/ /* not needed with updated layout :) */
width:100%;
}
.left .title {
/*margin:0 -500%;
padding:0 500%; /* nightmare is removed */ */
width:100%;
background: yellow;
}
.right {
float:right;
width:40%;
background:orange;
}
.clearfix:after {
content:"";
display: table;
clear: both;
}
Like Antoine says, you have to put the title, outside the left div.
.container {
width:600px;
margin:0 auto;
clear:both;
padding:1em;
background:grey;
}
.left {
float:left;
width:60%;
}
.title {
background: yellow;
}
.right{
float:right;
width:40%;
background:orange;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<div class="container clearfix">
<div class="title">Title extends beyond container</div>
<div class="left">
<p>lorem ipsum someip orlem lorem ipsum someip orlem lorem ipsum someip orlem</p>
</div>
<div class="right">
<div class="sidebar">items in this sidebar div should fall below the title div. Currently it starts on the same line.</div>
</div>
</div>
You have to clear floats like:
.container {
width:600px;
margin:0 auto;
clear:both;
padding:1em;
background:grey;
}
.left {
float:left;
width:60%;
}
.left .title {
margin:0 -500%;
padding:0 500%;
background: yellow;
}
.right{
float:right;
width:40%;
background:orange;
clear: left;/*add clear left*/
margin-top: -60px;/*add negative top margin*/
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<div class="container clearfix">
<div class="left">
<div class="title">Title extends beyond container</div>
<p>lorem ipsum someip orlem lorem ipsum someip orlem lorem ipsum someip orlem</p>
</div>
<div class="right">
<div class="sidebar">items in this sidebar div should fall below the title div. Currently it starts on the same line.</div>
</div>
</div>
i got a tricky situation here. im trying to center 3 divs inside my footer and they need to have dynamic width, like min-width.
[cotainer [first] [second] [third] /container]
my setup is this
<footer>
<div id="container">
<div id="first"></div>
<div id="second"></div>
<div id="third"></div>
</div>
</footer>
footer #container { width: 800px; margin: 0 auto; }
#container #first,#container #second,#container #third
{
float: left;
min-width: 200px;
height: 25px;
background: /* image url */
padding: 4px;
margin: 0 20px 0 0;
}
#container #third { margin-right: 0; }
You should use display: table; and table-cell.
#container {
display:table;
}
#first, #second, #third {
display: table-cell;
width: 200px;
height: 40px;
border: 1px dashed #000;
}
Demo available here.
set container to display as:table and set it's margin to 0 auto.
#container {
display:table;
margn:0 auto;
whitespace: nowrap;
}
#first, #second, #third {
min-width: 200px;
float:left
...
}
Demo: http://jsfiddle.net/AZ4yT/1/
Edit: It gets left aligned in IE. so you might wanna use a workaround for that
What about using display: inline-block? You can see a jsFiddle of it here:
http://jsfiddle.net/S7bKT/1/
HTML
<div id="container">
<div id="first">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aliquam scelerisque euismod auctor. Sed pulvinar nulla eu
lorem iaculis ultrices. Mauris
</div>
<div id="second">Lorem ipsum dolor sit amet</div>
<div id="third">Sed pulvinar nulla eu lorem iaculis ultrices</div>
</div>
CSS
#container {
width: 500px;
background: #dedede;
margin: 0 auto;
text-align: center;
}
#first, #second, #third {
display: inline-block;
min-width: 50px;
max-width: 120px;
min-height: 100px;
zoom: 1; /* Fix for IE */
_display: inline; /* Hack for IE */
margin-right: 20px;
vertical-align: top;
}
#first {
background: #f00;
}
#second {
background: #0f0;
}
#third {
background: #00f;
}
#container div:last-child {
margin-right: 0;
}