CSS iframe won't move - html

I'm pretty new to HTML and CSS, and I've looked for an answer to this for awhile but I can't seem to find anything. I have an iframe element that I'm trying to position , but whenever I change the left or right properties it doesn't actually move.
.things1 {
position: relative;
}
.afx-vid {
position: absolute;
left: 500px;
}
<div class="things1">
<iframe class="afx-vid" width="300" height="200" src="https://www.youtube.com/embed/rndV_5q8Tkc" frameborder="0" allowfullscreen></iframe>
</div>
I know this probably seems like a dumb question but some help would be appreciated :)

You code will actually move the iframe, but this is not a good way to do that. I recommend you use flex property to move your elements on your website.
flex is super easy and it will make your learning so much easier.
There are tons of youtube videos and websites that explain how flex works, so please watch them, it will help you. :)
Here is your fixed solution. Just replace your current css with this one :
.things1 {
width : 100%;
display: flex;
justify-content: center;
}
.afx-vid {
margin : 0px auto;
}
You always assign display : flex; to the parent of the element(s) that you want to move (in this case, you want to move .afx-vid, and his parent is .things1, so we give .things1 display : flex;).
justify-content : center; is one of the properties you can use when you declare display : flex;. What it basically does is align items on x-axis (in this case, he will align your iframe to the center of the page).
Let me know if it worked. :)

This actually should be a comment, but I want to demonstrate what I write by using code, so here it is:
What do you mean when you write "whenever I change the left or right properties it doesn't actually move"?
I changed the left setting of your code in the the snippet below to 200px(it's the only change I made), and the position of the iFrame is different than in you original snippet! (it's 200px left of the parent's left border, opposed to 500px in your snippet).
???
.things1 {
position: relative;
}
.afx-vid {
position: absolute;
left: 200px;
}
<div class="things1">
<iframe class="afx-vid" width="300" height="200" src="https://www.youtube.com/embed/rndV_5q8Tkc" frameborder="0" allowfullscreen></iframe>
</div>

I had the same problem if I understand you correctly. I had an iFrame and I gave it a style by giving it the class-attribute and in the CSS for that class I tried to give it:
position: absolute;
left : 200px;
right : 0px;
top : 0px;
bottom : 0px;
But the left and right positions had no effect. The IFrame did not "move" to where I wanted it.
For every other type of element using CSS this way seems to work but there is something about iFrame that makes it different.
Then I finally discovered a somewhat round-about way to make it position like I wanted by doing the following:
In the HTML for the IFrame-element give it:
width="100%"
height="100%"
Note above is HTML, not CSS
In the HTML wrap the IFrame element inside a DIV and give that div a style-class named for example 'iFrameWrapper'. Give that wrapper-class the attributes like these:
.iFrameWrapper
{
position : absolute;
left : 210px;
right : 0px ;
top : 0px;
bottom : 0px;
}
Now the iFrameWrapper -DIV AND the IFrame -element inside inside it position correctly.
The HTML looks something like this:
<div class="iFrameWrapper">
<iFrame width = 100%;
height = 100%;
src = "..."
></iframe>
</div>
SUMMARY:
Make the iFrame element have HTML attribute-values height="100%" width="100%" and wrap it inside an absolutely positioned DIV. Then position that wrapper-div with CSS anyway you want.

Related

Bootstrap : block image resizing

I'm using a YouTube picture below one for example :
and Bootstrap to display it:
<img src="{{img}}" alt="{{title}}" class="img-circle" width="60px" height="60px">
But the picture is crushed:
Am I missing a bootstrap property ? or a common hack ? Thanks !
Edit :
I finally found a trick to do the job :
<div class="crop">
<img src="https://i.ytimg.com/vi/EONhJ9qvCPY/default.jpg" alt="#" >
</div>
And
.crop{
width: 60px;
height: 60px;
overflow:hidden;
position:relative;
border-radius: 50%;
}
.crop img {
position: absolute;
left: -27px;
top: -18px;
}
What do you mean by picture is crushed? You're against the picture being in a circle, or the way it displays in the circle?
I think first of all it's crucial to understand, bootstrap as in whole is a framework containing rules for html, css & javascript. So to answer your question, there is no property/hack orso you're missing.
The reason why it displays like it displays, is because the image does not properly fit into the 60x60 image (or rather the crop of it in the circle) therefore, it crops out the parts that do not fit.
What I'm saying is, although it may not visually look like it, it still takes the 60x60 block and just puts a circle inside it and renders the outskirts transparent. There is virtually no way to avoid this, other than resizing the original picture.
So either
a) Edit the original picture in mspaint/photoshop/gimp whatever so it will fit better inside the circle crop
b) Go inside the bootstrap CSS properties and change the width and height properties of the img. Alternatively set a max-width and max-height for the images so it will not be stuck inside the 60x60 definition.
img {
width: value;
height: value;
}
The reason why you'd want to do it like that, is because in case you will want to use such an image in future, you will not have to specify the width and height properties through HTML code (which is causing you unnecessary displaying issues and code-readability problems to begin with), but it will automatically apply it to every element using the CSS rules.

