This is my first time posting here. Been a long time fan coming here every once in a while, hopefully someone can lead me to the right direction. I have an image file that I am unable to move anywhere. The image file is in a div that is in a tag that I want positioned to the bottom right of the div. I have used top-margin and left margin to no avail it is always just sitting there in the same position. Below is the code that pertains to the problematic area. Html part followed by the css part.
<div id = "container">
<section id = "content">
<article>
<div id ="monkey_img"><img src="images/cartoon-monkey_1.png" width="250" height="252"></div>
</article>
</section>
<aside id="sidebar">
<p>Monkey</p>
</aside>
</div>
<!--css-->
#content{
width: 600px;
height: 475px;
background-color: #FFF;
border-style: solid;
border-width: 2px;
float:left;
margin-right:30px;
}
#monkey_img{
width:500px;
height:425px;
margin-top:100px;
margin-left:100px;
display:block;
}
#container{
width:1000px;
height:550px;
margin:auto;
margin-top:65px;
}
#container p{
padding:15px;
}
#sidebar{
width 275px;
height:475px;
background-color:#FFF;
border-style:solid;
border-width: 2px;
margin-left:30px;
overflow:auto;
}
You'll probably want to set {position: relative} on the parent, and {position: absolute} on the element you're trying to move. You can then set top/right/bottom/left as you see fit.
http://jsfiddle.net/XemPh/2/
#monkey_img {
width:200px;
height:200px;
background-color: #eee;
position: relative;
}
#monkey_img img {
position: absolute;
right: 0;
bottom: 0;
}
<div id="monkey_img">
<img src="http://placehold.it/100x100" />
</div>
In this example I've applied the styles directly to the image, but you could do the image's wrapper and that element's parent as well.
Related
I succeeded to put div at the bottom with this code:
#div {
position: absolute;
width: 100%;
height: 58px;
margin: 0 auto;
bottom: 0;
left: 0;
overflow: hidden;
}
Recently, I added a side-bar to my site (300px).
When the side-bar opens, the whole site move left 300px, except for the div in the bottom.
I found that if I delete the position: absolute; from the css, the div will move left like all the elements in the site, but the div will not be in the bottom.
There is a way to move the div when the sidebar open like the all site and also be in the bottom of the page?
Thanks in advance
div{
position:fixed;
bottom:0;
}
If you want to center divs inside a div ,there's an example
HTML
<div class="parent">
<div class="children"></div>
<div class="children"></div>
<div class="children"></div>
</div>
CSS:
div.parent{
border:1px solid black;
padding:25px;
text-align:center;
}
div.children{
border:2px solid blue;
background-color:orange;
width:25%;
display:inline-block;
height:250px;
}
Other way to center only 1 div inside another div looks like that
HTML
<div class="parent">
<div class="children">Woho</div>
</div>
CSS
div.parent{
border:1px solid black;
padding:25px;
}
div.children{
border:2px solid blue;
background-color:orange;
width:250px;
margin:0 auto;
}
The margin:0 auto; property makes your div to go in the center.
members,
I'm having troubles with my HTML code. I am trying to make somekind of youtube. But when I try to create this:
How it should look1
But this is how it looks when I try to make it in HTML:
http://jsfiddle.net/4u64jb5w/3/
<div class="Video">
<div class="BlackRect"></div>
<div class="Video-content">
<h2 class="Titel">This is a video title..</h2>
<div class="Video-footer">
Gebruikersnaam
</div>
</div>
</div>
.Video {
display:block;
position:relative;
margin-top: 100px;
}
.BlackRect{
Width:250px;
height:150px;
background-color:#000;
float:left;
}
.Titel {
color: #34495e;
display:block;
font-size: 25px;
float:left;
position:absolute;
top:0;
margin-left: 270px;
padding: 0;
}
.Video-content{
/*nothing to see here yet*/
}
.Video-footer {
position: absolute;
bottom: 0px;
left:0px;
}
I've noticed while inspecting the code in google chrome that the divs all have a width but no height. I think it has something to do with my positioning in CSS but I don't know exactly what I did do wrong.
How can I get this to like the picture I posted?
Any help is appreciated!
Thank you in advance
UPDATE!:
When I give the divs a static height I get the belonged result but how is it possible that I have to do so?
You've given position: absolute; for child elements like title1 and footer. But the immediate parent is position: static; so they were misaligned.
Other than that, instead of having margin-left for video-content, it's preferable to make it float left. it will be very generic and also can make it responsive easily.
.Video {
display:block;
position:relative;
margin-top: 100px;
}
.BlackRect{
Width:250px;
height:150px;
background-color:#000;
float:left;
}
.Video-content {
float: left;
position: relative;
margin-left: 10px;
height: 100%;
min-height: 150px;
}
.Titel {
color: #34495e;
display:block;
font-size: 25px;
margin-top: 0px;
}
.Video-footer {
position: absolute;
bottom: 0px;
}
DEMO
You've got compounded problems here. The first one is that elements that are position:absolute; do not create space inside their parent container. So first your a tag collapses because .Tite1 doesn't take up space, and then the .video-content container collapses because neither does .Video-footer. This equals zero height for that entire block.
Your second problem is that elements that are floated aren't by default considered in their parent's stacking context. So if all the elements in a parent are 'floated', the parent element has no height. This is the case for your .BlackRect element.
To break down:
<!-- no height because all children/grandchildren produce 0 height -->
<div class="Video">
<!-- doesn't create height because floated -->
<div class="BlackRect"></div>
<!-- doesn't create height because all children/grandchildren pos absolute -->
<div class="Video-content">
<!-- collapses because .Tite1 doesn't create height -->
<a href="#">
<!-- doesn't create height because position absolute -->
<h2 class="Titel">This is a video title..</h2>
</a>
<!-- doesn't create height because position absolute -->
<div class="Video-footer">
Gebruikersnaam
</div>
</div>
</div>
There isn't much to be done if all the elements in .Video-content are positioned absolute, but you can force .BlackRect to create space through a few different methods, the easiest is by applying overflow:hidden to the .Video wrapper.
.Video {
display:block;
position:relative;
margin-top: 100px;
overflow:hidden;
}
You do not need floats and the only absolutely positioned element should be the one you want at the bottom
.Video {
display: block;
position: relative;
margin-top: 100px;
}
.Video a {
text-decoration: none;
}
.BlackRect {
width: 250px;
height: 150px;
background-color: #000;
}
.Titel {
color: #34495e;
font-size: 25px;
font-style: italic;
}
.Video-content {
position: absolute;
left: 270px;
right: 0;
top: 0;
bottom: 0;
}
<div class="Video">
<div class="BlackRect"></div>
<div class="Video-content">
<h2 class="Titel">This is a video title..</h2>
<div class="Video-footer">
Gebruikersnaam
</div>
</div>
</div>
You're halfway there. Instead of floating .Titel you need to float the .Video-content, since it's a sibling of .BlackRect:
.Video-content{
float:left;
margin-left:20px;
height: 150px;
position:relative;
}
Notice I've given it a margin so the text stands off from the video, given it the same height as .BlackRect, and positioned it relative. I positioned it relative to do a little trick with the footer:
.Video-footer {
position:absolute;
bottom:10px;
}
This may have been where you were going with the absolute and relative positioning, but let me explain what I did anyway: When a parent div has a position of relative, any child div of the parent with a position of absolute and will be positioned absolutely within that parent container only (in other words, absolute relative to the parent, not to the page). It looks like that's what you were after, the code just needed to be simplified.
Everything else just needed to be simplified by removing unnecessary selectors:
.Video {
margin-top: 100px;
}
.BlackRect{
width:250px;
height:150px;
background-color:#000;
float:left;
}
.Titel {
color: #34495e;
font-size: 25px;
margin-top:10px;
}
/*to remove the underline*/
.Video-content a{
text-decoration:none;
}
Here's an updated jsFiddle
Did Few twerks and came up with this
Check Fiddle Fiddle
The CSS:
.Video {
position:absolute;
display:block;
background-color:gray;
width:100%;
height:60%;
}
.BlackRect{
Width:250px;
height:150px;
background-color:#000;
float:left;
}
.Titel {
color: #34495e;
display:block;
font-size: 25px;
float:left;
position:absolute;
top:0;
margin-left: 270px;
padding: 0;
}
.Video-content{
/*nothing to see here yet*/
}
.Video-footer {
margin-top:30%;
float:right;
}
Picture describes all. I know how to make this circular image. But still don't know the way to place the image like this. Circular Image should stay middle of the div, as the div's width change.
you have to set the parent element as relative (position:relative) the wrap your img in a div with an absolute position 50% left or right depending on you.
<figure>
<figcaption class="top">assassin's creed</figcaption>
<div><img src=http://www.pulpfortress.com/wp-content/uploads/2010/11/Ezio-Assassins-Creed.jpg /><div>
</figure>
Demo
figure{
width:400px;
height:300px;
background:#444;
position:relative;
}
figure div{
width:150px;
height:150px;
overflow:hidden;
border-radius:100%;
position:absolute;
bottom:-75px;
left:50%;
margin-left:-75px;
}
figure img{
width:100%;
height:160px;
}
figcaption{
width:100%;
text-align:center;
padding-top:40px;
color:white;
font-size:20px;
}
You could use position relative to shift the image from the bottom div over the boundary between the two.
CSS
.top {
background: grey;
height: 120px;
}
.bottom {
background: white;
text-align: center;
height: 60px;
}
.bottom > img {
position: relative;
top: -50%;
}
HTML
<div class="wrap">
<div class="top">HELLO PROGRAMMERS!</div>
<div class="bottom"><img src="image.png" /></div>
</div>
Say logo1 and logo2 is 100px long each and I want to cover half of the logo up.
Whats the best way and neatest way of making two logos over lap and making them in the center of page.
Put both your logos in a <div> and give it margin: 0 auto;.
Then give logo2 z-index: 1; so that it is layered on top of logo1.
Here's a JSFiddle demo.
Page:
<div class="center">
<img src="Link/To/Your/Image/For/Logo1" id="logo1" />
<img src="Link/To/Your/Image/For/Logo2" id="logo2" />
</div>
CSS:
.center {
width: 210px;
margin: 0 auto;
position: relative;
left: 10px;
}
#logo2 {
z-index: 1;
position: relative;
left: -10px;
}
If you make the logos overlap even more (e.g. move logo2 to overlap by 50px with left: -50px; then you must also change the position of the surrounding div to match the overlap with left: 50px;, so the the left positioning for #logo2 and .center should be the same but opposite.
One option is using the style position:absolute;. Following is an example.
<style>
.container{
border:solid 1px red;
text-align:center;
height:500px;
}
#logo1, #logo2{
width:100px;
height:100px;
display:inline;
position:absolute;
top:200px;
}
#logo1{
border:solid 1px green;
left:450px;
}
#logo2{
border:solid 1px blue;
left:540px;/*note 540 = 450 + (100 - 10)*/
}
</style>
Page:
<div class="container">
<div id="logo1"></div>
<div id="logo2"></div>
</div>
I have following html. How can I get this so that dragDiv is shown on top of the image?
<div id="pnlContainer" class="container">
<img id="cropbox" src='1.jpg' />
<div class="dragDiv" id="dragDiv">
</div>
</div>
.dragDiv {
width:400px;
background-color:transparent;
border:2px solid #CCCCCC;
position:relative;
left:20px;
top:20px;
padding:0px;
margin:0px;
height:50px;
}
Currently, you're actually moving the dragDiv down and away from the image. If you just change your code to -20px and -20px on the .dragDiv css, it will be over the image.
Or, you could give the "pnlContainer" relative positioning, then absolutely position both the "dragDiv", and the "cropBox" - you shouldn't need z-index - just by positioning, the div will appear over the image in this case.
Either way is just fine. Bottom line is - positioning them correctly in this case will get the div over the image.
<style type="text/css">
#pnlContainer {
position: relative;
}
#dragDiv {
position: absolute;
top: 0px;
left: 0px;
width:400px;
background-color: transparent;
border:2px solid #CCCCCC;
position:relative;
left:20px;
top:20px;
padding:0px;
margin:0px;
height:50px;
}
#cropbox {
position: absolute;
top: 0px;
left: 0px;
}
</style>
You could make sure one element appears above the other using the Z-index CSS property: