Changing CSS height on image not working? - html

I cant change the height only the width works? I dont understand:)
.image-size{
width: 100%;
height: 50%;
}
<div class="container">
<div class="row">
<div class="page-header">
<div class="col-md-8">
<nav class="navbar navbar-default navbar">
<div class="navbar-header">
<a class="navbar-brand" href="#">Lexicon</a>
</div>
<ul class="nav navbar-nav">
<li>Java Fundamentals</li>
<li>Java Advanced</li>
<li>Front-End</li>
<li>Test and Management</li>
<li>Java Enterprise</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="jumbotron">
<div class="row">
<div class="col-md-12" align="center">
<img class="thumbnail image-size" src="https://academy.oracle.com/en/oa-assets/i/c82/c82-java-prog-logo.jpg" class="img-responsive image-size">
</div>
</div>
</div>
</div>
Im using bootstrap does i have anything to do with my problem? Why does the whole image change size when i just change the width.

it is because the Col that contain the img don't have height and you can't give % value to image because the parent don't have any height to get the 50% of that!
in other hand you can make it possible with "px";
.image-size{
width: 100%;
height: 250px;
}
Or add height for container Col

You should set specific height for parent of image (class=col-md-12)
For example:
.col-md-12{
height: 100px;
}
.image-size{
width: 100%;
height: 50%;
display: block;
}

Your should provide height to parent first before assigning to a child.
You haven't set the parents height . i.e. div's height so that it the will know what 50% means.
<div class="col-md-12" align="center" style='height:100px'>
<img class="thumbnail image-size" src="https://academy.oracle.com/en/oa-assets/i/c82/c82-java-prog-logo.jpg" class="img-responsive image-size">
</div>
I do not support inline styling.

we can set height pixel it will work
.image-size {
height:300px;
width :100%;
}
<div class="col-md-12" align="center">
<img class="thumbnail image-size" src="https://academy.oracle.com/en/oa-assets/i/c82/c82-java-prog-logo.jpg" class="img-responsive image-size">
</div>
And if you want to set the height with percentage you have to set position:absolute to the image like
.image-size {
height:50%;
width:100%;
position:absolute;
left:0;
top:0;
}
<div class="col-md-12" align="center">
<img class="thumbnail image-size" src="https://academy.oracle.com/en/oa-assets/i/c82/c82-java-prog-logo.jpg" class="img-responsive image-size">
</div>

you can use css style
.thumbnail, .image-size, src {
height: 50%;
width: 100%
}

Related

Applying an opacity filter over an image on html