position iframe on specific content inside amazon

kinda new here
so I've been trying for the past 2hr to position an iframe and just couldnt get it right (or anywhere near that...)
my goal is to position an iframe of amazon just where "Hello, [name]" is written.
first I couldnt set an iframe because of their Same origin policy but I guess some pages aren't protected, like this one: http://www.amazon.com/product-reviews/B0051QVF7A/ref=cm_cr_dp_see_all_top?ie=UTF8&showViewpoints=1&sortBy=bySubmissionDateDescending
positioning the iframe on my account information just seem impossible (tried margin-left, right, divs and everything)
my goal would be somewhat like this - http://i.stack.imgur.com/gQwyn.png
While I'm a little skeptical about what this is for, I'll provide an answer for it anyways.
So you can't exactly target the location of where your iframe's initial screen will show up at (as it will always default to the top left corner if I'm not mistaken) but you can move the iframe itself around.
Knowing that, it's possible to create an iframe effect over the iframe itself.
You'll have an iframe that will be large enough to capture the button at first glance (which 1260px wide and 300px high is good enough)
You will then move the iframe to position the button to where you would like it to show up in using an absolute position and the top and left style.
Then create a new div to contain that iframe and give it a width and height to what the button's size would be and then remove the ability to scroll with overflow: hidden; and remove the scrolling by stating it within the iframe tag scrolling="no".
You should then have the same results as below:
#my-div {
width: 128px;
height: 55px;
overflow: hidden;
position: relative;
}
#my-iframe {
position: absolute;
top: -42px;
left: -884px;
width: 1260px;
height: 300px;
}
<div id="my-div">
<iframe src="http://www.amazon.com/product-reviews/B0051QVF7A/ref=cm_cr_dp_see_all_top?ie=UTF8&showViewpoints=1&sortBy=bySubmissionDateDescending" id="my-iframe" scrolling="no"></iframe>
</div>

How do I make a header that remains in the top at all times?

I want to make a header like http://www.chacha.com (doesn't move, is about that wide and that height, and able to fit divs inside it and also has to be an image)
I am starting off with a blank html document and a blank css page, so there I haven't currently written any code.
I've been trying two days straight to do this now so I would really appreciate any help anyone can provide.
I have gimp so if anyone could also give me image dimensions for a perfect header and perfect background size I would appreciate it even more.
CSS:
#header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 10px;
background: url(yourimage.png) repeat-x;
}
<!--html -->
<div id="header"></div>
That should give you a starting place, I can't tell you more without seeing exactly what the layout's supposed to be.
The CSS property you're looking for is position: fixed which will position the element relative to the viewport. This is good breakdown of positioning: https://developer.mozilla.org/en-US/docs/CSS/position
In this specific case, what you've got is an element with styles roughly along these lines:
#header_id {
position: fixed;
width: 100%;
height: 35px;
}
You don't have to set the height, but unless there is content in the fixed element, it will collapse if there is no height specified. They also appear to have put a drop-shadow on the element toget the neat floating effect.
If you want to have an image inside, you can just put the <img> inside the header element, or use it as the background-image url in the CSS and position it with background-position (see also: https://developer.mozilla.org/en-US/docs/CSS/background-position although the compatability table at the bottom is important if you want to do anything too specific with this property).
You can do this with any block-level element (or any element with display:block set on it). In your example they are using the HTML5 <header> tag; a <div> would work, too, if <header> wasn't appropriate for your page.
I would recommend using the Firebug addon with Firefox (or similar developer consoles with other modern browsers) -- you can right click on an element on the page and select 'Inspect element' from the dropdown menu and get a breakdown of both the markup and styling to see how other websites are constructed. Very useful for when you're browsing the internet and you see something and think, 'that's a neat trick, how does it work?'
FOR FULL WIDTH FIXED HEADER
header {
width:100%;
background:green;
height:60px;
margin:-8px;
position:fixed;
}
FOR NONFULL WIDTH FIXED HEADER
Create a div and set width and height (you can also set it left or right by float:left, float:right)
then in this div put the code above but without margin:-8px; and change the width to the width that your div has.
Here is a test

Converting an img tag to a div tag giving odd height results

I'm certainly no CSS guru, but I am working on a problem where I'd like to make copying of images just slightly more burdensome for users. Sure, they can still easily be retrieved, but this makes it so you can't just drag/drop them on your desktop. Basically, I had a bunch of markup like this:
<img width="400" src="my image.png" class="foo" alt="foo">
Instead, I decided to put this into a background image and change the element to a div:
<div width="400" class="foo">
The problem I have is that the images have a fixed width, but a variable height. This worked excellent when I was using an img tag. It doesn't have the same behavior when I use a div tag. Instead, the CSS is requiring me to force a height property to display anything at all:
This doesn't work
.foo {
display: block;
margin: 0;
padding: 0;
width: 400px;
background-image: url(myimage.png);
/* height: 200px; */
}
This sorta does:
.foo {
display: block;
margin: 0;
padding: 0;
width: 400px;
background-image: url(myimage.png);
height: 200px;
}
The problem is the height for the images are all variable as I mentioned before. So it tiles over and over if I hard code a size. The container can be a placeholder for well over 5,000 images, so setting it by hand won't do it. If I can get this div to behave exactly like the img tag did, the problem is solved.
If you are just trying to prevent people from clicking and drag/dropping, I would say put each img into it's own div with position: relative. Add another div inside that relative div that has the following style:
div.img_box {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: none;
z-index: 9999; /* or anything higher than your img's z-index */
}
That will cover up the image with a transparent div.
That way the image (which is part of your content) is still syntactically correct in the html.
Everybody is of course correct in saying that they have already downloaded the images to their computers just by visiting the site.
If you're trying to prevent users from reusing your content easily, some good methods are to:
1. Use images with lower resolution to limit reuse potential
2. Watermark your images
3. A combination of both, in an image sprite.
Hacking at it will just be ugly, ineffective, and difficult to maintain.
You are just setting the background of the div, you aren't adding an image to the div. The div can be resized to whatever it won't resize to what it's background image is. Just use the tag.
The only thing you could do with CSS is add a height which would work for all images. So if you're images range from 200-250px in height, set the div to 250px. Otherwise, you'll need javascript or server-side scripting to determine the height of the image and set the the CSS.

Clipping an element to only show the middle part?

I'm using the Google Charts API which renders charts using an <iframe>, however there's an large amount of white space on both the bottom and top parts which I'd like to remove. I've been attempting to do this in a variety of ways (explained below), but can't seem to get it to work out how I want it to;
My HTML markup
<div id="chart">
<div id="chart-contents">
<iframe name="Drawing_Frame_49918" id="Drawing_Frame_49918" width="690" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>
</div>
</div
The <iframe> is included via javascript, and so not actually part of my mark-up; but part of the DOM post-load.
My CSS Styling
#chart {
padding-top: 15px;
margin: auto;
width: 690px;
height: 155px;
overflow: hidden;
}
#chart-contents {
margin-top: -45px;
}
#chart-nav {
margin-top: 15px;
padding: 0px 15px;
}
The intent of this CSS is to restrict the height of the container element #chart to 155px (where the <iframe> height is 200px), and hide the overflow. Then #chart-contents is pushed up by 45px but because the overflow is hidden, it's still contained within the same 155px area, and thus the middle and x-axis of the chart is shown.
However, this doesn't seem to work, as while clipping off the bottom part of the <iframe> by setting a restricting height and overflow to hidden, attempts to #chart-contents up have all failed.
So far I've tried;
Use of negative top, padding-top and margin-top properties.
Positioning of absolute and relative in conjunction with top.
Using the clip property in conjunction with a relative position.
I'm starting to think that this is something that perhaps isn't possible without further elements or javascript?
Any suggestions and answers for how to rectify this in an efficient way (ideally sticking to just CSS properties for the already existing elements if possible) would be greatly appreciated!
If you feel like you need more information or some kind of visualization please just ask. I would jsFiddle this for you, but because of their AJAX policies and Google's API use of AJAX, it's rather difficult.
You could always place the previous element on top of your iframe so it looks like it's starting sooner than it actually is. This obviously works for an element coming after the iframe as well.
All you need to do to achieve this is to give the element position: relative.
Preview: http://jsfiddle.net/Wexcode/XyVGr/