The 'close window' image loaded by the code below is meant to be clickable.
When the page loads, everything displays properly but the area that is clickable is just a couple of pixels wide, a pixel or two high and just below and just above the centre of the image. I've included snips of code and relevant css.
All works just fine with IE9 in IE9 mode (the entire image is clickable). But the symptom I mentioned - the microscopic clickable area that isn't on the image occurs in Firefox 7, Chrome, Safari and Opera.
I've tried using an onclick in the image and tried putting the class declaration in the link tag but the same thing happens. I've also tried:
a {
display: block;
border: 1px solid white;
text-align: center;
}
I suspect I'll feel quite dumb when one of you points out the error of my ways.
I'm stumped.
.advCloser {
float: right;
padding: 5px 5px 0px 0px;
}
.advTitle {
position: relative;
top: -10px;
font-size: 125%;
padding: 0px 0px 0px 5px;
color: DarkBlue;
}
<div><img src="images/closeWindow.png" alt="Close window" class="advCloser"/><br/><div class="advTitle">Advanced configuration page</div></div>
You might get better results if you float the a tag, and not the image, also I would set the a tag to be a block with the same width and height as the image. This should make it work consistently with all browsers.
<style type="text/css">
.advCloser {
display: block;
height: 50px; /* set to the height of the image.*/
width: 50px; /* set to the width of the image.*/
float: right;
padding: 5px 5px 0px 0px;
}
.advTitle {
position: relative;
top: -10px;
font-size: 125%;
padding: 0px 0px 0px 5px;
color: DarkBlue;
}
<style>
<div>
<a class="advCloser" href="javascript:advConfigPageOpen();">
<img src="images/closeWindow.png" alt="Close window" />
</a>
<br />
<div class="advTitle">Advanced configuration page</div>
</div>
A slight alternative, without editing your existing classes may work as well:
<style type="text/css">
.advCloser {
float: right;
padding: 5px 5px 0px 0px;
}
.advTitle {
position: relative;
top: -10px;
font-size: 125%;
padding: 0px 0px 0px 5px;
color: DarkBlue;
}
.block-link {
display: block;
height: 50px; /* set to the height of the image.*/
width: 50px; /* set to the width of the image.*/
}
<style>
<div>
<a class="block-link" href="javascript:advConfigPageOpen();">
<img src="images/closeWindow.png" alt="Close window" class="advCloser" />
</a>
<br />
<div class="advTitle">Advanced configuration page</div>
</div>
Try adding a width to the image. Hopefully that will give the link tag something to work with in the compliant browsers.
Related
I've only recently really gotten into trying to learn how to do web-development, and the reason I actually got into it, was because I was incredibly curious on how to make this: https://imgur.com/a/dvghHmD.
Not the chat, but in the bottom-left, you can see what I'm looking at. I'd really like to make something similar, with a drop-shadow. Currently, this is what I got:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
}
<style>
.rectangle {
height: 100px;
width: 400px;
background-color: #FFFFF;
border-radius: 15px;
position: fixed;
bottom: 0;
margin-bottom: 2.5%;
margin-left: 2.5%;
}
.rectangle {
-webkit-box-shadow: 0px 0px 53px 0px rgba(0,0,0,0.24);
-moz-box-shadow: 0px 0px 53px 0px rgba(0,0,0,0.24);
box-shadow: 0px 0px 53px 0px rgba(0,0,0,0.24);
}
.rectangle class = "full-height"
#rectangle {
}
</style>
<style>
.text {
color: #151515;
text-align: left;
width: 300px;
font-family: 'Roboto', sans-serif;
position: absolute;
bottom: 0;
margin-bottom: 2%;
margin-left: 6%;
</style>
</head>
<body>
<div class="rectangle"></div>
<div class="text"> </div>
<div class="text"><span class="text"> <h2 style="font-size:21px"> This is a test text! This text is quite fine. I have no idea what I'm doing. <h2> </span>
</div>
</body>
</html>
Okay, so, you can most likely tell I have no clue what I'm doing. I've really been enjoying working on this, but I still have no clue really how to do a lot of things. Here are a few of those things:
How do I make a box like this always appear responsively to the size of the screen?
How do I 'parent' the text to the box, so that the text scales according to the box, and not independently? I don't know how to better describe it.
Would there be a more effective way of going about this (or have there been made any github depositories that already made this, so I could take a look at that code)?
To any of you who see this, thank you so much for reading. I really appreciate any help!
You can use relative positioning for sizing the box according to the screen
OR
You can use 'Responsive Media Queries'(https://www.w3schools.com/css/css_rwd_mediaqueries.asp)
For scaling text according to the popup, you may use the 'rem' unit is CSS. What it basically does is it scales your text according to the size of the parent.
Check this link: (https://css-tricks.com/almanac/properties/f/font-size/)
Hope this helps. :)
Before diving into CSS, first structure your HTML appropriately. You ask about parenting items and that's done with wrapping things with opening/closing tags:
HTML:
<div id="message_container">
<div id="message_content">message</div>
</div>
CSS:
With your HTML proper, then you work on styling:
#message_container {
/* to position it at bottom-left (dependent on the parent) */
position: absolute;
bottom: 2em;
left: 2em;
/* to position the contents within the box (ie the message text) */
display: flex;
justify-content: center;
align-items: center;
/* to style the message box in particular ways */
padding: 2em;
border-radius: 40px;
box-shadow: 4px 4px 20px rgba(0,0,0,0.3);
width: 100%;
max-width: 200px;
}
Responsive optimization:
Once your structure (HTML) and style (CSS) are solid, then you can think about responsiveness. To do this, you'd want to be exploring CSS #media rules to change the box style properties according to some conditions (e.g. screen width). Its all subjective, so you have to trial-and-error yourself to clean up the layout at different screen sizes.
For example:
/* for screens smaller than 320px width */
#media (max-width: 320px) {
/* make the message slimmer, and center it */
#message_container {
padding: 0.5em;
padding-top: 1em;
padding-bottom: 1em;
left: 50%;
transform: translate(-50%,0);
}
/* make the message text smaller */
#message_content {
font-size: 0.9em;
}
}
Controlling the box:
If you want this box to appear-and-disappear according to different events (like 2 seconds after the page fully loads, or when the user clicks something elsewhere), then you'll be looking at using Javascript. There's plenty of tutorials for that.
This is the general process.
Codepen
#message_container {
/* to position it at bottom-left (dependent on the parent) */
position: absolute;
bottom: 2em;
left: 2em;
/* to position the contents within the box (ie the message text) */
display: flex;
justify-content: center;
align-items: center;
/* to style the message box in particular ways */
padding: 2em;
border-radius: 40px;
box-shadow: 4px 4px 20px rgba(0,0,0,0.3);
width: 100%;
max-width: 200px;
}
#media (max-width: 320px) {
#message_container {
padding: 0.5em;
padding-top: 1em;
padding-bottom: 1em;
left: 50%;
transform: translate(-50%,0);
}
#message_content {
font-size: 0.9em;
}
}
<div id="message_container">
<div id="message_content">message</div>
</div>
As you can see in the picture above, the image on the right side is somehow not stretching to the full parent height. Why is this and how can I, without defining a specific height for the parent, always make sure that the image stays on the very edges of the parent? That is, without using background-size: cover; or any CSS pertaining to removing the img tag.
I've tried using this thread: click here
However, I turned unsuccessful.
HTML
<div class="scheme center-center">
<div class="superintendent center-center">
<div class="details">
<div class="hero hero-initial">
<div class="container">
<div class="wrapper text-center">
<div class="hero-header">
<h1>Welcome back!</h1>
</div>
</div>
</div>
</div>
<form class="form" action="#" method="post">
<div class="container">
<label for="author-name">Author's Name</label>
<input type="text" placeholder="John Doe"name="author-name" required>
<label for="password">Password</label>
<input type="password" placeholder="Password" name="author-name" required>
<input type="submit" class="submission" value="Continue from where you left off">
</div>
</form>
</div>
<div class="graphics">
<div class="hero-img scheme-img">
<img src="/assets/img/about-us1.jpg" width="100%">
</div>
</div>
</div>
</div>
CSS
.scheme {
height: 940px;
width: 100%;
background-color: #f2f2f2;
}
.superintendent {
width: 900px;
height: auto;
border-radius: 5px;
background-color: #fff;
-webkit-box-shadow: 3px 6px 30px -2px rgba(0,0,0,0.51);
-moz-box-shadow: 3px 6px 30px -2px rgba(0,0,0,0.51);
box-shadow: 3px 6px 30px -2px rgba(0,0,0,0.51);
}
.details {
float: left;
width: 60%;
height: inherit;
}
.graphics {
float: right;
width: 40%;
height: auto; /* Same height as the image currently in use */
}
.scheme-img {
width: auto;
height: auto;
}
.hero-initial {
height: auto;
padding: 30px 0 0;
}
.hero-initial h1 {
font-size: 2.4em;
font-weight: 500;
}
.form {
max-width: 400px;
height: inherit;
margin: auto;
padding: 0 0 30px 0;
}
label {
padding: 15px 0;
display: inline-block;
font-weight: 600;
letter-spacing: 0.4px;
font-weight: 400;
}
input[type=text], input[type=password] {
width: 100%;
padding: 15px 10px;
display: inline-block;
font-size: 1em;
border-radius: 5px;
background-color: #f2f2f2;
border: 1px solid #f2f2f2;
outline: none;
}
input[type=submit] {
width: 100%;
display: inline-block;
text-align: center;
padding: 15px 10px;
font-size: 1em;
cursor: pointer;
margin: 35px 0;
transition: 0.2s ease-in-out;
}
I will be happy to assist anyone further in clarifying this question!
The answer was found due to a new perspective of things: instead of seeing that the child didn't stretch to the parent. I thought why the parent went beyond the child. And thanks to the wonderful #PeeHaa, I was able to find an answer.
The img tag is an inline element, making it display: block; will suffice, and the child will stay within the designated perimeter (parent).
Good luck to you all, and happy coding!
Maybe you would like to remove the image tag and have the image as the background of the .scheme-img div. You can set background-size:cover to have the image covering all edges. Please note that this solution may cause blurry image if the image isn't large enough that it has to be enlarged to fit the .scheme-img div.
Btw, i can't seem to see why you have to add both .hero-img and .scheme-img tags to the div. If it is not needed, you are suggested to simplify it.
What about adding below CSS and removing your <img> tag? -
.hero-img {
background:url('/assets/img/about-us1.jpg');
background-size:cover;
}
Note: Above will cover your entire div having hero-img class with the image you want, edge-to-edge. But it comes with a caution that your div's size may change depending on the device screen size and also image may be of different aspect ratio than your div so in those cases stretching the image will make it lose its aspect ratio.
This will work.
You can use JavaScript. Here is your code. But before this please create an id of your img tag and place it's value as img. Also, create an id of the div whose size height you want to set as the the height of your image and place it's value as y .
<script>
var a = document.getElementById("y");
var b = document.getElementById("img");
var c = a.offsetHeight +"px";
b.style.height = c;
</script>
I request that you either vote or add a comment for this answer.
I have an svg img I got from thenounproject.com (don't worry, I have a place on my site where I give credit to the creators of the images) which I have inside a div. I have set the CSS of the div to have overflow: hidden; however the img is stickout out of the bottom, changing the height of the containing div above the div the svg img is contained it.
Here is the photo of the end result so far (the blue overlay is the <img> object being viewed with firebug so you can see how it is sticking out beyond the white div containing it)
the code I have is:
HTML
<div class="dropdown">
<div class="box edit"><img src="../media/gear.svg"/></div>
</div>
CSS
.dropdown .box{
width: 32px;
height: 32px;
padding: 5px 0px;
margin: 0px 4px;
display: inline-block;
background-color: white;
overflow: hidden;
font-size: 1em;
font-weight: bold;
text-align: center;
border: 1px solid transparent;
border-radius: 2px;
cursor: pointer;
}
.box.edit{
float: right;
padding: 0px;
}
I'm trying to get it so that the "blueish" overlay in the photo, which represents the svg img, does not extend beyond the white box
UPDATE
Thank you all for your answers. I though I would update this to narrow down my question now that I have gotten your feedback. I've tried removed float: right; and the other ideas (remove the border: 0px solid transparent;) but, while helpful, they did not solve the problem.
I currently have transform: rotate(90deg); applied to .box.edit so that way at least the overflow is inline with the rest of the .dropdown bar.
I've tried max-height: 100% and width: 100%; height: auto; etc. but that does not solve my problem. I do not need the entire svg in the box, only what you can see in the photo above (the gear). The part below that has copyright bit from thenounproject.com (see my above statement, I am still following their rules on using photos).
I don't know if I will need to edit the svg file or what, but I was trying to use overflow: hidden; to cut off the end bit (so it does not affect my spacing).
Thank you for your assistance so far.
try this remove border
.dropdown .box{
width: 32px;
height: 32px;
padding: 5px 0px;
margin: 0px 4px;
display: inline-block;
background-color: white;
overflow: hidden;
font-size: 1em;
font-weight: bold;
text-align: center;
/*border: 1px solid transparent;*/
border-radius: 2px;
cursor: pointer;
}
Remove the float from .box and use display: inline-block instead
Hi he is working and now you can define your img css width and height 100% as like this
.dropdown .box > img {
vertical-align: top;
width: 100%;
height: 100%;
}
.dropdown .box{
width: 32px;
height: 32px;
padding: 5px 0px;
margin: 0px 4px;
display: inline-block;
background-color: white;
overflow: hidden;
font-size: 1em;
font-weight: bold;
text-align: center;
border: 1px solid transparent;
border-radius: 2px;
cursor: pointer;
}
.box.edit{
float: right;
padding: 0px;
}
.dropdown .box > img {
vertical-align: top;
width: 100%;
height: 100%;
}
<div class="dropdown">
<div class="box edit"><img src="http://i.stack.imgur.com/8wc74.png"/></div>
</div>
So unless I am reading this wrong the height and width attribuite would work wouldn't it?
Code would be like this and then you would just adjust the height and width according to what you would need..
<div class="dropdown">
<div class="box edit"><img src="../media/gear.svg"/ height="42" width="42"></div>
</div>
As of now your image height is exceeding more than the height of its container due to which it is showing overlay going out of its container. Well applying max-height:100%; to image will make your image to stay within it's parent container, so give it a try.
I have finally found what the problem was with this:
Upon further research, I found that a <svg> has an attribute called "viewBox," which controls how much of the <svg> is shown. The <svg> I was using had a viewBox setting of "0 0 100 125," which basically means the width of the <svg> was 100 and the height 125. Upon finding this, and reducing the height to 100, the <svg> became a proper square and did not stick out further than it's containing div.
Thank you everyone for your answers, a lot of them were good and helpful.
i have a webpage and use the <hr> tag for separation of content when the page is displayed on tablets. it look like this:
at the red rectangle the line should continue. however, it does not. what do i have to change in html/css in order to let the <hr> continue until the border of the page?
the page is here: http://crossroads-festival.org/test2015/en/film/almaen
please note to redue the browser width to at least 811px for the horizontal line to show up.
thanks for your help!
UPDATE:
the css for <hr> is
hr {
height: 0;
border: none;
border-bottom: 1px solid #c1c1c1;
margin-bottom: 1.5em;
background: none;
}
the css for the divider-mobile class is:
.divider-mobile {
margin-top: 3.125em;
margin-bottom: 3.125em;
overflow: visible;
border: none;
color: #888888;
background-color: #888888;
height: 1px;
width: 150%;
margin-left: -25%;
}
in the html i use it like this:
<hr class="divider-mobile">
In your CSS you have:
#filmcontent {
overflow-x: hidden;
}
That is preventing the negative margin on your <hr> from going to the edge of the page.
You'll also want to remove the width: 150%; and margin-left: 25% on the <hr> and instead do...
margin-left: -20px;
margin-right: -20px;
(Where 20px is equal to the padding on #content .entry-content)
That will get you your desired effect!
I have a few Links/images sitting side by side in a container.
The container has its overflow property set to overflow: hidden and the images are 'sunken' into the container using margin-top: -50px;.
When the user hovers over the link I want the image to slide down out of the container and when the user hovers out the image jumps back up.
Here is a demo of what I have currently.
Here is my css ( I will post it all in case there are problems somewhere else that is causing this)
html, body {
width:100%;
height: 100%;
margin:0;
padding:0;
}
#w {
display:table;
width: 100%;
height: 100%;
}
#iw {
display:table-cell;
text-align:center;
vertical-align:middle;
width: 100%;
}
#iiw {
border-top: 1px solid #000;
height: 125px;
overflow: hidden;
}
#iiw a {
margin-left: 8px;
margin-right: 8px;
}
#iiw a img {
margin-top: -50px;
height: 100px;
-moz-box-shadow:0 0.8em 1em #444;
-webkit-box-shadow:0 0.8em 1em #444;
-o-box-shadow:0 0.8em 1em #444;
box-shadow:0 0.8em 1em #444;
-moz-border-radius:0 0 10px 20px;
-webkit-border-radius:0 0 10px 20px;
-o-border-radius:0 0 10px 20px;
border-radius: 0 0 10px 20px;
}
and html HTML markup is
<div id="w">
<div id="iw">
<div id="iiw">
<a href="#">
<img src="http://stackoverflow.com/content/stackoverflow/img/apple-touch-icon.png" />
</a>
<a href="#">
<img src="http://programmers.stackexchange.com/content/programmers/img/apple-touch-icon.png" />
</a>
</div>
</div>
</div>
I'm using JQuery right now to do the hover events (for ease of use), however the final product will have no JQuery (so don't comment on the JQuery code)
Edit I realize I left that code out.. oops.
very simple stuff. just using it to swap the margin-top property
$("a").hover(function() {
$(this).children().css("margin-top", "-2px");
}, function() {
$(this).children().css("margin-top", "-50px");
});
#iiw a {
display: block;
float: left;
}
Them a tags need to be block level.
It appears that elements that share the same line will align themselves with the lowest element in that line. When you set the top margin of an image to be much lower than the rest, the other images will drop down so their bottom edges align with it.
To avoid this behavior, try adding vertical-align:top; to your #iiw a img block. I've applied the change to your example here.