I have a script for a popup which is meant to display a clickable image. My problem is I have to adjust the popup dimensions everytime I change the image. Is there a way the popup can adjust automatically based on the image dimensions?
popup.php
<?php
/** popup code **/
echo "
<div id='pop1' class='simplePopup'>
<div id='main' class='row'>
<div class='adimage' align='center'>
<a href='localhost/test/test_target.php' target='_blank'><img src='images/logo.png'></a>
</div>
</div>
</div>";
?>
CSS code:
body {
font-family: Arial;
font-size:14px;
}
.simplePopup {
display:none;
position:fixed;
border:4px solid #808080;
background:#fff;
z-index:3;
padding:12px;
width:50%;
min-width:70%;
}
.simplePopupClose {
float:right;
cursor:pointer;
margin-left:10px;
margin-bottom:10px;
}
.simplePopupBackground {
display:none;
background:#000;
position:fixed;
height:100%;
width:100%;
top:0;
left:0;
z-index:1;
}
You can adjust the image by width or by height. If you do both you will distort the aspect ratio (assuming you have images of different sizes).
For example, to keep a fixed width, set the width of the image container. You can use any unit you like, e.g.
.adimage {
width: 400px;
}
Then force the image to fit to its container:
.adimage img {
width: 100%;
height: auto;
}
For a consistent height you would use
.adimage {
height: 400px;
}
.adimage {
height: 100%;
width: auto;
}
If you need to target the outer containers you can try giving them fixed dimensions, and then applying 100% width to the inner containers:
.simplePopup {
width: 50%;
}
.adimage {
width: 100%;
}
.adimage img {
width: 100%;
height: auto;
}
If this isn't helpful please add a fiddle to your post and I'll take a closer look.
Related
I don't know if it is possible, but is it possible for a <span> of variable text length to be horizontally aligned over an image? The one catch with this, is I'd like the <span> to have a background color and the background color block should overlap the image.
I've tried setting the <span> to display:inline-block but it doesn't seem to end up horizontally aligned. Here is the code if you don't want to look in the fiddle (the HTML here should remain the same if-at-all-possible)
The Code (https://jsfiddle.net/6c9gmvom/1/):
#wrapper {
width:100%;
}
.txt {
text-align:center;
margin:0 auto;
width:40px; /* ideally I would not want to use a fixed width here */
background-color:#ffffff;
}
img {
height:30px;
width:100%;
}
<div id="wrapper">
<img src="http://seedmagazine.com/slideshow/the_long_shot/img/8_the_long_shot_ss.jpg">
<div id="modulewrapper">
<span class="txt">hey</span>
<div id="module"></div>
</div>
</div>
You can align it with css. I've updated your fiddle, check it out to see the result https://jsfiddle.net/6c9gmvom/8/
The css I've added is:
#wrapper {
width:100%;
position: relative;
}
#modulewrapper {
text-align:center;
position: absolute;
top:0;
left:0;
right:0;
}
You can set the image as a background image... then set the span to display block.....
#wrapper {
width:100%;
}
.txt {
text-align:center;
margin: 10px auto;
background-color:#ffffff;
display: block;
text-align: center;
} /* ideally I would not want to use a fixed width here */
img {
height:30px;
width:100%;
}
#modulewrapper {
padding: 200px 0;
background: url(http://seedmagazine.com/slideshow/the_long_shot/img/8_the_long_shot_ss.jpg) no-repeat center center; }
<div id="wrapper">
<div id="modulewrapper">
<span class="txt">hey</span>
<div id="module"></div>
</div>
</div>
I'm not too sure I understand what it is you are asking.
If im not mistaken what you want is for the text to be on top of the image.
This can be done as seen https://jsfiddle.net/6c9gmvom/9/
#wrapper {width:100%;position:relative}
.txt {
position:absolute;
text-align:center;
margin:0 auto;
width:40px;
background-color:#ffffff;
z-index: 100;
width:100%;
}
img {
height:30px;width:100%;
}
.imageClass{
position:absolute;
left: 0;
top: 0;
}
.txt {
text-align:center;
margin:0 auto;
width:100%;
background-color:#ffffff;
position: fixed;
left: 0;
top: 15px;
}
img {
height:30px;
width:100%;
position: relatable;
}
I want to put two images in one div. One remains up and other goes down. Both take around 25% width:-
<div class="images">
<div class="pics">
<img src="GRProvider/Img.jpg" />
</div>
<div class="pics">
<img src="GRProvider/Img_2.jpg"/>
</div>
</div>
CSS:
.images {
float: left;
width: 25%;
}
.pics {
float: left;
width: 12%;
margin: 0%;
}
images_img {
width: 100%;
}
Try this out using display:inline-block
CSS
.images {
display: inline-block;
width: 25%;
}
.pics img{
display: inline-block;
width: 100%;
}
DEMO HERE
Do you want the pics side by side? You only need one line of css:
.pics { display:block; float:left; }
http://jsfiddle.net/ve9ud2o4/1/
Or if you want the image container div to be 25% and the pictures to span the div you could do:
.images { background:red; display:block; float:left; overflow:hidden; width:25%; }
.pics { background:green; display:block; float:left; width:50%; }
.pics img { border:1px dotted black; display:block; width:100%; }
http://jsfiddle.net/ve9ud2o4/2/
Remember that .pics width is relative to it's container. So even though the .images div is 25%, if you want a pic to be half of that you set the .pics width to 50%
you can use display:block; to prevent line breaks and display elements in same line
Of course you can ajust your div width to fit the two images and float them as you wish
This question already has answers here:
div under another div
(6 answers)
Closed 7 years ago.
I am making a page and I need one div block to go under the other. I have a lot of different color divs, and when I use margin-top:100px(for example) for one div, and margin-top:200px for other div it looks ok on my computer but on the lap top completely different
--- 1st and 2nd divs are in the right place, but I have to put the 3rd one below the 2nd div. How can I do that?
Here is the pic:
Try setting your divs to "position:relative", then set z-index properties. The lower it's set the farther it's displayed...
Example :
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
Then your css :
.div1 {
position:relative;
z-index:1;
width: 100%;
height: 300px;
background-color: #eee;
}
.div2 {
position:relative;
z-index:2;
margin-top: -100px;
width: 100%;
height: 300px;
background-color: #f90;
}
.div3 {
position:relative;
z-index:3;
margin-top: -100px;
width: 100%;
height: 300px;
background-color: #ccc;
}
#container{
width:500px;
}
.innerdivs
{
width:100%;
float:left;
}
<div id="container">
<div class="innerdivs" style="background-color:#4C4C4C;"><h1>first div</h1></div>
<div class="innerdivs" style="background-color:#0087DE;"><h1>2nd div</h1></div>
<div class="innerdivs" style="background-color:#FFFF00;"><h1>3rd div</h1></div>
</div>
that is working perfectly in here
CSS
#wrapper{
width:100%;
max-width:460px;
}
.inline-divs
{
width:100%;
display:inline-block;
}
#div1{
height:50px;
background-color:#ff0000;
}
#div2{
height:150px;
background-color:#00ff00;
}
#div3{
height:300px;
background-color:#0000ff;
}
HTML
<div id="wrapper">
<div class="inline-divs" id="div1"></div>
<div class="inline-divs" id="div2"></div>
<div class="inline-divs" id="div3"></div>
</div>
JSfiddle Demo
https://jsfiddle.net/1tuj0c9a/2/
Hope you find this helpful!
I have added 3 different Div's with different colors one after another with 100% width. So it works without overlapping div's in mobile screens as well.
#container {
width:100%;
display:block;
}
.content1 {
width: 100%;
height: 100px;
background:pink;
display:flex;
}
.content2 {
width: 100%;
height: 100px;
background: blue;
display:flex;
}
.content3 {
width: 100%;
height: 100px;
background: yellow;
display:flex;
}
http://jsbin.com/nonufehuja/4/edit
If you want to add margin to entire page container
#container {
width:100%;
display:block;
margin-top:100px
}
http://jsbin.com/nonufehuja/5/edit
Margin for second div
.content2 {
width: 100%;
height: 100px;
background: blue;
display:flex;
margin-top:100px;
}
http://jsbin.com/nonufehuja/6/edit
Try to use CSS z-index property
For example, in styles, for div1 you should add
position:relative;
z-index:1;
For div2
position:relative;
z-index:2;
For div3
position:relative;
z-index:3;
I have the following problem:
I'd like to create a html page where a #sidebar spans a constant 27px and a #content spans the remaining part of the screen. The #content is divided into two areas splitting it at 40% - 60%.
<html>
<body>
<div id="sidebar">
</div>
<div id="content">
<div id="forty-percent">
</div>
<div id="sixty-percent">
</div>
</div>
</body>
</html>
I have tried to make the following css:
#sidebar{
width:27px;
}
#content{
position:absolute;
padding-left:27px;
width:100%;
}
But then I cannot divide the content into 40%-60%, because percentages are calculated from the width of the #content and not from its area inside.
What am I doing wrong? Can you please help?
UPDATE:
The demo of the NOT working version:
http://jsbin.com/iseqon/1/edit
Ideally the dashed boxes should be side-by-side, inside the blue box.
This may suit more your needs. If you want to have a better control of your #sidebar & #content vertical alignment, you must use inline-block to have a CSS only solution.
You can view it live here: http://codepen.io/jpsirois/pen/dvbmEy
* {
/* This prevent padding to be added on defined width */
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-size: 0; /* Need to be set to 0 to properly use inline-block here */
color: white; /* For a better preview purpose only */
}
#sidebar,
#content {
display: inline-block; /* Allow vertical-align control (float didn’t) */
font-size: 16px; /* Reset font-size to normal */
vertical-align: middle; /* Demo of vertical-alignement */
}
#sidebar {
width: 27px;
background: darkred;
height: 50px; /* For a better preview purpose only */
margin-right: -27px; /* This allow #content to be inlined aside */
}
#content {
font-size: 0; /* Need to be set to 0 to properly use inline-block here */
width: 100%;
padding-left: 27px;
}
#forty-percent,
#sixty-percent {
height: 100px;/* For a better preview purpose only */
display: inline-block;
font-size: 16px; /* Reset font-size to normal */
}
#forty-percent {
width: 40%;
background: darkgreen;
}
#sixty-percent {
width: 60%;
background: darkblue;
}
You need this to float the #sidebar and give an equal margin-left to the #content, and also float the two inner boxes so they can sit side by side..
#sidebar {
width:27px;
float:left;
}
#content {
margin-left:27px;
overflow:auto;
}
#forty-percent {
width:40%;
float:left;
}
#sixty-percent {
width:60%;
float:left;
}
and also to not use the # char in the actual id
Demo at http://jsfiddle.net/gaby/8a7CN/
(your fixed jsbin demo at http://jsbin.com/iseqon/4/edit you need to keep in mind that borders add to the width so it cannot work with percentages very well)
how about having a parent div that would be relative and then having the div inside float right or left with absolute position within container. when the parent container is pos relative and the child is pos absolute, the children with position with respect to their container. In other words, something like that (untested but should give you the right idea)
#wrapper {
position:relative;
width:100%;
margin:50px;
}
#leftCol {
width:60%;
background-color:yellow;
}
#rightCol {
width:40%;
position:absolute;
right:0px;
top:0px;
height:100px;
background-color:red;
}
</style>
<div id='wrapper'>
<div='leftCol'>
</div>
<div id='rightCol'>
</div>
</div>
I am using your HTML only change the CSS.
My CSS is
#sidebar
{
width:27px;
min-width:27px;
float:left;
}
#content
{
float:right;
width:100%-28px;
min-width:100%-28px;
}
#forty-percent
{
width:40%;
float:left;
}
#sixty-percent
{
width:60%;
float:right;
}
Hope this will help you.Thanks.
I have the following issue with css and was wondering whether there is a way to solve it by setting an absolute height value. The code I have is as follows,
<style type="text/css" media="screen">
html { height:100%; }
body { background: black; height:100%; }
#menud {
position:absolute;
padding:1em;
height:300px;
background-color:#eaeaea;
width:184px;
}
#menue {
position:absolute;
margin-top:300px;
padding:1em;
height:900px;
width:184px;
background-color:red;
}
#data {
position:absolute;
margin-top:0px;
margin-left: 184px;
width:630px;
height:600px;
border-left:1px solid #dedede;
border-right:1px solid #dedede;
}
#ad {
position:absolute;
padding:1em;
margin-top:0px;
margin-left:814px;
width:186px;
background-color:red;
height:800px;
}
#content {
width:1000px;
background-color:white;
height:100%;
}
#info {
margin-top:0px;
width:1000px;
}
</style>
<html>
<body>
<div id='content'>
<div id='info'>
<div id='menua'>test</div>
<div id='menub'>test</div>
<div id='data'>test</div>
<div id='ad'>test</div>
</div>
</div>
</body>
</html>
I have set the height property to 100% but this does not cover the whole background white as one would expect it to. Any help on this would be appreciated.
Thanx.
Setting the height to 100% means 100% of the current viewport height. If your page is longer than the browser viewport, the div is too short. Use auto height to let the height get calculated correctly for you.
Set the height of content back to auto (remove height: 100%):
#content {
width:1000px;
background-color:white;
}
and remove the position: absolute from your ad (or replace with position: relative), so that the ad's height is respected when calculating the parent's (#content's) height:
#ad {
padding:1em;
margin-top:0px;
margin-left:814px;
width:186px;
background-color:red;
height:800px;
}
now your content is as long as you would expect.
100% height is relative to the container. To cover the whole background, you will have to use javascript. On page load you set the height to the window height.
You can use jQuery, to do this: in that case
$("#content").css('height', $(window).height());
You might have to remove paddings and margins from the body, like body { margin: 0; padding: 0; }, for the relative-positioned container div to cover the whole height.