I was trying to find this solution but I can only find solutions to apply filter on images as background-image on css.
I have a row with 3 images in equal size on my HTML.
The effect that I am trying to replicate is a "filter" on all of the photos that give a gradient opacity. This filter has a bottom completely dark and starts getting transparent until reaching the top. (a little bit like this: http://www.webdesignerwall.com/wp-content/uploads/2010/04/css-gradient-box.gif where the white top would be transparent)
How could I do that, considering that images are 100% responsive and changes for every time we change the size of the browser.
PS: The gradient code is not a problem, I can do that, the problem I can't find the solution is how to apply a "DIV" or something over each of those images that always follow the image size, no matter its height and width.
Here's my HTML:
<section class="home-page-gallery">
<div class="container-fluid">
<div class="row">
<!-- FIRST IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding yellow-bg">
<div class="gallery-item">
<img src="images/photo01.png" alt="">
</div>
</div>
<!-- SECOND IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding blue-bg">
<div class="gallery-item">
<img src="images/photo02.png" alt="">
</div>
</div>
<!-- THIRD IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding pink-bg">
<div class="gallery-item">
<img src="images/photo03.png" alt="">
</div>
</div>
</div><!-- ./ row -->
</div><!-- ./ container-fluid -->
</section>
and the CSS:
.gallery-item{
width:100%;
}
.gallery-item img{
width:100%;
height:auto;
}
I already tried to put another div wrapping each image, giving a position: relative and a z-index trying to make this div stay over the image, but it didn't work
Thank you so much!
Use pseudo-element like this:
.gallery-item {
width: 100%;
position:relative;
}
.gallery-item:after {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background:linear-gradient(to top,red 20%,transparent 80%);
}
.gallery-item img {
display:block;
width: 100%;
height: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<section class="home-page-gallery">
<div class="container-fluid">
<div class="row">
<!-- FIRST IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding yellow-bg">
<div class="gallery-item">
<img src="https://lorempixel.com/400/200/" alt="">
</div>
</div>
<!-- SECOND IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding blue-bg">
<div class="gallery-item">
<img src="https://lorempixel.com/400/200/" alt="">
</div>
</div>
<!-- THIRD IMAGE -->
<div class="col-xs-12 col-sm-4 no-padding pink-bg">
<div class="gallery-item">
<img src="https://lorempixel.com/400/200/" alt="">
</div>
</div>
</div>
<!-- ./ row -->
</div>
<!-- ./ container-fluid -->
</section>
you need a element that is a sibling to the image, inside the gallery-item wrapper.
you want to do something like this with your css:
.gallery-item{
width:100%;
position: relative;
}
.gallery-item img{
width:100%;
height:auto;
position: relative;
}
.overlay {
height: 100%;
width: 100%;
position: absolute;
opacity: 0.5;
z-index: 1;
background: linear-gradient(red, yellow);
}
position the outer container as relative, then position the gradient el as absolute. here is a fiddle:https://jsfiddle.net/y9o1paex/11/

image scale proportionally within specified column bootstrap 3

I'm trying to get image fit with bootstrap column in a row proportionally within specified height 300px, i have tried so many ways but unfortunately its not fit with column width (my 1st image dimension is 262*380 and 2nd image dimension 546*380 and im using img-responsive class)
I need my image should be like this Expected
but im getting like this Actual
My HTML
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="grid">
<img src="https://static5.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lunch-5502ae26.jpg" class="img-responsive" alt="">
</div>
</div>
<div class="col-md-8">
<div class="grid">
<img src="https://static7.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lounge-0cd3d802.jpg" class="img-responsive" alt="">
</div>
</div>
</div>
My CSS
.grid {
height: 300px;
border-right: 4px;
}
.grid img {
height: 100%;
}
Try this HTML:
<div class="container">
<div class="row">
<div class="col-md-4 bg-cover grid" style="background-image: url(https://static5.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lunch-5502ae26.jpg)">
</div>
<div class="col-md-8 bg-cover grid" style="background-image: url(https://static7.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lounge-0cd3d802.jpg)">
</div>
</div>
</div>
with this CSS:
.grid {
height: 300px;
}
.grid img {
height: 100%;
}
.bg-cover {
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
height: 300px
}

How to make image fit in container?

I'm trying to use Bootstrap grid system with rows each has 4 column contains image, but the image size is big and it gets over its container, so I set image position: absolute and div position: relative but it still doesn't work. Is there any way to make the image fit the div container with container's size?
.sec5row {
border: 1px solid red;
position: relative;
}
.filter {
position: absolute;
}
<div class="container">
<div class="row">
<div class="col-md-3 sec5row">
<img class="filter" src="https://placehold.it/40" alt="f1">
</div>
<div class="col-md-3 sec5row">
<img class="filter" src="https://placehold.it/40" alt="f1">
</div>
<div class="col-md-3 sec5row">
<img class="filter" src="https://placehold.it/40" alt="f1">
</div>
<div class="col-md-3 sec5row">
<img class="filter" src="https://placehold.it/40" alt="f1">
</div>
</div>
<div>
You can use the below code to fit image inside the responsive div
.filter {
width:100%;/*To occupy image full width of the container and also fit inside the container*/
max-width:100%/*To fit inside the container alone with natural size of the image ,Use either of these width or max-width based on your need*/
height:auto;
}
I think the bootstrap class ".img-responsive" solves your problem. So try something like this:
<div class="container">
<div class="row">
<div class="col-md-3">
<img class="img-responsive" src="resources/images/f1.jpg" alt="f1">
</div>
<div class="col-md-3">
<img class="img-responsive" src="resources/images/f2.jpg" alt="f1">
</div>
<div class="col-md-3">
<img class="img-responsive" src="resources/images/f3.jpg" alt="f1">
</div>
<div class="col-md-3">
<img class="img-responsive" src="resources/images/f4.jpg" alt="f1">
</div>
</div>
<div>
It sets the style of your image to "max-width: 100%;" and "height: auto;" which should be exactly what you need. There should be no need for any additional css.
Add css to your code
#img {
width: 100px;//change px size
height: 100px;//change px size
padding-left: 3px;
padding-top: 5px;
}
Just add class="img-responsive" to your img tag...it works fine

Two small align images beside a large image

I'm struggling on how I will code to create a two vertical images and is it possible to lessen the height of the larger image without lessen the width? because I need to fit it on col-md-8 any thoughts about this?
this is the image I need to make.
Click here
HTML and CSS code:
.img-big{ height: 100%;width: 100%; }
<div class="row col-md-8">
<img class="row img-big img-responsive" src="/assets/icons/people-crowd-child-kid-large.jpg"></div>
</div
the above code is what I've used to make the bigger image beside image 2 and 3. the dimension of the large image is 900x767
You can use the flexbox property to achieve what you want and set the image as background.
body, html {
margin: 0;
padding: 0;
color: white;
}
.container {
height: 767px;
display: flex;
}
.left {
background-image: url('http://i.imgur.com/AzeiaRY.jpg');
background-size: cover;
flex: 1;
}
.right {
display: flex;
flex-direction: column;
flex: 0 0 50%;
}
.one {
background-image: url('http://i.imgur.com/AzeiaRY.jpg');
background-size: cover;
flex: 50%;
}
.two {
background-image: url('http://i.imgur.com/AzeiaRY.jpg');
background-size: cover;
flex: 50%;
}
<div class="container">
<div class="left">Left image</div>
<div class="right">
<div class="one">First image</div>
<div class="two">Second image</div>
</div>
</div>
In Bootstrap 5, you can use d-grid gap-x. For example:
HTML
.content {
background-color: transparent;}
.content .left, .content .right {
float: left;}
.full-width-band-hd {
margin-top: -35px;}
.txt-yellow {
color: var(--bs-yellow);}
<section class="container-lg">
<div class="content row">
<h2 class="txt-yellow full-width-band-hd">Head</h2>
<!-- Left Side -->
<h6 class="text-yellow">H6 head</h6>
<h3 class="text-yellow">H3 head</h3>
</div>
<!-- style in content row will become a class later-->
<div class="content row" style="height: 642px;">
<div class="col-md-4 left d-grid gap-3">
<div class="">
<img src="image1" width="100%" height="auto" alt="fp1">
</div>
<div class="">
<img src="image2" width="100%" height="auto" alt="fp2">
</div>
</div>
<!-- End of Left Side -->
<div class="col-md-8 left">
<div class="">
<img src="image3" width="100%" height="auto" alt="fp3">
</div>
</div>
<!-- End of col-md-8 -->
</div><!-- content row -->
</section>
You should format your code like below:
<div class="row">
<div class="col-md-8">
<img class="img-big img-responsive" src="https://en.apkshki.com/storage/5/icon_5dcfce7f86906_5_w256.png"></div>
</div>
<div class="col-md-4">
<img src="https://en.apkshki.com/storage/5/icon_5dcfce7f86906_5_w256.png"></div>
<img src="https://en.apkshki.com/storage/5/icon_5dcfce7f86906_5_w256.png"></div>
</div>
</div>
As you can see the two images at the bottom in col-md-4 if you spread the width 100% the next image will drop below.
You shouldnt really have a class with both a row and a col-md in the class name. (See http://getbootstrap.com/css/)
With regards to reducing the height and not the width are you not able to crop the image down on Paint or Photoshop and upload the image with the correct height?

2 stacked containers to the right of an image

I'm trying to achieve the following layout for a search result box. Specifically a 100% width and height image that on the right has two stacked containers that equals the height of the image, each with differing background colours that are butted up right against the image.
All attempts to achieve this simple layout are failing miserably. The issue I keep hitting is the when using something like:
<div class="search-result-box">
<div class="row">
<div class="col-md-3">
<img src="" class="img-responsive" style="height: 196px;" height="196">
</div>
<div class="col-md-9">
...
</div>
</div>
</div>
The image doesn't quite fill the col-md-3 column completely and thus you see the column's background.
What's the best way to do this?
Bootstrap columns have a padding of 15px by default. Also the image width has to be 100%. You can do something like this:
<div class="search-result-box">
<div class="row">
<div class="col-md-3" style="padding: 0;">
<img src="" class="img-responsive" style="width: 100%;">
</div>
<div class="col-md-9">
...
</div>
</div>
</div>
Jsfiddle: http://jsfiddle.net/HM4gE/1/
I wouldn't use Bootstrap columns though to achieve this since you seem to have some fixed heights and widths for columns. Instead I would do it like this (given that the height and the width of the image is always 196px): http://jsfiddle.net/HM4gE/2/
Check browser support for calc() before using it: http://caniuse.com/calc
Here a possible answer:
<div class="search-result-box">
<div class="row">
<div class="col-md-3">
<img src="" class="img-responsive" style="height: 196px;" height="196" />
</div>
<div class="col-md-9">
<div class="title">Title</div>
<div>Link1</div>
</div>
</div>
</div>
.search-result-box {
display: table;
width: 100%;
}
.row {
display: table-row;
}
.row > * {
display: table-cell;
}
.col-md-3 {
background: orange;
width: 260px;
height: 196px;
}
.col-md-9 {
vertical-align:top;
background: grey;
}
.title {
background: #ccc;
width: 100%;
height: 150px;
}
http://jsfiddle.net/junkie/fAPQ6/2/