Make an image come out of a div with background-image - html

I need some help, I need to code this image:
This is what I have so far:
I tried adding a margin-top, padding-top, tried all combinations of position relative and absolute, I just need some ideias on how to do it.
This is how my code is structured:
<div class="background-oficina">
<div class="container">
<div class="col-xs-12 text-center">
<img class="logo" src="logo.png" alt="Oficina de Redação">
</div>
</div>
</div>
This is the css for the two classes that I'm using:
.background-oficina {
background: #fff url("bg-texture.png");
}
.logo {
padding-top: 50px;
margin: 0 auto;
}

You could use an additional absolutely positioned element to which you assign the repeated background pattern and which you put behind the original element by using z-index: -1:
html, body {
margin: 0;
}
.background-oficina {
position: relative;
border: 1px solid #333;
border-bottom: none;
}
.bg-container {
position: absolute;
z-index: -1;
left: 0;
top;
width: 100%;
height: 120px; /* or whatever height is desired */
background: url("http://placehold.it/20x15/cff");
}
.text-center {
text-align: center;
}
.logo {
padding-top: 50px;
margin: 0 auto;
}
<div class="background-oficina">
<div class="bg-container"></div>
<div class="container">
<div class="col-xs-12 text-center">
<img class="logo" src="http://placehold.it/200x150/fb7" alt="Oficina de Redação">
</div>
</div>
</div>

Your trying this, you can set default height and width to parent div that consist of that logo then using position:absolute you can push that out of parent div, but don't add overflow:hidden to parent div or else it hides your image or element that you are trying to push outside parent div as hidden.
.background-oficina {
background: #fff url("https://via.placeholder.com/800x100/000") no-repeat;
box-shadow: inset 0 0 0 1000px rgba(255, 255, 255, 0.2);
background-size: 100% 100%;
width: 100%;
height: 100px;
position: relative; /*Add this*/
}
.logo {
padding-top: 50px;
margin: 0px auto;
position: absolute; /*Add this*/
bottom: -20px; /*Add this*/
}
<div class="background-oficina padding margin-bottom">
<div class="container">
<div class="col-xs-12 text-center margin-bottom">
<img class="logo" src="https://via.placeholder.com/50/ff2" alt="Oficina de Redação">
</div>
</div>
</div>

Related

Images exceeding size

