This question already has an answer here:
Responsive width is too small on phone, but okay on desktop browser
(1 answer)
Closed 6 years ago.
I have:
<div style="min-width: 1000px;">
<p>
Some text
</p>
<div class='div_img_left'>
<img src="images/sth.png" alt="missing image" style="max-width: 100%;">
<footer>My caption</footer>
</div>
</div>
.div_img_left {
max-width: 50%;
float: left;
margin-right: 30px;
margin-bottom: 2em;
text-align: center;
}
It is looking fine on my PC's screen. The problem begins when I open it on my mobile phone. As I suppose the issue here is that I don't have 1000px screen width on the phone. So everything shrinks. The problem is that "Some text" looks fine. Unfortunately "My caption" shrinks significantly more. How can I solve this?
I tried using other geometrical constraints but I failed. Specifically using % or min-height.
Use media queries and don't set things at such a large min-width if you want to have a responsive site. Use vw for width.
.div_img_left {
max-width: 50vw;
float: left;
margin-right: 30px;
margin-bottom: 2em;
text-align: center;
}
figcaption {
font-size: 1em;
line-height: 1.3;
text-align: center;
}
#media (max-width: 500px) {
figcaption {
font-size: 14px;
line-height: 1
min-width: 100%;
}
figure {
min-width: 100vw;
}
}
<div style="width: 100%;">
<!--changed from min-width: 1000px-->
<p>
Some text
</p>
<figure class='div_img_left'>
<img src="http://placehold.it/150x200/eea/e00?text=150x200" alt="missing image" style="max-width: 100%;">
<figcaption>My caption</figcaption>
</figure>
</div>
Related
This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 2 years ago.
my problem is space between pictures
Hello everyone,
I am from Russia and my eng so bad, sorry for this.
I have a problem with margin that u can see on the attachment photo.
I already try justify-content and it didnt help to solve my problem.
i don't know from where this margin appeared.
Somebody please help me
thx
<style>
.services1 {
display: flex;
width: 80vw;
align-items: center;
margin-left: 10vw;
background-color: white;
text-align: center;
}
.photo {
width: 40vw;
}
.photo div {
margin: 0;
}
.services_text_photo1 {
width: 40vw;
color: black;
font-weight: 100;
font-size: 16px;
}
h5 {
font-size: 32px;
font-weight: 600;
margin: 0;
}
.services_text_width {
width: 35vw;
margin:0 2.5vw;
}
</style>
<div class="services1">
<div class="services_text_photo1 services_text_width">
<h5>text</h5>
<p>text</p>
</div>
<div class="photo">
<img src="img/photo.jpg" alt="" width="100%">
</div>
</div>
<div class="services1">
<div class="photo">
<img src="img/photo-3.jpg" alt="" width="100%">
</div>
<div class="services_text_photo1 services_text_width">
<h5>text</h5>
<p>text</p>
</div>
</div>
So this isn't a flexbox specific issue but rather an issue with how the browser renders images.
To fix it simply add
.photo img {
vertical-align: bottom;
}
```html
This post has some good info in explaining it I think
https://stackoverflow.com/questions/5804256/image-inside-div-has-extra-space-below-the-image/5804278
How to resize images on my presentation website depending on different screen resolutions? For example, on a resolution like 2560x1440 the width of the images is too big. I want it to go from 28% to 20% because that's how i think it will look better. But only for that screen resolution, in other screen resolutions like 1280x720 it's ok.
This is an image of what i'm saying, with the 28% width: https://imgur.com/OPUbdWz
And this is how i want to transform it, with 20% width on that specific screen resolution: https://imgur.com/iXLAe8l
This is my trying in CSS, but not working:
#media (max-width: 2000px){
.amenajari_interioare_css{
width: 20%;
}
}
And this is my HTML and CSS code:
HTML:
<section id="showcase">
<div class="container">
<h1>LOCUINȚE</h1>
<div class="amenajari_interioare_css">
<img src="../img/locuinta1.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta2.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta3.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta4.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta5.jpg" alt="" />
</div>
<div class="amenajari_interioare_css">
<img src="../img/locuinta6.jpg" alt="" />
</div>
</section>
CSS:
.amenajari_interioare_css{
min-width: 350px;
width: 28%;
height: 300px;
display: inline-block;
margin: 8px;
position: relative;
}
.amenajari_interioare_css img{
margin-top: 5px;
margin-bottom: 1px;
width: 100%;
height: 100%;
border: 1px solid black;
border-radius: 16px;
}
You have a couple errors in your CSS - mainly the media query. It should be min-width, because you want the change to happen for screen sizes above 2000px.
#media (min-width: 2000px){
.amenajari_interioare_css {
width: 20%;
}
}
The other thing you should probably do is:
.amenajari_interioare_css img{
margin-top: 5px;
margin-bottom: 1px;
width: 100%;
height: auto;
border: 1px solid black;
border-radius: 16px;
}
Set the height to auto or in the event you don't have a perfectly square image, otherwise that image will get stretched.
In the homepage of my website I would like to display 12 pictures, equally sized, in a 3 by 4 grid. I would like to avoid tables because in the CSS I've got 2 media queries that are "changing" the layout from 3 by 4 to 2 by 6 and to 1 by 12 when the screen is not big enough, but if there's a way to "change layout" with tables I'm totally ok with it. The issue I'm having is that when I'm displaying not 12, but 11 pictures, the last one is not centered.
The code of the first 3 divs is as follows (the other 9 are pretty much the same):
.divThumb1{
float: left;
width: 31%;
max-width: 288px;
margin: 0%;
position: relative;
margin-top: 15px;
}
.divThumb2{
margin:0 auto;
display:inline-block;
width: 31%;
max-width: 288px;
margin: 0%;
position: relative;
margin-top: 15px;
}
.divThumb3{
float: right;
width: 31%;
max-width: 288px;
margin: 0%;
position: relative;
margin-top: 15px;
}
Any suggestions? Please let me know if you need more infos!
If you want to achieve such responsive layout, you may want to look into using the grid layout offered in a popular CSS framework named Bootstrap: http://getbootstrap.com/css/#grid-options
Once you included Bootstrap, using something like:
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
...
</div>
should allow you achieve your purpose without customizing each div manually. Be sure to look into .col-xs-, .col-sm-, .col-md-, and .col-lg- as well. They are well documented.
Hope that helps.
Here's a responsive image grid with a maximum width. All images are centered. I hope you find it useful!
.imageGrid {
display: block;
margin: 0 auto;
max-width: 800px;
text-align: center;
font-size: 0;
line-height: 0;
}
.imageGrid * {
font-size: 16px;
line-height: 21px;
}
.imageGrid > img {
display: inline-block;
width: 31%;
margin: 1%;
background-color: gray;
}
<div class="imageGrid">
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
<img src="https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg" alt="img"/>
</div>
First of all, I just wanted to say this page is for a Web Design course.
I have icons for social media in a responsive page I'm building, and I've applied a max-width:3% to all of them to reduce their original size, as they were too big before. Now, as I reduce the size of the window, I would like the icons stay responsive while retaining their new size. However, the icons scale as well, making them appear too small. I know I could use pixels to define a fixed size, but one of the objectives of this exercise is to not set image values in pixels (just allowed for padding values).
Is there a way to achieve this?
My html codes
<div id="footwrap">
<footer>
<div id="footh3">
<h3 class="h3">Follow me on social media:</h3>
</div>
<div id="footlink">
<a href="http://www.facebook.com" target="_blank">
<img src="images/facebook-icon.svg" alt="Facebook">
</a>
<a href="http://www.instagram.com" target="_blank">
<img src="images/instagram-icon.svg" alt="Instagram">
</a>
<a href="http://www.youtube.com" target="_blank">
<img src="images/youtube-icon.svg" alt="YouTube">
</a>
<a href="http://www.twitter.com" target="_blank">
<img src="images/twitter-icon.svg" alt="Twitter">
</a>
</di>
</footer>
</div>
My CSS style:
#footwrap {
clear: both;
padding: 2%;
}
footer {
position: relative;
clear: both;
text-align: center;
width: 100%;
height: 8em;
margin-top: 12%;
}
#footh3 {
display: inline-block;
}
footer h3 {
display: inline-block;
font-family: 'Open Sans', sans-serif;
font-size: 1.17em;
margin-bottom: 2em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}
#footlink {
display: inline-block;
}
footer a {
text-decoration: none;
}
footer img {
display: inline-block;
max-width: 3%;
height: auto;
margin-left: 1.5%;
margin-right: 10px;
vertical-align: middle;
}
The desired outcome would be how the icons in the top right corner of this page react when the web browser window is reduced: http://www.omganeshaya.com/
You can use media queries to adjust to a higher percentage as the page gets smaller. see fiddle: https://jsfiddle.net/622r62mp/
For more information about media queries you can reference this site https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
CSS example
img{max-width:3%}
#media (max-width: 1000px){
img{max-width:9%}
}
#media (max-width: 600px){
img{max-width:15%}
}
I’m updating some legacy code on an old website, and the CSS is a nightmare. All I want to do is make the div that holds a username expand a bit when needed, and keep the outer div centered (horizontally) on the page. The myLabel control is populated based on a user’s name (it typically isn’t pre-defined as John Doe).
Currently, between the 800px value on myContainer, and the 350px value on myGridB, longer usernames are wrapping inside of the div. I’d rather display the long names on one line and, when possible, not bump the other controls to the next line.
I’ve tried using min-width on myContainer and myGridB , but that just allows the divs to expand across the whole page. I see this is common behavior for divs in this question.
I also tried some of the methods in this other question, but that pushed my header content to the left, and I need it centered.
I realize this code is a garbled mess, but I appreciate any ideas…
aspx:
<div class="myLogo1">
<div class="myContainer" style="width: 800px">
<div class="myGridC myLogo2 first">
<a onclick="loadMyHomePage(); "><img src="myImageAddress" /></a>
</div>
<div class="myGridB first last">
<div class="myHome myGridB first last">
<asp:Label runat="server" CssClass="myHome" ID="myLabel">
John Doe
</asp:Label>
<span class="myHome">
<asp:HyperLink NavigateUrl="mySettingsPage.aspx" runat="server">
My Settings
</asp:HyperLink>
</span>
<a href="myLogoutPage.aspx") %>">
<img src="myLogout.jpg") %>" alt="Logout" />
</a>
</div>
<div class="myGridB first last">
<div class="myGridA myPaddingA myHome">
<a href="myOtherPage" target="_blank">
<img width="180px" height="72px" src="myOther.jpg" />
</a>
</div>
</div>
</div>
</div>
</div>
css:
.myLogo1
{
background-color: #363636; /* #000000; */
width: 100%;
height: 125px;
}
.myContainer
{
margin-left: auto;
margin-right: auto;
width: 960px;
}
.myGridA, .myGridB, .myGridC {
display: inline;
float: left;
margin-left: 5px;
margin-right: 5px;
}
.myGridA
{
width: 190px;
}
.myGridB
{
width: 350px;
}
.myGridC
{
width: 390px;
}
.myLogo2
{
border: none 0px transparent;
padding-top: 10px;
}
.first
{
margin-left: 0;
}
.last
{
margin-right: 0;
}
.myHome
{
text-align: right;
display: block;
vertical-align: top;
float: right;
position: relative;
font-size: 9pt;
}
.myHome span
{
font-size: 9pt;
float: left;
padding: 3px 5px 0px 0px;
}
.myContainer .myPaddingA
{
padding-left: 44px;
}
If it's ideas, how I usually horizontally center my divs is I set the container to a certain % width. then i use margin: auto; hope that helped.