Total newbie here, tried to google my issue, even get on the second page of results... I'm stuck on resizing image and I have no idea why it is not working, hoping someone can help. By using Inspect on Chrome I can see that element for img is not being connected to the img and I have no idea why.
Block below is within <main>
<article>
<section class="article-content">
<img src="./assets/images/page_screenshot.png" alt=""/>
</section>
</article>
Here is CSS that I have for the whole part.
main {
display: inline-block;
background-color: var(--main-bgc);
padding-top: 5%;
}
article {
display: flex;
margin-bottom: 3%;
width: 100%;
}
.article-title {
display: inline-block;
width: 9%;
margin-right: 1%;
color: var(--font-colot-slate);
border-right: 1px solid var(--font-color-white);
}
.article-title h2 {
float: right;
margin-right: 10px;
}
.article-content {
display: inline-block;
width: 90%;
float: right;
color: var(--font-color-white);
}
.article-content img {
width: 100px;
height: 100px;
}
I tried adding height and width in tag and works fine, but not very happy with that solution.
The code you've given us works fine, as you can see in this snippet (run it to see the result). So if your image is not being properly resized, it must be because of some other part of your code, which you haven't included.
If you want the image to retain its original aspect ratio, you can add object-fit: cover; which will crop the image rather than squash it.
article {
display: flex;
margin-bottom: 3%;
width: 100%;
}
.article-content {
display: inline-block;
width: 90%;
float: right;
color: var(--font-color-white);
}
.article-content img {
width: 100px;
height: 100px;
object-fit: cover;
}
<article>
<section class="article-content">
<img src="https://shotkit.com/wp-content/uploads/2020/08/night-landscape-photography-featured.jpg">
</section>
</article>
Related
I know there are a LOT of examples of this, and I have tried all of them to no avail. I am trying to create a carousel component that resizes images according to its boundary. I am using it in a myriad of places, in a myriad of different ways, so it MUST be responsive. I also need the images to be clickable as normal images for a11y and customers (managing expectations).
Here is my fiddle so far: https://codepen.io/skamansam/pen/NWvroeY?editors=1100
I can get all of the elements to resize accordingly (using max-width/height). when I use an image that is wider than taller, all works well. When I use an image that is taller than wider and exceeds the height of the box, the image overflows instead of respecting the max-width/height properties.
The most common answer involves wrapping the image in an html element and setting the width/height there, which I have done, but it doesn't solve the problem. Another common answer involves using combinations of position values, which didn't give any better results than I already have. Using the inspector, you can clearly see that all the elements EXCEPT the image are correctly sized, and the image overflows the container.
Is there any other way to get the img tag to respect height: 100% in the same way it respects width: 100%?
you are using image with a very high resolution (500x800) , you have use little lower resolution otherwise you have to use overflow:hidden; on your wrapping div.Using max-width:100%; the image is already resizing itself but cannot resize further more, inspect the element to get a better understanding.
I made three changes:
Your slide needs width: auto; and height: 100%;
Your image needs width: 100%; and height: 100%;
Your image needs object-fit: contain; (not cover)
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.jumbotron {
display: block;
width: 100%;
margin: 0;
padding: 0;
background-color: #aaa;
/* overflow: hidden; */
height: 150px;
}
.jumbotron .container {
width: 100%;
height: 100%;
}
.my-carousel {
background-color: #77f;
max-height: 100%;
max-width: 100%;
height: 100%;
width: 100%;
display: flex;
flex-direction: row;
// overflow: hidden;
}
.my-carousel .previous-btn, .my-carousel .next-btn {
font-size: 200%;
padding: 0px 10px;
display: flex;
flex-direction: column;
justify-content: center;
}
.my-carousel .content {
max-height: 100%;
max-width: 100%;
align-self: center;
flex-grow: 1;
position: relative;
width: 100%;
height: 100%;
}
.my-carousel .content .slide {
height: 100%;
//max-width: 100%;
display: none;
position: relative;
// width: 100%;
vertical-align: middle;
padding: 0px;
margin: 0px;
overflow: visible;
}
.my-carousel .content .slide.active {
display: block;
}
.my-carousel .content .slide img {
//position: relative;
// margin: 0px auto;
// box-sizing: border-box;
// vertical-align: middle;
height: 100%;
width: 100%;
// max-width: 100%;
// max-height: 100%;
object-fit: contain;
object-position: center;
overflow: hidden;
}
.my-carousel .content .slide .caption {
position: absolute;
background-color: rgba(0,0,0,.4);
text-shadow: 2px 2px 4px #fff, -2px -2px 4px #fff;
stroke: 2px #fff;
padding: 10px;
bottom: 0px;
width: 100%;
font-size: 150%;
// color: #000;
// -webkit-text-stroke-width: 1px;
// -webkit-text-stroke-color: #fff;
}
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#6.3.95/css/materialdesignicons.min.css" rel="stylesheet"/>
<main role="main">
<section class="jumbotron text-center">
<div class="container">
<div class="my-carousel">
<div class="previous-btn">
<span class="mdi mdi-transfer-left"></span>
</div>
<div class="content">
<div class="slide active">
<img src="https://picsum.photos/500/800?random=1" />
<div class="caption">This is only a WIP to figure out how to style this carousel properly.</div>
</div>
<div class="slide">
<img src="https://picsum.photos/1000/400?random=1" />
</div>
</div>
<div class="next-btn">
<span class="mdi mdi-transfer-right" />
</div>
</div>
</div>
</section>
</main>
luckily, the answer is inside "picksum" itself, it allows you to choose the resolution of the image you want, you chose (500x800) that is way too large, you can use the following reduced resolutions >(50x80), (100x160), (180x288), (190x304), (200x320). I am sure you will get your desired result by using (180x288) or (190x304)
for example:<img src="https://picsum.photos/190/304?random=1" />
Use max-width and max-height
Like this
.slide {
width: 100px;
height: 100px;
max-width: 100%;
max-height: 100%;
overflow: hidden;
}
.slide .img {
max-width: 100%;
max-height: 100%;
}
I have a header as follow: logo + nav containing 4 links
I would like to arrange all this element next to each other at the top (that is working), but also to make them at equal distance of each other. The second part does not work, I don't manage to define the size of the a elements in % ...
I am using float:left to position all this element on top next to each other. I am using the css property width to make them occupy 20% each of the total top of the page.
<body>
<header>
<img src="mylogo.png" style="width:42px;height:42px">
<nav>
Welcome
About
Art Work
Events
</nav>
</header>
<h1>Title of the page</h1>
</body>
* {
box-sizing: border-box;
padding: 0px;
margin: 0px;
}
header {
width: 100%;
}
.logo {
float: left;
width: 20%;
}
nav {
float: left;
}
nav a {
width: 20%;
}
There is some space between the logo and the links, but the links does not arrange along the top at equal distance, they stay stuck to each other... I suppose it's because their width is relative to nav, which is not 100% as there is the logo. But I don't know how to define the size of these a elements relatively to the header that I fixed to be 100% of my page?
Here's my solution. I made some changes in your css and instead of float I used flex-box technique to align them. I made the header black to detect the header easily. You can change it in the css. Hope this solution will help you.
* {
box-sizing: border-box;
padding: 0px;
margin: 0px;
}
header {
height: 10vw;
line-height: 10vw;
width: 100%;
background-color: #000;
}
.logo img {
vertical-align: middle;
}
a {
display: inline-block;
height: inherit;
width: 20%;
text-align: center;
line-height: inherit;
vertical-align: bottom;
transition: all .33s ease-in-out;
}
a:hover {
background-color: white;
}
<body>
<header>
<img src="mylogo.png" style="width:42px;height:42px"><!-- -->Welcome<!-- -->About<!-- -->Art Work<!-- -->Events
</header>
<h1>Title of the page</h1>
</body>
I found out that the following CSS worked:
header {
width: 100%;
display: inline-block;
}
.logo {
float: left;
width: 20%;
}
header nav {
width: 80%;
float: left;
}
header nav a {
width: 20%;
float: left;
text-align: center;
}
I am currently developing my own website. The first div container integrates a image to html. The second div with the classname "face" should show up directly beneath the image. It contains a text with predefined width and height.
Now the problem: It does not show up on the right of the image div. How can I show it on the right side?
.face {
text-align: center;
background-image: linear-gradient(rgb(0, 21, 166), #115FD8);
border-radius: 5px;
width: 240px;
height: 80px;
margin-right: 0 !important;
}
.start {
margin-right: 10px;
}
.postpreview {
position: relative;
width: auto;
}
.one-half {
float: left;
width: 48.717948717948715%;
margin-left: 2.564102564102564%;
}
<div class="one-half start postpreview">
<a href="#">
<img src="http://vocaloid.de/wp-content/uploads/2015/02/KAITO-6th-anniversary-2015-Project-DIVA-Arcade-Diamond-Dust-750x256.jpg" class="attachment-Beitragsbild wp-post-image">
</a>
</div>
<div class="face">Facebook
</div>
This should help. http://jsfiddle.net/13m3vbu1/3/
Insert into your css:
.face {
text-align: center;
background-image: linear-gradient(rgb(0, 21, 166), #115FD8);
border-radius: 5px;
width: 240px;
height: 80px;
float: left;
margin-right: 0 !important;
}
.one-half {
float: left;
width: 48.717948717948715%;
margin-left: 2.564102564102564%;
margin-right: 10px;
}
.one-half > a {
display: block;
width: 100%;
overflow: hidden;
}
I removed the redundant CSS that isn't needed as well.
If you just want the div with a class face to show on the right side of div one-half use float: left and instead of using pixels in .face use percent it's more flexible
CSS
.one-half {
float:left;
width: 45%; //adjust in what % you want
display: inline;
}
.face {
float: left;
width: 45%; //adjust in what % you want
display: inline;
}
I am building a backend for a website and I got a strange behavior of display table/cell/row
My fiddle: http://jsfiddle.net/5G9nJ/
html
<div id="App">
<div id="AppFrame">
<div id="AppMenu">
<div id="AppMenuContent">test</div>
<div id="AppMenuLog">test</div>
</div>
</div>
</div>
css:
html, body{
height: 100%;
margin-left: 0px;
margin-top: 0px;
margin-bottom: 0px;
background-color: #ebebeb;
font-family:Helvetica;
}
#App{
height: 100%;
display: table;
margin-left: 0px;
margin-top: 0px;
}
#AppFrame{
display: table-row;
height: 100%;
margin-top: 0px;
}
#AppMenu{
height: 100%;
width: 300px;
margin-top: 0px;
display: table-cell;
}
#AppMenuContent{
max-width: 65px;
height: 100%;
background-color: red;
}
#AppMenuLog{
margin-left: 65px;
width: 200px;
height: 100%;
background-color: #999999;
}
#AppDisplay{
display: table-cell;
height: 100%;
}
The problem is that, the div "AppMenuLog" will not appear next to the div "AppMenuContent"! I've tried to set the both divs to blocks, changed the width and heights but nothing solves this, can anyone help me?
You need to add display: inline-block to #AppMenuContent and #AppMenuLog.
Here's a JSFiddle.
This is a lot better and easier than using float: left; see the reason here.
If you want to go with the table structure check this
DEMO
display:table-cell; needs to be added to #AppMenuLog and #AppMenuContent
DEMO
You need to add float:left to div #AppMenuContent
#AppMenuContent {
background-color: #FF0000;
float: left;
height: 100%;
max-width: 65px;
}
Next time try to search harder an answer. On this is are a lot of questions similar with your. You need to use float:left;
Here you find your solution http://jsfiddle.net/5G9nJ/5/
I'm struggling to set an img's height inside a div to be taler than the other img's on the rest of my site, can anyone advise, thanks
Here is the HTML
<div class="project">
<img src="../../../Images/Nu Space/Nu Space LH.jpg" alt="Nu Space LH" class="image" height="auto" width="580">
<img src="../../../Images/Nu Space/Nu Space BC.jpg" alt="Nu Space BC" class="image" height="auto" width="580">
<div class="clear"></div>
</div>
Here is the CSS
img {
float: right;
margin-top: 0px;
height: auto;
}
img li {
margin-top: 75px;
height: 100%;
width: 100%;
}
.project {
width: 700px;
min-height: 100%;
margin-left: 10px;
margin-right: 0px;
margin-bottom: 30px;
left: auto;
background-color: #FFF;
}
Any help would be appreciated
try this one,
.project
{
width: 700px;
min-height: 100%;
margin-left: 10px;
margin-right: 0px;
margin-bottom: 30px;
left: auto;
background-color: #FFF;
}
.project .image1
{
width:200px;
height: 200px;
}
http://jsfiddle.net/tT8JH/2/
div > img {
width: (desired width in %);
height: (desired height in %):
}
Edit: Sorry I was not exact in my explanations, but this will change only the images inside a div, which was what the author wanted. I believe he has other images on the webpage, which should have different size.