I want to display images in my div. I display different images according to the condition (if moviePoster true).
I moviePoster I display it, but if it is false, I display a image that informed that the file is not found.
I don't know why but when I display these 2 types of image, the moviePoster image, exceeding the size of the dive.
This is a screen from the issue in my application
.list {
border: 1px solid grey;
display: flex;
margin: 30px;
height: 230px;
border-radius: 10px;
box-shadow: 1px 1px 12px #555;
}
.list-img {
// border: 5px solid red;
width: 20%;
}
img {
height: 100%;
width: 100%;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
<div class="list">
<div class="list-img">
<div *ngIf="moviePoster; else notFound">
<img src="https://image.tmdb.org/t/p/w200/{{moviePoster}}" alt="...">
</div>
<ng-template #notFound>
<img src="../../assets/not_found.jpg" alt="...">
</ng-template>
</div>
img is a default display: inline, so height and width refers to inner content.
Anyway set image width and height usually stretches image, and that's orrible.
I suggest on using a div with the image setted as background, so use something like that:
html:
...
<div
*ngif="..."
class="thumbnail"
style="background-image: url(https://...{{ moviePoster }})"
></div>
...
css:
.thumbnail{
background-size: cover;
background-position: center;
}
You should apply this class also to #notFound.
One thing missing: thumbnail div must have height and width expressed
You can do that in multiple ways via css, depending on how have you structured the card box.
Hope it helps.
i think this is what you want :
if the image is null then the default background will show.
UPDATE: i have made it more dynamic
.list {
display: flex;
flex-direction: column;
}
.list-item {
height: 150px;
overflow: hidden;
border-radius: 10px;
box-shadow: 0 0 3px 2px rgba(0,0,0,.5);
}
.list-item + .list-item {
margin-top: 10px;
}
.list-img {
width: 200px;
height: 150px;
transition: background .5s ease;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-image: url(https://www.tourismselangor.my/wp-content/themes/Directory/images/noimage.jpg);
}
<div class="list">
<div class="list-item">
<div class="list-img" style="background-image: url(https://picsum.photos/200)"></div>
</div>
<div class="list-item">
<div class="list-img"></div>
</div>
<div class="list-item">
<div class="list-img" style="background-image: url(https://picsum.photos/200)"></div>
</div>
</div>

How can you perfectly centre a grid within a container without using CSS Grid or flexbox?

Okay, so I thought that the grid was perfectly aligned to the center, only to realise that it was a few pixels out. I completely stripped all of my attempts at centering and looked online but couldn't find anything.
I know I can use CSS Grids, Flexbox etc. but I am trying to learn how to create websites without using any aid. So I can learn the reasoning behind things.
Fiddle:
https://jsfiddle.net/8L9ye7nj/5/
Grid HTML:
<div class="box-wrapper">
<div class="box-container">
<div class="box" id="stethoscope">
<div class="box-label">
<p>Book an appointment</p>
</div>
</div>
<div class="box" id="prescription">
<div class="box-label">
<p>Request a repeat prescription</p>
</div>
</div>
<div class="box" id="group">
<div class="box-label">
<p>Join the Patient Group</p>
</div>
</div>
</div>
</div>
Grid CSS:
.box {
float: left;
width: 25%;
height: 300px;
background-color: #252625;
color: #FFF;
position: relative;
padding: 15px;
margin: 0.5%;
}
.box-label {
position: absolute;
bottom: 0;
text-align: center;
background-color: rgba(0,0,0,0.5);
width: 100%;
padding: 7px 0;
left: 0;
}
.box-label:hover {
animation: box-stretch 1s forwards ease-in-out;
cursor: pointer;
}
.box-container {
width: 90%;
}
.box-container::after {
content: "";
clear: both;
display: table;
}
.box-wrapper {
background-color: #B21645;
padding: 30px;
}
How can you divide the box and center them?
You can use calc to use mathematical expressions to calculate height, widths etc in css. You can divide the width by three here for the box.
.box {
display: inline-block;
width: calc(100% / 3);
}
Things to consider
Mind the space between inline-block elements. You can read more about
that here.
Avoid using floats as much as possible. Most layouts done with float can be achieved with inline-block. Floats are simply meant to take an element, put it to one side, and let other content flow around it. That’s all.
box-wrapper and box-container either one is only needed to wrap the contents inside.
Code Snippet
body {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
.box-wrapper {
background-color: #b21645;
padding: 20px;
}
.box {
position: relative;
display: inline-block;
width: calc(100% / 3);
padding: 0 10px;
height: 300px;
overflow: hidden;
}
.box img {
height: 100%;
width: 100%;
object-fit: cover;
object-position: left top;
}
.box-label {
position: absolute;
bottom: 0;
width: calc(100% - 20px);
text-align: center;
background-color: rgba(0, 0, 0, .6);
padding: 10px 0;
transition: padding 0.3s;
}
.box-label:hover {
padding: 25px 0;
}
.box-label p {
font-family: Helvetica;
color: white;
font-size: 20px;
}
<div class="box-wrapper">
<div class="box">
<img src="https://images.unsplash.com/photo-1509027572446-af8401acfdc3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=ef8f839186c5a6055d2802005b575194&auto=format&fit=crop&w=500&q=60" alt="" />
<div class="box-label">
<p>Some Title Here</p>
</div>
</div><div class="box">
<img src="https://images.unsplash.com/photo-1509027572446-af8401acfdc3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=ef8f839186c5a6055d2802005b575194&auto=format&fit=crop&w=500&q=60" alt="">
<div class="box-label">
<p>Some Title Here</p>
</div>
</div><div class="box">
<img src="https://images.unsplash.com/photo-1509027572446-af8401acfdc3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=ef8f839186c5a6055d2802005b575194&auto=format&fit=crop&w=500&q=60" alt="">
<div class="box-label">
<p>Some Title Here</p>
</div>
</div>
</div>

How to make the gradient come on top of image and behind the text?

i have been trying to place the grandient on top of the image and behind the text but everything i tried from what i could find out in web didnt worked.
i would need to have the source of the image in the div cause if its in the css code it will apply the same image to all other templates i create.
thanks :)
<div class="titles">
<div class="thumb">
<img class="img overlay"
height=260px
width=240px
alt="Shokugeki no Souma: Ni no Sara"
src="https://img7.anidb.net/pics/anime/184719.jpg" />
<div class="titulo">Shokugeki no Souma: Ni no Sara</div>
<div class="epis">Epis. 12</div>
</div>
.titles .thumb {
position: relative;
float: left;
height: 260px;
width: 245px;
max-height: 260px;
max-width: 260px;
margin: 0 auto;
padding: 5px;
}
.thumb .titulo {
position: absolute;
bottom: 0;
left: 0;
padding: 8px;
margin: 5px;
font-size: 15px;
font-weight: bold;
color: white;
}
.thumb .epis {
position: absolute;
top: 0;
right: 0;
padding: 8px;
margin: 10px;
font-size: 15px;
font-weight: bold;
color: white;
}
.titles .thumb .img:hover {
max-height: 260px;
max-width: 260px;
height: 260px;
width: 240px;
opacity: 0.8;
}
.img.overlay {
background: linear-gradient(
to bottom,
black,
rgba(64,64,64,1),
rgba(64,64,64,1),
rgba(64,64,64,1),
rgba(64,64,64,1),
rgba(64,64,64,1),
rgba(64,64,64,1),
black);
}
Do you mind explaining a bit more about what is going wrong when you try to implement this?
My suggestion would be to put the overlay in its own separate div instead of inside the image tag. Then close the overlay div before you start your caption div. Then you can set your "thumb" class to have a certain width and height in your css, and style the overlay div to have height:100% width:100%so that it completely covers your thumbnail image. If you absolutely position the caption text, you can place it on top of the gradient. For example
<div class="titles">
<div class="thumb">
<img alt="Shokugeki no Souma: Ni no Sara" src="https://img7.anidb.net/pics/anime/184719.jpg" />
<div class="overlay"></div>
<div class="titulo">Shokugeki no Souma: Ni no Sara</div>
<div class="epis">Epis. 12</div>
</div>
</div>

Trying to align an image vertically but also float it left

I'm trying to create a vertically aligned image, but also have it float left with a 10px padding.
Here is what I have so far:
<div class="container">
<div class="header">
<div class="headliner"><strong>blaw</strong>
<br />blah</div>
<div class="header_eta"></div>
</div>
<div class="content">
<div class="dummy"></div>
<div class="img-container">
<img src="http://placehold.it/75x75" alt="" />
</div>
</div>
<div class="footers"></div>
</div>
You can also check out this fiddle.
I can't seem to get the img to float: left. It seems to be centered horizontally. Once the I get the image floated left, I need to float some text to the left side of the image.
UPDATE: Something like this https://cdn.shopify.com/s/files/1/0070/7032/files/UberRUSH_Tracking_Page-5_1.png?5766570299208136168
Add text-align:left into img-container with padding-left:10px;
Like this:
.img-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align:left; /* Align center inline elements */
font: 0/0 a;
padding-left:10px
}
try float:lefton the image, then add a div into img-container also floated left with a suitable margin
<div class="img-container">
<img src="http://placehold.it/75x75" alt="" style="float:left;"/>
<div style="float:left;margin-left:10px;">Your Content</div>
</div>
In order to achieve your desired result, you can use the following CSS code:
/* Positioning */
position: absolute;
top: 50%;
left: 0;
transform: translate(0, -50%);
Setting top: 50% and transform: translate(..., -50%) will center your element vertically.
Setting left: 0 and transform: translate(0, ...) will float your element horizontally to the left.
For optical reference you can check my code work in this fiddle.
<div class="container">
<div class="header">
<div class="headliner"><strong>blaw</strong>
<br />blah</div>
<div class="header_eta"></div>
</div>
<div class="content">
<div class="img-container-2">
<div class="img-cell">
<img src="http://placehold.it/75x75" alt="" />
</div>
</div>
</div>
<div class="footer"> </div>
</div>
<style type="text/css">
.content {height:300px; background-color:rgb(239, 65, 59);}
.header {height:60px; background-color:rgb(55, 102, 199);}
.img-container-2 {display:table; height:100%; width:100%; text-align:left;}
.img-cell {display:table-cell; vertical-align:middle;}
.headliner {padding:10px; height:50px;}
.footer {height:40px; background-color:rgb(66, 199, 123);}
</style>
img-container text align to left;
text-align: left;
here you code
.img-container {
position: absolute;
top: 10px;
bottom: 0;
left: 10px;
right: 0;
text-align: left;
/* Align center inline elements */
font: 0/0 a;
}
Once the I get the image floated left I need to float some text to the left side of the image.
So you will need to align two divs horrizontaly. For this you will need to use display: inline-block for both of them. By using this approach, you will need to put the image inside a div, and the text inside another div.
You could also make a table with the first td containing the text and the second td containing the image. Then float table to left.
Do you need like this,
Html code:
<div class="container">
<div class="header">
<div class="headliner"><strong>" blaw "</strong><br />" IS EN ROUTE "</div>
<div class="header_eta"></div>
</div>
<div class="content">
<div class="dummy"></div>
<div class="img-container">
<img src="http://placehold.it/75x75" alt="" />
</div>
</div>
<div class="footer">sdfsd</div>
</div>
css:
.content {
height: 100px;
position: relative;
width: 100%;
border: 1px solid black;
background-color: rgb(239, 65, 59);
}
.header {
height: 60px;
background-color: rgb(55, 102, 199);
}
.dummy {
padding-top: 100%; /* forces 1:1 aspect ratio */
}
.img-container {
position: absolute;
top: 10px;
bottom: 0;
left: 10px;
right: 0;
text-align: left;
}
.img-container:before {
content: ' ';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.img-container img {
vertical-align: middle;
display: inline-block;
}
.headliner {
padding:10px;
height:50px;
}
.footer {
height: 40px;
padding-bottom: 0px;
padding-left: 5px;
padding-top: 5px;
background-color: rgb(66, 199, 123);
text-align: left;
}
you can refer a link:https://jsfiddle.net/vpbu7vxu/5/

Force empty div with background image to cover height of container div

I have a row with two columns. I would like the column containing the .product-image empty div with background image (on the right) to have the same height as the column containing the .product-text div with text (on the left). The background image should cover the entire area of the right column.
I've created a codepen here: http://codepen.io/anon/pen/VemgQb
HTML:
<div class="container-fluid subpage-product">
<div class="row">
<div class="col-lg-6 col-md-6 col-xs-12 product-text">
<div class="product-icon">
<img src="https://s-media-cache-ak0.pinimg.com/736x/5a/dc/89/5adc89f4a0752dfec5c2f9ba625bfac5.jpg">
</div>
<h2>Meow Meow Meow</h2>
<p>Pelt around the house and up and down stairs chasing phantoms shove bum in owner's face like camera lens stare at ceiling.</p>
</div>
<div class="col-lg-6 col-md-6 col-xs-12 no-padding product-img" id="horse-racing-bg-img-01">
</div>
</div>
CSS (LESS):
#horse-racing-bg-img-01 {
background: url(http://i.imgur.com/C9xULnI.jpg) no-repeat;
background-size: cover;
}
.subpage-product .row {
overflow: hidden;
.product-text {
padding: 70px 100px;
text-align:center;
background-color: #000;
color: #fff;
}
.product-img {
height: 100%;
}
.product-icon {
height: 80px;
width: 80px;
display: block;
margin: 0 auto 0;
border-radius: 50%;
border: 1px solid white;
background-color: #fff;
img {
height: 50px;
width: 50px;
margin: 15px 15px 0 13px;
}
}
}