My web application is only required to support modern browsers (IE starting at 10). But it has to be fully responsive, so it should look good on all possible display sizes and resolutions.
It has the standard logo in the upper left corner, which is linked to the start page. I want to use an SVG logo, which should look good at any resolution. At first, I had the logo in a normal <img> tag, with height and width specified in css.
<a href="#Url.Action("Index", "Home")" id="Home">
<img id="logo" src="~/Content/images/mitoLogo.svg" />
</a>
#logo {
height: 3em;
width: 9em;
margin: 0.3em 1.5em 0.3em 0.2em;
}
Sadly, IE cannot work with that and clips the logo instead of stretching it to the given size. So I looked around and found this suggestion for placing an SVG image in a page. What I have now is
<div id="logo">
<a href="#Url.Action("Index", "Home")" id="Home">
<object height="100%" width="100%"
data="~/Content/images/mitoLogo.svg" type="image/svg+xml">
</object>
</a>
</div>
This displays the image properly in both IE and Firefox (haven't tried other browsers yet), but the link only works in IE. Neither in IE nor in Firefox does the cursor change to a clicking hand, and FF with AdBlockPlus shows a "block" suggestion on hover, possibly because this is an object tag.
Is there a way to display the SVG image correctly everywhere, while preserving its link function? I'm not limited to css, but can do radical changes to the markup, if needed, and I can also change the SVG source.
I played with your initial code a bit and got it working... it seems that you need to only set the width as a percentage and it will scale the height appropriately.
#logo {
width: 25%;
}
Try changing the percentage and adjusting the result window size in the JSFiddle Demo
I tested it in IE10 (+ IE9 in the emulator) and Chrome and it worked exactly as expected.
Related
I'm writing an ebook in HTML and converting to MOBI with Kindlegen. I want to make sure the images never take up the whole page. However some images are doing just that.
I've tried multiple CSS styles but nothing seems to change. I'm testing on Kindle Previewer, iPhone X, kindle paper white (older device) and iPad. All these devices seem to react to CSS differently and the iPad seems to completely ignore my image styles. No matter what I set the iPAD images don't change. How can I make sure the images are never too large? I want the image to be small enough so that text is also on the same page. Ideal never larger than about 30% of the screen.
I've tried setting a percentage
width: auto;
height: 30%;
and setting em
width: auto;
height: 20em;
I get an error from Kindlegen if I use max-height
.image {
width: auto;
height: 30%;
}
.centerImg {
text-indent: 0;
margin: 1em 0 0 0;
padding: 0;
text-align: center;
}
<!-- Page 29 -->
<p class="centerImg">
<img class="image" alt="lock" src="images/page29.jpg" />
</p>
<p class="collector">
Text
</p>
<br />
<p class="description">
Text
</p>
<div class="pagebreak"></div>
What's the best way to do this?
CSS with ebooks on Amazon can be a bit daunting. I've even seen major bestsellers where the layout didn't work out as intended. Although I've never gotten an ebook to look exactly the same across all devices, I have been able to size my images satisfactorily. I use the free program Sigil for editing, then convert to .mobi with Calibre.
Because CSS can be so unreliable on ebooks, I sized the image in the HTML itself:
<div align="center"><img height="148" src="../Images/stars-300.jpg" width="200"/></div>
<br/>
<h1 class="cinz" id="sigil_toc_id_21">-21-</h1>
<br/>
<h1 class="toocinz sigil_not_in_toc">Between Worlds</h1>
Below is an image of the above code on Kindle Paperwhite. On the iPad, the image is a bit smaller, and some of the spacing is different, but it looks close enough. Another trick I've used to 'force' the ebooks to use your styling, is to use two CSS stylesheets. The first one simply refers to the second, "real" one. This can get around some of the default styles that override custom styles. I'm not sure how well it's worked, but it hasn't hurt:
Style0001.css has only this line:
#import url(../Styles/Style0002.css);
Style0002.css is where all my actual styling is. All my book pages link to the first stylesheet:
<link href="../Styles/Style0001.css" rel="stylesheet" type="text/css"/>.
I have a web page with a text box. The background is black and the text is white. It displays correctly in Chrome and Safari, but for some reason the display is way off in Firefox. For arguments sake that could be reversed, that it is correct in Firefox but not Chrome or Safari - I am just going with the majority for now.
Here is the HTML:
<div class="col-sm-6 black">
<p style="text-align:center">Each unit is full of character and convenience with original hardwood floors, 10’ ceilings, washer/dryer and walkability to local restaurants and shops. </p>
<p style="text-align:center">Rents range from $825 – $950/month.</p>
<p style="text-align:center">Call us to reserve your unit: </p>
<p class="estilo big" style="text-align:center">919-292-2200</p>
<p class="estilo" style="text-align:center">or through Facebook messenger.<br />
facebook.com/thelutterloh</p>
</div>
Here is the CSS:
.black { background-color: #000; padding: 15px 15px 65px 15px; }
This is how it looks in Chrome and Safari:
This is how the same code renders in Firefox:
I have looked extensively for a solution and have have seen nothing that would resolve this. Also, Mozilla does not have a -moz specific styling that can be applied.
Any help would be appreciated.
The inconsistency in the font-size seems to be causing the height of the .black div to increase in case of firefox (since the font-size appears to be higher). The padding added on top of this increases the total height of the div.
I would recommend using normalize.css or CSS resets before doing any of your styling to avoid such scenarios.
Another workaround is for you to set box-sizing: border-box and set a max-height on the .black div., along with overflow:hidden.
You can also use #font-face which will help keep your font consistent between browsers instead of the browser using its default. https://developer.mozilla.org/en-US/docs/Web/CSS/#font-face
In a smaller browser window the css moves in Safari It appears to look fine in other browsers except Safari
Take a look at http://tinyurl.com/mvkkcfg? In Chrome the Firefox - Then compare in Safari
I just need the OR image to stay in the same spot no matter what browser or window size is used
here is the code that Im currently using
<div style="z-index:10; position:absolute; margin-top:400px; margin-left:335px">
<img src="http://173.83.251.7/~iworeitb/wp-content/uploads/2013/06/or.png" alt="" />
</div>
Just tried option 2
I changed the code to as follows still no luck on a good position any other suggestions?
<div id = 'O' style="z-index:10; position:absolute; margin-top:20%; margin-left:18%">
<img name="" src="http://shopiworeitbe.../2013/08/or.png" alt="" /></div>
#O{
height: 100%;
max-height: 100%;
overflow: auto;
width: 100%;
http://tinyurl.com/mvkkcfg
Still not accurate
Please help thanks
You will have better luck using pixels or ems as opposed to percentages.
Percentages are dynamic and depend on the viewport whereas pixels and ems are static values and will deliver desired results.
Currently I'm getting like this in Chrome, Safari, Mobile Safari and Opera. edges are rough.
img {border-radius: 10px; border:3px solid red}
See this example in Google Chrome or Opera or iPad http://jsfiddle.net/4PLUG/2/show/
Borders are fine in Firefox.
and in IE9 border edges are fine but it has a different problem. it shows some space between border and images
How to get the result like Firefox in all other browser?
You can give extra div to your img tag like this:
body {padding:100px}
img {
vertical-align:bottom;
position:relative;
z-index:-1;
}
div{
overflow:hidden;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
border:3px solid red;
display:inline-block;
}
http://jsfiddle.net/4PLUG/4/
/* just make sure you're including border radius for all browsers rendering engines */
.img-border{
border-radius:15px;
-moz-border-radius:15px;
-webkit-border-radius:15px;
border:3px solid red;
}
all browsers have different CSS capabilities, and handle them differently.
if you want the corners to look exactly the same in all browsers, you'll just have to put the curves in the actual image, and not rely on CSS.
An alternative is to use a background image on a div instead, which may get better clipping.
You might want to try wrapping the images in a block element and floating 4 divs in all four corners with border images as a background. Make sure the image itself has an border as well, this makes using radius borders in images quite a lot easier if you have more than one size of images that needs 'm.
I've done this effect with two divs using z-index.
<div class="picture-wrapper">
<div class="mask">
</div><!-- end mask -->
<div class="picture">
<img src="" />
</div><!-- end picture -->
</div><!-- end picture-wrapper -->
Set your background image on mask to the red borders with the middle cut out (png), then use z-index to stack it above the picture div.
Should work cross browser, the only thing is it doesn't account for dynamic widths/height in the images, it assumes all images are the same. AND you're doing a request for that extra mask image.
Up to you.
for img tags , percent border radius work perfectly:
.roundcornerimg{border-radius: 50%;}
<img src='imageurl' class='roundcornerimg'/>
link the image in the body:
<img src="image.jpg">
add your sizing to the image:
<img src="image.jpg" width="100%" height="30%">
Then add in the inline CSS.
<img src="image.jpg" width="100%" height="30%" style ="border:solid thick black;border-radius="25px">
By adding in the inline CSS, the border and border radius will take effect on the image. Just dont style this particular image in the stylesheet because specificity may mess with the inline CSS.
I need to set up a website with a video as the background.
Will I be able to use z-index to position other elements on top of the video? Is there a better alternative?
I have not tested it, but you could try to set width/height of <video> to 100% then using z-index let all the others element stay on top of it...
Edit:
for example to set video as background entire page
<body style="height: 100%;width: 100%">
<div style="position: fixed; top: 0; width: 100%; height: 100%; z-index: -1;">
<video src="" width="100%" height="100%" autoplay>
Your browser does not support the video tag.
</video>
</div>
... rest of your site
You can not apply it as a CSS background (background property). You can give the effect though using layers which is controlled via the z-index property.
If you are using flash as your video playing method no - flash is ALWAYS on top of anything regardless of z-index, But I imagine this could be done by using the new HTML5 <video> tag.
Failing that convert to a high-frame rate animated image and set as BG...