I am new to media queries. I have it setup to swap an image based on the portal size. That is working great with the following code:
<header>
<div class="logo_div">
<img src="images/logo_full.png" class="logo_full">
<img src="images/logo_small.png" class="logo_small">
</div>
</header>
/* Logo DIV */
.logo_div {
margin: auto;
width: 50%;
}
/* Logo */
.logo_small {
display: none;
}
#media (min-width: 1200px) {
.logo_full {
display: block;
text-align: center;
}
.logo_small {
display: none;
}
}
My large logo is centered just fine. My small logo however sits to the right. I have tested this by simply changing the browser window size as well as on my iPhone XSM. On my phone, it is obvious that the small logo is to the far right.
Am I missing something here?
You can see this live also by going to http://thelavender.net/_fades/
For me the best way to center any object is:
#myobjectid{
display:table;
margin:0 auto;
}
In your case put it to your div container, and remove width.
Inside your image, put your width tag.
I want to add that you're making two http requests, for both the large and small logos, when you really need only one. Have you considered using picture?
The HTML <picture> element contains zero or more <source> elements and
one <img> element to provide versions of an image for different
display/device scenarios. The browser will consider each child
<source> element and choose the best match among them; if no matches
are found, the URL of the <img> element's src attribute is selected.
The selected image is then presented in the space occupied by the
<img> element.
This following snippet will produce only one logo at a time and shrink your CSS significantly.
<picture>
<source srcset="logo_full.png" media="(min-width: 1200px)" />
<source srcset="logo_small.png" />
<img srcset="logo_full.png" alt="My default image" />
</picture>
Related
currently I'm working on an image galery and image upload tool. In the image below there is a demonstration of my current and my wanted galery state. The user is able to click on the thumbnails and see the large picture below that current thumbnail row in full size, pushing the next rows relative to the components height.
images.component.html
<div class="container">
<div class="image-box" *ngFor="let img of images$ | async">
<img class="mat-elevation-z1" [src]="environment.img + '/images/thmb/' + img.id + '.jpg'" (click)="selected = img">
<app-image-details *ngIf="selected?.id === img.id" [img]="img"></app-image-details>
</div>
</div>
images.component.scss
The theme-flexfix.scss fixes all images widths equally, while using flex. flex-container-wrap-items() makes the container flex and flex-wrap. The .image-box items are flex: 1.
#import 'src/theme-flexfix.scss';
.container {
#include flex-container-wrap-items(128px);
}
.container > .image-box {
#include flex-wrap-fix(128px);
padding: 4px;
box-sizing: border-box;
/* position: relative; */
}
img {
width: 100%;
}
image-details.component.html
<img [src]="environment.img + '/images/' + img.id + '.jpg'">
<p>
Lorem ipsum
</p>
image-details.component.scss
:host {
/* position: absolute */
/* left: 0 */
}
Tried the commented styles in resulting in what I want, but not pushing the other content. I think there is an easy solution, but for now I can't get it.
Thanks for your help.
I assume you are trying to replicate Google image search.
I would go about it like this:
When image is clicked, calculate how many images in a row you are displaying.
Inject DIV with larger version of the image after the last image in the row.
The idea is to always inject DIV after the end of current row.
This way, your DIV will not be absolutely positioned, but instead will flow with HTML and no absolute positioning hacking is required.
I am using a straight-forward HTML 5 video set up. The CSS and HTML are minimal. The video plays just fine, the splash image and everything is working great, controls show up. The problem is a dark line shows top and bottom. If I change the HTML divs to reference an "ID" rather than a "Class", the dark lines go away, but I need to use a class because I use a javascript to make sure each video starts at the beginning frame if the filmmakers forget to create a splash image for me. Have tried changing background to transparent, changing borders to 0, I've tried resizing images, and nothing changes. I would appreciate any thoughts/guidance you might have. I want to understand what is happening so if you can even just point me in the right direction, I'll dig more.
This is the CSS
.video-player {
background-color:#999999;
display: inline-block;
}
.video-player img {
background-color:#000000;
}
.video-tree {
width: 430px;
height: 250px;
}
video {
height: 100%;
width: 100%;
}
This is the HTML:
<div class="video-player">
<div class="video-tree">
<video id="myVideo1" poster="someimage.png" width="430" height="250" controls>
<source src="someVideo.mp4" type="video/mp4">
</video>
</div> <!-- end video-tree class -->
</div><!-- end video-player class -->
I'm working on a site that uses Bootstrap. I'm working to make this site work on both desktop and mobile browsers. Everything's working except for my banner image size.
I have an image that is 640x480. I have an image defined like this:
<img alt="My Picture" src="/wwwroot/img/banner.jpg" style="height: auto; max-height:320px; max-width: 100%;" />
On mobile pages, the image looks just like I want. However, on the desktop, the image is only 320px wide. However, on the desktop, I want the image to go as wide as it can go. Basically, I want to crop the right portion.
Is there a way to do this with CSS?
Thanks!
Stick your CSS in a class.
If using HTML5 remove the superfluous /
Change your max- to min- regards height.
Change your standard width: to auto, changing you
CSS:
.imageFun {
height: auto;
min-height:320px;
width:100%;
/* this is actually no longer needed but kept for posterity */
max-width: 100%;
}
HTML:
<img alt="My Picture" src="/wwwroot/img/banner.jpg" class="imageFun">
Use a media query to target the img in css file:
#media only screen and (min-width : 320px) {
img {
width:100%!important;
}
}
That should work changing the min-width to your desktop size.
More info here
on twitter-bootstrap you can use div with class responsive width :
<div class="col-md-12 col-sm-12 col-xs-12">
<img alt="My Picture"
src="/wwwroot/img/banner.jpg"
style="height: auto; width: 100%;"
/>
</div>
Where value 12 is width scala on grid bootstap. Please look at : https://getbootstrap.com/examples/grid/
i hope it what U want
You are using Booststrap, so remove the inline styling and add
class="img-responsive col-xs-12
That will fix it.
I want to make content of <div class="features"> smaller so that it appears like this:
Check this demo here to see what I have been able to achieve so far.As you see in the pic the features icons(No daily limits etc...) are small and the text below them is centered but I haven't been able to do this so far.
Give Some Width to class features in css .
<pre>
.features { width: 800px; }
</pre>
You can use media query for this.(If device size is smaller then you mentioned as above then what will be size of your given width and all thing goes here...As shown below.)
<pre>
#media screen and (max-width: 300px) {
body {
background-color: lightblue;
// font-size , margin , padding etc goes here ...
}
}
</pre>
Disable width in the class .feature. Currently, it is set to 400px. Once done, you should have something like this
I figured, rather than go back and forth in comments, I'd just write an answer.
A couple of things to consider:
your images and your text are in separate areas. For the images you adjust their size using width/height not font-size. If you want to adjust the font-size then adjust the class of the captions.
.features img {
float: left;
padding-left: 50px;
width: 100px; /*add some sort of width/height and that will resize*/
}
Your images and text are in different rows of the table, so adjusting them as a unit will be very hard.
<tr>
<td>
<img src=""/>
<p>text</p>
</td>
</tr>
would probably be a better set up, but to be honest ditching the tables all together and moving to a list would be more semantic.
<ul class="features">
<li>
<img src=""/>
<span>image caption</span>
</li>
</ul>
If you really want to get semantic checkout http://html5doctor.com/the-figure-figcaption-elements/ but long story short, you just need to hit those images with a width/height to adjust the size.
I have these 3 icons enclosed in separate DIVs all of which are enclosed within a single DIV:
<div id="icons">
<div id="divtxt" class="divicon">
<img src="/icons/text.png" id="icontxt" class="icon"/>
</div>
<div id="divpdf" class="divicon">
<img src="/icons/pdf.png" id="icondoc" class="icon"/>
</div>
<div id="divrtf" class="divicon">
<img src="/icons/rtf.png" id="iconrtf" class="icon"/>
</div>
</div>
I set some simple styles but can't figure out why these images are lining up top-to-bottom instead of left-to-right:
div#icons
{
width:200px;
height: 100px;
}
div.divicon
{
margin: 0 0 0 0;
padding: 0 0 0 0;
border: 0 0 0 0;
}
Any suggestions would be appreciated.
And now for something a bit more comprehensive:
You look like you just want a row of icons. Using your HTML, you would need to float the divs containing the icons in order for them to be next to each other. The reason why you need to float is because a div is a block level element (as opposed to inline) which means that nothing can exist in the horizontal space next to it.
You can achieve this effect by adding a float: left; rule to div.divicon
Floating does two things: it takes the block element out of the page flow allowing other elements to exist next to it (or flow around it) and it reduces the width of the box to fit the content. As far as the parent is concerned, a floated element has no height. To illustrate this, just try giving #icons a background color or border. You will notice that it won't show up - or show up as a 1px line.
In order for the parent to recognise the height of the floated element you need to tell the parent that overflow should be hidden with this rule:
#icons { overflow:hidden; }
This also works in IE however not always, so sometimes you might need to set a height or width or do a zoom:1 which tends to fix a lot of IE bugs (look up "hasLayout bug" if you want more info).
Now for a different solution:
You look like you just want a row of icons. Unless theres a reason for the images to be surrounded in a div (and in your example there is none) I would suggest to you to do something like this:
<div id="icons">
<img src="/icons/text.png" id="icontxt" />
<img src="/icons/pdf.png" id="icondoc" />
<img src="/icons/rtf.png" id="iconrtf" />
</div>
#icons { /* rules for our container go here */ margin:0; padding:0; /* etc... */ }
#icons img { /* rules for your icons */ border:none; margin:0 2px; /* etc... */ }
I have removed the redundant divs and the redundant class attribute on the images. Since images are inline elements you wont need to screw around with floats and you wont have any extra divs that may cause divitis a degenerative HTML disease that affects many websites and spreads through bad advice. Remember, only use what you need - don't use it just because its there.
Hope this helps,
Darko
You need a
float: left;
in your div#icons.
div is a block level element. So the default behavior is to layout one below the other, unless you float them like Robert suggested.