positioning

random position of divs in javascript

心已入冬 提交于 2019-11-27 07:54:19
I'm trying to make Divs to appear randomly anywhere on a webpage with javascript. So a div appears then disappears, then another div appears somewhere else on the page then disappears, then another div appears again in another random spot on the page then disappears, and so on. I'm not sure on how to generate random units in pixels or what technique to use to generate random positions. How do I do that? Here's my code: var currentDivPosition = myDiv.offset(), myDivWidth = myDiv.width(), myDivHeight = myDiv.height(), var myDiv = $('<div>'), finalDivPositionTop, finalDivPositionLeft; myDiv.attr(

Why aren't my absolutely-positioned elements located where I expect?

孤者浪人 提交于 2019-11-27 05:39:23
I'm just learning the positioning in CSS. Based on the article that I've found useful, I'd started to playing around. With the following code, I cannot understand why the absolute grey-box div is outside of it's relative parent. I expected that the grey-box will be on the top-left corner of the container. .container { background: lightblue; position: relative; } .box-orange { background: orange; height: 100px; width: 100px; position: relative; top: 100px; left: 100px; z-index: 2; } .box-blue { background: lightskyblue; height: 100px; width: 100px; /*position: static;*/ } .box-green {

Relatively position an element without it taking up space in document flow

情到浓时终转凉″ 提交于 2019-11-27 04:09:37
问题 How can I relatively position an element, and have it not take up space in the document flow? 回答1: What you're trying to do sounds like absolute positioning. On the other hand, you can, however, make a pseudo-relative element, by creating a zero-width, zero-height, relatively positioned element, essentially solely for the purpose of creating a reference point for position, and an absolutely positioned element within that: <div style="position: relative; width: 0; height: 0"> <div style=

CSS Positioning Margin Trouble

旧城冷巷雨未停 提交于 2019-11-27 03:00:52
问题 I am unsure how to position elements using css, as when I use methods like the following, whenever I resize the browser, the elements stay in the same place instead of where I would like them to be on the resized document. Please can you tell me what I am doing wrong?! .logo { left: 20px; top: 20px; position: absolute; } #header h1 { margin-top: 20px; margin-left: 500px; color: rgb(127, 127, 126); line-height: 0px; } Please, have a fiddle - http://jsfiddle.net/hHGRc/ 回答1: Within the (X)HTML

How do I center an SVG in a div?

我与影子孤独终老i 提交于 2019-11-27 02:46:32
I have an SVG that I am trying to center in a div. The div has a width or 900px. The SVG has a width of 400px. The SVG has its margin-left and margin-right set to auto. Doesn't work, it just acts as if the left margin is 0 (default). Anyone know my error? Spadar Shut SVG is inline by default. Add display: block to it and then margin: auto will work as expected. Esger Above answers did not work for me. Adding the attribute preserveAspectRatio="xMidYMin" to the <svg> tag did the trick though. The viewBox attribute needs to be specified for this to work as well. Source: Mozilla developer network

jQuery position DIV fixed at top on scroll

≯℡__Kan透↙ 提交于 2019-11-27 02:01:39
I have a page that's fairly long and within the layout's menu, there's a flyout menu. I'd like this flyout portion of the menu to show at the top of the page even when the user has scrolled the menu bar out of view. Here's the HTML for the menu <div id="task_flyout"> <div id="info">Compare up to 3 cards side-by-side. Click “Add to Compare” next to any card to get started…</div> <div id="card1" class="card"> <div class="cardimage"></div><div class="cardname"><a href="#"></a></div><div class="remove"><a href="#"><img src="images/remove.png" alt="remove card" width="12" height="12" border="0" /><

Difference between static and relative positioning

℡╲_俬逩灬. 提交于 2019-11-26 23:57:45
In CSS, what is the difference between static (default) positioning and relative positioning? Static positioning is the default positioning model for elements. They are displayed in the page where they rendered as part of normal HTML flow. Statically positioned elements don't obey left , top , right and bottom rules: Relative positioning allows you to specify a specific offset ( left , top etc) which is relative to the element's normal position in HTML flow. So if I have a textbox inside a div I could apply relative positioning on the textbox to have it display at specific place relative to

What is the simplest jQuery way to have a 'position:fixed' (always at top) div?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 23:51:06
I'm relatively new to jQuery, but so far what I've seen I like. What I want is for a div (or any element) to be across the top of the page as if "position: fixed" worked in every browser. I do not want something complicated. I do not want giant CSS hacks. I would prefer if just using jQuery (version 1.2.6) is good enough, but if I need jQuery-UI-core, then that's fine too. I've tried $("#topBar").scrollFollow(); <-- but that goes slow... I want something to appear really fixed. Using this HTML: <div id="myElement" style="position: absolute">This stays at the top</div> This is the javascript

How can I fill a div with an image while keeping it proportional?

倾然丶 夕夏残阳落幕 提交于 2019-11-26 23:20:39
I found this thread — How do you stretch an image to fill a <div> while keeping the image's aspect-ratio? — that is not entirely the thing that I want. I have a div with a certain size and an image inside of it. I want to always fill-out the div with the image regardless if the image is landscape or portrait. And it doesn't matter if the image is cut-off (the div itself has overflow hidden). So if the image is portrait I want the width to be 100% and the height:auto so it stays in proportion. If the image is landscape I want the height to be 100% and the width to be auto`. Sounds complicated

CSS: fixed to bottom and centered

孤人 提交于 2019-11-26 21:38:25
I need my footer to be fixed to the bottom of the page and to center it. The contents of the footer may change at all time so I can't just center it via margin-left: xxpx; margin-right: xxpx; The problem is that for some reason this doesn't work: #whatever { position: fixed; bottom: 0px; margin-right: auto; margin-left: auto; } I crawled the web and found nothing. I tried making a container div and nada. I tried other combinations and gurnisht. How can I make this happen? Thanks marcgg You should use a sticky footer solution such as this one : * { margin: 0; } html, body { height: 100%; }