I have an image like the b
Im trying to achieve an infinite line at the bottom so no matter what screen the line fills the width of the screen.
I have cropped my image and set it to the bottom of a div so i can use a boarder but when i use
.row2{
position: absolute;
width:500%;
overflow: hidden;
}
The div just seems to stretch 510% to the right rather than 250 to the left and 250 to the right and keeping my image the same size (it also moves my image to the center of the div so way off screen)
This is my html :
<div class="row row2">
<div class="col-xl-12 hscentertext" style="">
<img src="assets/img/25k.png" class="img-fluid center-block text-xl-center" alt="Responsive image">
</div>
</div>
I'm using bootstrap. Thanks in advance.
There's no need to use position: absolute; for this:
html, body {
background: red;
margin: 0;
padding: 0;
}
.row2 {
width: 100%;
border-bottom: 1px solid white;
}
.row2 .hscentertext {
text-align: center;
}
<div class="row row2">
<div class="col-xl-12 hscentertext" style="">
<img src="http://placehold.it/200x200" class="img-fluid center-block text-xl-center" alt="Responsive image">
</div>
</div>
Unless you have other reasons to use position: absolute; in which case can center it with transforms:
.selector {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
By using the translateX(-50%); trick the element will always be centered, regardless of it's width.
Since you did not provide the image, i remade one : cutting off edges for the snippet below:
.myimg {
background-color: #D52226;
/* draw the line behind*/
background-image: linear-gradient(to top, transparent 3px, white 3px, white 5px, transparent 5px);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row row2">
<div class="col-xl-12 hscentertext myimg" style="">
<img src="https://i.stack.imgur.com/Bf9Cy.jpg" class="img-fluid center-block text-xl-center" alt="Responsive image">
</div>
</div>
The width of that image used can be reduced to the text it holds.
The line can be drawn on the background of the container .
It can be a gradient or few pixel dot repeated over a background-color.
display:flex can help too to work from a translucide png, which allows background to be modify: example.
.myimg {
display: flex;
background-color: #D52226;
}
.myimg:before,
.myimg:after {
content: '';
flex: 1;
background: linear-gradient(to top, transparent 3px, white 3px, white 5px, transparent 5px);
}
.myimg:hover {
background-color: #4195BE
}
<div class="row row2">
<div class="col-xl-12 hscentertext myimg">
<img src="https://i.stack.imgur.com/37doI.png" class="img-fluid center-block text-xl-center" alt="Responsive image">
</div>
</div>
Related
I am trying to position a small image in the center of a bibber one. Both images are inside a Bootstrap Column.
<div className="row justify-content-center my-5 ">
<div className="col-xs-10 col-sm-6 my-auto mx-auto">
<Fade left duration={1000} delay={1000} fraction={0.1} >
<div className="father">
<img height="110%" width="100%" className="img-fluid biggerImg" src="/img/edificios.jpg" alt="edificios"/>
<img src="/img/logo02.png" alt="logo" className="logo"/>
</div>
</Fade>
</div>
And this is the css.
.padreImagenes{
/* background-image: url("../../assets/img/edificios.jpg"); */
text-align: center;
}
.biggerImg{
position: relative;
opacity: 0.8;
}
.logo{
position: absolute;
/* position: absolute;
transform: translate(-200%, 70%); */
/* position: absolute;
top: 60px;
left: 80px; */
}
As you can see in commented CSS code, I have tried setting the smaller image as absolute, and playing around with top, left, even transform/translate. The problem is that, when the site adapts to user screen size, It does not remain centered.
Combining both images with photoshop is not an option, since I want to apply an effect to the "smaller image".
Thanks,
try:
.logo {
position: absolute;
top:50%;
left:50%;
transform:translateX(-50%) translateY(-50%);
}
div {position:relative; display:inline-block;}
img {display:block;}
.logo {
position: absolute;
top:50%;
left:50%;
transform:translateX(-50%) translateY(-50%);
}
<div>
<img src="https://www.kurzweilai.net/images/Naam-Limits-of-Earth-Part1-001-earth-600x600.jpg" alt="">
<img src="https://blogs.salleurl.edu/sites/default/files/blogs/emprendedores/chrome_hacked_Pwnium-300x300.jpg" alt="" class="logo">
</div>
You can set the images container to display: flex and use the flex attributes to center the elements.
However, I haven't tested it with bootstrap, so there might be some styles conflicts.
.father {
display: flex;
align-items: center;
justify-content: center;
}
.logo {
position: absolute;
}
<div class="row justify-content-center my-5 ">
<div class="col-xs-10 col-sm-6 my-auto mx-auto">
<div class="father">
<img height="110%" width="100%" class="img-fluid biggerImg" src="https://picsum.photos/200/150
" alt="edificios"/>
<img src="https://picsum.photos/100/100
" alt="logo" class="logo"/>
</div>
</div>
I have a container div with multiple varying-width, uniform-height images. The images are horizontally arranged with no gaps between them.
What I have so far:
#imageContainer {
width: 80%;
border: 1px solid blue;
position: relative;
left: 50%;
transform: translateX(-50%);
}
#images {
display: flex;
width: 80%;
position: relative !important;
margin: 2px;
}
#imageContainer img {
display: inline-block;
position: relative;
margin: 1px;
}
<div id="imageContainer">
<div id="images">
<img src="https://dummyimage.com/400x100/000/fff" alt="">
<img src="https://dummyimage.com/320x100/000/fff" alt="">
<img src="https://dummyimage.com/420x100/000/fff" alt="">
<img src="https://dummyimage.com/540x100/000/fff" alt="">
</div>
</div>
I would like for all of the images to scale to fit within my div, filling it, but I can't seem to find where I can do this with multiple images.
I question is basically this one but with a twist of also scaling to fit.
Unless you want a gap in your box you should remove width/position from the inner #images container. To make the images scale down you can add a min-width. If you want the images to not distort add an object-fit:
#imageContainer {
width: 80%;
border: 1px solid blue;
position: relative;
left: 50%;
transform: translateX(-50%);
}
#images {
display: flex;
margin: 2px;
}
#imageContainer img {
display: inline-block;
position: relative;
margin: 1px;
/* Important bits: */
min-width: 0;
object-fit: contain;
}
<div id="imageContainer">
<div id="images">
<img src="https://dummyimage.com/400x100/000/fff" alt="">
<img src="https://dummyimage.com/320x100/000/fff" alt="">
<img src="https://dummyimage.com/420x100/000/fff" alt="">
<img src="https://dummyimage.com/540x100/000/fff" alt="">
</div>
</div>
(Btw, centering using left + transform can cause blurriness in some rendering engines.)
I prefer using Bootstrap for most of my front-end styling as they provide lots of nifty "features" that make it easy for me to create a nice looking front-end without having to spend hours with CSS trying to get it looking perfect or making it scalable to multiple viewports.
Hence, here is how I would solve it using Bootstrap-4. (Here is a Codepen link)
<div class="container">
<div class="row outline-primary">
<div class="col">
<img src="https://dummyimage.com/400x100/000/fff" class="img-fluid h-100">
</div>
<div class="col">
<img src="https://dummyimage.com/320x100/000/fff" class="img-fluid h-100">
</div>
<div class="col">
<img src="https://dummyimage.com/420x100/000/fff" class="img-fluid h-100">
</div>
<div class="col">
<img src="https://dummyimage.com/540x100/000/fff" class="img-fluid h-100">
</div>
</div>
</div>
I want to have a blurry background image for a div container. But if I set the blur filter the edges also will get blurry causing the blurred image to overflow it's frame. This is what I tried till now:
.one {
height: 400px;
width: 400px;
border: 1px solid black;
/* background-image: url("https://i.imgur.com/JCyxUxA.jpg"); */
/* background-repeat: no-repeat;
background-position: center;
background-size: contain;
*/}
.a {
background-image: url("https://i.imgur.com/JCyxUxA.jpg");
}
.b {
background-image: url("https://i.imgur.com/O1jVhYH.jpg");
}
.thing {
object-fit: contain;
width: 100%;
height: 100%;
}
.bl {
filter: blur(20px);
}
<div class="one t">
<img class="thing" src="https://i.imgur.com/JCyxUxA.jpg" alt="">
</div>
<div class="one t">
<img class="thing bl" src="https://i.imgur.com/JCyxUxA.jpg" alt="">
</div>
<!-- <div class="one a">
</div>
<div class="one b">
</div>
-->
Try adding overflow:hidden; to its container (class one in your case).
This will hide every part of the children elements that is overflowing its container
I have a square div with a known size.
I want to show an image with an unknown size in it.
I want:
. to use the maximum space in the div to show the image while keeping the size ratio of the image.
. the image to be centered, either horizontally if the image is taller than wider, or vertically if the image is wider than taller.
. I don't want the image to be cropped
. I don't want the image to be stretched and use the whole div
. The image should keep its ratio
I'm fine with either an html img tag or a CSS background image property
I found a solution thanks to #CBroe and his suggestion to use background-size
.container {
width: 100px;
height: 100px;
border: 1px solid black;
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
.container1 {
background-image: url('http://placehold.it/30x50');
}
.container2 {
background-image: url('http://placehold.it/50x30');
}
.container3 {
background-image: url('http://placehold.it/500x300');
}
.container4 {
background-image: url('http://placehold.it/300x500');
}
<div class="container container1">
</div>
<div class="container container2">
</div>
<div class="container container3">
</div>
<div class="container container4">
</div>
.container {
width: 100px;
height: 100px;
border: 1px solid black;
position: relative;
}
img {
max-width: 100px;
max-height: 100px;
position: absolute;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="container">
<img src="http://placehold.it/30x50" />
</div>
<div class="container">
<img src="http://placehold.it/50x30" />
</div>
<div class="container">
<img src="http://placehold.it/500x300" />
</div>
<div class="container">
<img src="http://placehold.it/300x500" />
</div>
I'm making a layout for a group of text and images using Foundation. I've exported pngs from photoshop. Visually in photoshop the image look like they will be contained nicely in square boxes within a layout of divs. However when I put them in that layout one of the images appears larger than the others visually. Is Photoshop saving these images at their original size, not what the designer has resized them to on the layout? What is the best practice to get the images to look visually the same size on the page?
Do I re-size and re-save the image trying and repeating until it looks right in the layout? I have about four images. Should I give them all a separate class and assign a unique width so that they appear correctly on the screen? Doing that makes the images sometimes appear fuzzy? I'm not sure if I will encounter this when re-size/re-saving them in photoshop. Please let me know if this question is better suited for graphicdesign.stackexchange. It sort of straddles the two sites in my opinion
structure:
div class="media-object"
div class="media-object-section middle
img
div class="media-object"
div class="media-object-section middle
img
div class="media-object"
div class="media-object-section middle
img
div class="media-object"
div class="media-object-section middle
img
May I suggest you use background-image and background-size: cover. That will ensure that no matter the image is wider or higher, it will always fill the div, all rendered in the same visual size, with its aspect ratio kept.
This can be done with the img element too, though as its browser support is less good, I chose not to.
html, body {
margin: 0;
width: 100vw;
}
.media-object {
display: flex;
flex-wrap: wrap;
}
.media-object-section {
width: calc(25vw - 4px); /* 4px equal margin on each side */
height: calc(25vw - 4px);
margin: 2px;
background-size: cover;
background-position: center;
}
.media-object-section.img1 {
background-image: url('http://lorempixel.com/200/200/animals/1');
}
.media-object-section.img2 {
background-image: url('http://lorempixel.com/300/200/animals/2');
}
.media-object-section.img3 {
background-image: url('http://lorempixel.com/200/300/animals/3');
}
.media-object-section.img4 {
background-image: url('http://lorempixel.com/400/400/animals/4');
}
<div class="media-object">
<div class="media-object-section middle img1">
</div>
<div class="media-object-section middle img2">
</div>
<div class="media-object-section middle img3">
</div>
<div class="media-object-section middle img4">
</div>
<div class="media-object-section middle img2">
</div>
<div class="media-object-section middle img3">
</div>
<div class="media-object-section middle img4">
</div>
<div class="media-object-section middle img1">
</div>
</div>
Update based on comment
Here is a none flex solution
html, body {
margin: 0;
width: 100vw;
}
.media-object-section {
display: inline-block;
width: calc(25vw - 4px); /* 4px margin on eachside */
height: calc(25vw - 4px);
margin: 2px -2px -2px 2px; /* -2px to compensate for white-space */
background-size: cover;
background-position: center;
}
.media-object-section.img1 {
background-image: url('http://lorempixel.com/200/200/animals/1');
}
.media-object-section.img2 {
background-image: url('http://lorempixel.com/300/200/animals/2');
}
.media-object-section.img3 {
background-image: url('http://lorempixel.com/200/300/animals/3');
}
.media-object-section.img4 {
background-image: url('http://lorempixel.com/400/400/animals/4');
}
<div class="media-object">
<div class="media-object-section middle img1">
</div>
<div class="media-object-section middle img2">
</div>
<div class="media-object-section middle img3">
</div>
<div class="media-object-section middle img4">
</div>
<div class="media-object-section middle img2">
</div>
<div class="media-object-section middle img3">
</div>
<div class="media-object-section middle img4">
</div>
<div class="media-object-section middle img1">
</div>
</div>
Note: The -2px to compensate for white-space can be solved other ways. Check this post for more info