I have a div with 2 blocks:
One with informations
Another absolute on the bottom (with variant height)
Problem: I would like to center image on the middle of the div, excluding absolute block.
What I have
What I want
My actual code:
https://jsfiddle.net/ph4kfuy9/5/
.block {
height: 400px;
background-color: #EEE;
margin: 20px 50px;
position: relative;
}
.text {
padding: 20px;
background-color: #CCC;
width: auto;
text-align: center;
width: 50%;
margin: 0 auto;
}
.absolute {
padding: 20px;
background-color: #555;
color: #FFF;
position: absolute;
bottom: 0;
width: 100%;
box-sizing: border-box;
}
<div class="block">
<div class="text">
<p>My text</p>
<div>Lorem Ipsum</div>
<p>Another text</p>
</div>
<div class="absolute">
My absolute block
<p>
Quam ob rem cave Catoni anteponas ne istum quidem ipsum, quem Apollo, ut ais, sapientissimum iudicavit; huius enim facta, illius dicta laudantur. De me autem, ut iam cum utroque vestrum loquar, sic habetote.
</p>
</div>
</div>
Thank
I would use flex for this
.block {
height: 400px;
background-color: #EEE;
margin: 20px 50px;
display:flex; /* make this flex */
flex-direction:column; /* line up chld elements in a column */
}
.text {
padding: 20px;
background-color: #CCC;
width: auto;
width: 50%;
margin: 0 auto;
flex-grow:1; /* make this take up remaining space that footer doesn't */
display:flex; /* make this flex */
flex-direction:column; /* line up chld elements in a column */
justify-content:center; /* vertical centre */
align-items:center; /* horizontal centre */
}
.footer { /* no need to be absolute */
padding: 20px;
background-color: #555;
color: #FFF;
width: 100%;
box-sizing: border-box;
}
<div class="block">
<div class="text">
<p>My text</p>
<div>Lorem Ipsum</div>
<p>Another text</p>
</div>
<div class="footer">
My footer block
<p>
Quam ob rem cave Catoni anteponas ne istum quidem ipsum, quem Apollo, ut ais, sapientissimum iudicavit; huius enim facta, illius dicta laudantur. De me autem, ut iam cum utroque vestrum loquar, sic habetote.
</p>
</div>
</div>
Related
How do I make the pictures expand inside the class without being distorted and without edges or spaces between each other?
is there any other way to do this with Flexbox? there does not have to be a scrollbar and the .portof {class should not be too big in terms of height
How do I make the pictures expand inside the class without being distorted and without edges or spaces between each other?
is there any other way to do this with Flexbox? there does not have to be a scrollbar and the .portof {class should not be too big in terms of height
<pre>
<section class="Gallery">
<h1>Unsere Praxis</h1>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptatibus tempora accusantium provident ipsum placeat dolorem, dolores tempore optio, dignissimos eaque similique vel ea ullam nobis quas quae fugit laudantium sed!</p>
</section>
<!-- Portofolie -->
<section class="portof">
<div class="row">
<div class="wrapper">
<div class="container"> <img src="https://picsum.photos/350/250/?random=71" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=41" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=51" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=14" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=1" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=9" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=5" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=2" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=11" alt="?"></div>
<div class="container"> <img src="https://picsum.photos/350/250/?random=10" alt="?"></div>
</div>
<!-- <div class="gallery-row2">
sssdsd
</div>
--> </div>
</section>
</pre>
.Gallery{
width: 80%;
padding: 2% 0 0 0;
text-align: center;
margin: auto;
}
.Gallery h1{
font-size: 30px;
font-weight: 800;
color: #87CEEB;
}
.Gallery p{
padding-top: 10px;
font-family: 'Poppins', sans-serif;
font-weight: 30;
color: #000;
line-height: 30px;
font-size: 20px;
}
.portof{
width: 100%;
text-align: center;
background-color: royalblue;
background-image: url(img/slider_2.jpg);
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-color: rgba(0, 0, 0, 0.8);
background-blend-mode: multiply;
clip-path: polygon(51% 19%, 100% 13%, 100% 85%, 51% 94%, 0 85%, 0 13%);
}
.wrapper {
padding: 2% 0 0 0;
font-size: 0;
display: block;
}
.container {
display: inline-block;
width: 20%;
}
img {
display: inline-block;
max-width: 100%;
}
.container:hover{
background-color: rosybrown;
}
Just update CSS class .wrapper display property to be flex and give the container zero padding as following
.wrapper {
padding: 2% 0 0 0;
font-size: 0;
display: flex;
}
.container {
display: inline-block;
width: 20%;
padding: 0;
}
Mockup:
The parent div's height is dynamic; it shrinks to fit the left-hand div (the one containing the text). I'd like the right-hand div (white background, with child img) to stretch vertically to fill the parent div. Unfortunately, height: 100% only works when the parent div's height is statically determined.
Here's what I've got right now:
.container {
background-color: lightgray
}
.blurb {
display: inline-block;
padding: 2em;
}
.decoration {
float: right;
background-color: white;
position: relative;
left: -10px;
height: 100% // XXX does not work
}
<div class="container">
<div class="blurb">
Lorem ipsum...
</div>
<div class="decoration">
✓
</div>
</div>
Answers to similar questions recommend using display: table-cell;, but then you have the issue of making the first (text) div stretch horizontally all the way, which is a different can of worms entirely.
Flexbox can do that.
.container {
background-color: lightgray;
display: flex;
border: 1px solid red;
width: 80%;
margin: 1em auto;
}
.blurb {
flex: 1;
padding: 2em;
}
.decoration {
display: flex;
align-items: center;
background-color: white;
margin-right: 1em;
}
<div class="container">
<div class="blurb">
Lorem ipsum...
</div>
<div class="decoration">
✓
</div>
</div>
<div class="container">
<div class="blurb">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis molestiae accusantium, magni commodi repellendus quidem facilis doloremque perspiciatis, ab odio omnis deleniti, obcaecati maiores dolores?
</div>
<div class="decoration">
✓
</div>
</div>
You can achieve it with position property. The parent container set to relative and child decoration set to absolute with top and bottom set to 0.
.container {
background-color: lightgray;
position: relative;
}
.blurb {
display: inline-block;
padding: 2em;
}
.decoration {
float: right;
background-color: white;
position: absolute;
top: 0;
bottom: 0;
right: 10px;
/* Align the content to center */
display:flex;
justify-content:center;
align-items:center;
text-align: center;
}
<div class="container">
<div class="blurb">
Lorem ipsum...
</div>
<div class="decoration">
✓
</div>
</div>
I would like to give a DIV the width of the picture in its content.
Here is my HTML :
<div id="container">
<div id="picandtext">
<img src="https://placehold.it/480x320" />
<p>Eodem tempore etiam Hymetii praeclarae indolis viri negotium est actitatum, cuius hunc novimus esse textum. cum Africam pro consule regeret Carthaginiensibus victus inopia iam lassatis, ex horreis Romano populo destinatis frumentum dedit, pauloque postea cum provenisset segetum copia, integre sine ulla restituit mora.</p>
</div>
</div>
Here is my CSS :
#container { height: 600px; display:table; width:1%; background: red; padding:10px; }
#picandtext { height: 400px; display:table; width:1%; background: green; padding:10px; }
#picandtext img { height: 180px; }
#picandtext p { height: 180px; }
I finally found a way to do it with display:table; width:1%; as you can see with this JSFiddle example : https://jsfiddle.net/Ls750c64/2/
But I would like to know if this way is the best one to make it ?
Given your existing markup, you can make #container display: inline-block; and absolutely position the p with text.
#container {
height: 600px;
display: inline-block;
background: red;
padding: 10px;
}
#picandtext {
height: 400px;
background: green;
padding: 10px;
position: relative;
}
#picandtext img {
height: 180px;
}
#picandtext p {
position: absolute;
left: 10px;
right: 10px;
}
<div id="container">
<div id="picandtext">
<img src="https://placehold.it/480x320" />
<p>Eodem tempore etiam Hymetii praeclarae indolis viri negotium est actitatum, cuius hunc novimus esse textum. cum Africam pro consule regeret Carthaginiensibus victus inopia iam lassatis, ex horreis Romano populo destinatis frumentum dedit, pauloque postea cum provenisset segetum copia, integre sine ulla restituit mora.</p>
</div>
</div>
And a less supported way to do it would be using intrinsic sizing. The browser support for it sucks though. http://caniuse.com/#feat=intrinsic-width
#container {
height: 600px;
display: inline-block;
background: red;
padding: 10px;
width: min-content;
}
#picandtext {
height: 400px;
background: green;
padding: 10px;
position: relative;
}
#picandtext img {
height: 180px;
}
<div id="container">
<div id="picandtext">
<img src="https://placehold.it/480x320" />
<p>Eodem tempore etiam Hymetii praeclarae indolis viri negotium est actitatum, cuius hunc novimus esse textum. cum Africam pro consule regeret Carthaginiensibus victus inopia iam lassatis, ex horreis Romano populo destinatis frumentum dedit, pauloque postea cum provenisset segetum copia, integre sine ulla restituit mora.</p>
</div>
</div>
I have a block of code that is solid. Works fine. Except for the footer of my site. No idea why but the heading bars are not showing for the footer but they are everywhere else?
here is a pen of the working code
http://codepen.io/VincentStephens/pen/EjyJKP
Here is a screenshot of the not working site:
https://www.dropbox.com/s/y3oxrvzvdvyaai6/Screen%20Shot%202015-05-19%20at%2019.07.47.png?dl=0
This works by creating a :before element. Putting the menu text into a span, then using z-index to position the span on top of the :before.
You can see the element there (see photo), everything is the same but just won't show unless I change the z-index to 0 or higher but then the line is above the heading text in the span???
h1.heading {
color: $light-gold;
text-transform: uppercase;
font-size: 32px;
font-weight: 300;
line-height: 40px;
font-family: SourceSansPro;
span {
background-color: $golden-black;
display: inline-block;
z-index: 1;
padding-right: 10px;
}
}
h1.heading:before {
content: "";
background-color: $light-gold;
display: block;
position: relative;
top: 23px;
width: 100%;
height: 6px;
z-index: -1;
}
HTML - working
<h1 class="heading"><span>The Team</span></h1>
HTML - Footer, not working
<div class="fluid-container footer">
<footer class="container">
<div class="col-lg-4">
<h1 class="heading"><span>About</span></h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Bestiarum vero nullum iudicium puto. Quasi vero, inquit, perpetua oratio rhetorum solum, non etiam philosophorum sit. Quae sunt igitur communia vobis cum antiquis, iis sic utamur quasi concessis; De illis, cum volemus. Duo Reges: constructio interrete. Huic mori optimum esse propter desperationem sapientiae, illi propter spem vivere.</p>
</div>
<div class="col-lg-4">
<h1 class="heading"><span>Address</span></h1>
<p class="address">
address<br>
</p>
<p class="address">
Tell: 0207 374 6141 <br>
Email: enquiries#company.com
</p>
</div>
<div class="col-lg-4">
<h1 class="heading"><span>Connect</span></h1>
<img src="img/social-media.png" width="186" height="46">
<h1>Payment Options</h1>
<img src="img/payment-cards.png" width="267" height="56">
</div>
</footer>
</div>
Thanks for the moment on sanity.... it was indeed a position issue.
The footer also has a background colour. so that entire element needed to have a position: relative; and z-index: -1; added to it.
full code for anyone else in same situation:
SCSS - wil need compiling
.fluid-container.footer {
position: relative;
z-index: -1;
background-color: $light-golden-black;
footer {
h1.heading {
color: $light-gold;
text-transform: uppercase;
font-size: 32px;
font-weight: 300;
line-height: 40px;
font-family: SourceSansPro;
position: relative;
span {
background-color: $light-golden-black;
display: inline-block;
z-index: 1;
padding-right: 10px;
position: relative;
}
}
h1.heading:before {
content: "";
background-color: $light-gold;
display: block;
position: absolute;
top: 23px;
width: 100%;
height: 6px;
z-index: -1;
}
}
}
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;
}