I was wondering, what is the best way (using html, css, and graphics) to create a web page whose top header section appears to be beveled, as opposed to straight across? Please see the below image as an example:
I'm not sure how to use images in a way such that they would expand/contract in accordance with different browser sizes/resolutions...
Can anyone offer me some help? Or perhaps point me to a resource?
Thanks!
You could use border-radius.
See my example on jsFiddle.
Mine is a cleaner version of #Alex's:
Live Demo
.head {
-webkit-border-top-left-radius: 40% 80px;
-webkit-border-top-right-radius: 40% 80px;
-moz-border-radius-topleft: 40% 80px;
-moz-border-radius-topright: 40% 80px;
border-top-left-radius: 40% 80px;
border-top-right-radius: 40% 80px;
background: blue;
height: 280px
}
<div class="head"></div>
It obviously won't work in IE.
You could use CSS3 or webkit-specific properties, but this is not well supported as far as cross-browser compatibility is concerned. If you want to support as many browsers as possible, your best bet would be to use a background image to achieve this effect.
Here's a cross-browser version, which i made with help of jquery. Basically, the script creates many spans, with white background and decreasing width.
You can play around with STEPS and FACTOR variables, which will change the result. The step function sets the easing of the curve. You may replace it later with better functions than mine, it's just an example.
var STEPS = 53;
var FACTOR = 5;
var $el = $('div.header');
var width = $el.outerWidth();
var $span = $('<span></span>');
for(i=0;i<STEPS;i++){
tmpWidth = stepWidth(i, width);
$span.clone().css({
'bottom': i + 'px',
'width': tmpWidth,
'left': (width - tmpWidth)/2
}).appendTo($el);
}
function stepWidth(i, width){
return -(1 / FACTOR * Math.pow(i, 2)) + width;
}
You can find the entire code (html + css on the Fiddle)
Here is another way of achieving this.
Draw an overlay with pseudo element with width and height larger than element itself.
Apply border-radius to create round effect and background-color.
Add overflow: hidden on parent to hide excess part.
Output Image:
body {
background: linear-gradient(lightblue, blue);
min-height: 100vh;
margin: 0;
}
.box {
position: relative;
margin: 5vh auto;
overflow: hidden;
height: 90vh;
width: 500px;
}
.box:before {
border-radius: 100% 100% 0 0;
position: absolute;
background: white;
bottom: -200px;
right: -200px;
left: -200px;
content: '';
top: 0;
}
<div class="box">
</div>
Related
I have a div and for some reason I cant reduce its margin.
HTML
<div class="activebombgame">
</div>
CSS
.activebombgame{
height: 82vh;
width: 5vw;
background: black;
margin: 0;
}
This is from google chrome developer tools(blue = div, orange = margin)
Whole source code: https://www.hastebin.com/tapodoyuke.xml
Your code works fine see the fiddle here. Probably a surrounding tag is restricting the resize. Try something like taking ".activebomb" outside like
<div class="sorrounding">
</div>
<div class="activebombgame">
</div>
It sounds like it's your body margin. Many pages have one set by default. See the test below for an example. When you first run it, the body has a default margin. Clicking the button will remove it and line your div up with the page edge.
function change() {
document.body.style.margin = "0px";
}
.activebombgame{
height: 82vh;
width: 5vw;
background: black;
margin: 0px;
}
body {
background-color: lightgray;
}
button {
position: fixed;
left: 40%;
top: 20%;
}
<div class="activebombgame">
</div>
<button onclick='change();'>Remove Body Margin</button>
#Nisarg Shah,
You have added one extra closing div at the end, that's why your css is not working properly. Remove that extra closing div and run it.
I'm pretty novice when it comes to styling.
I have a web app (built with GWT) where I'm presenting a grid of results, and in one column, I want to display a visualization of a score, where there's a center black line, and either a green rectangle to the right for a positive score, or a red rectangle to the left for a negative score. The size of the rectangle indicates the value of the score. Something like this:
I have a div for the entire cell; I think what I need to do is add two sub-divs, somehow draw the center line, and then add the rectangle to the appropriate div. I"m just a little confused about how to do all that.
I have this:
#Override
public SafeHtml getValue(SearchResult value) {
SafeHtmlBuilder sb = new SafeHtmlBuilder();
float ratio = value.getRatio();
sb.appendHtmlConstant("<div style='width: 100%; height: 100%; position: relative;'>");
if (ratio > 0) {
sb.appendHtmlConstant("<div style='position: absolute; left: 0; top: 0; width: 100%; z-index: 1'><div style='display: inline; float: left; width: "
+ ratio
+ "%; height: 20px; background-color: #82cd80;'></div>");
}
else {
sb.appendHtmlConstant("<div style='display: inline; float: right; width: "
+ ratio
+ "%; height: 20px; background-color: #c54c4d;'></div>");
}
sb.appendHtmlConstant("</div>");
sb.appendHtmlConstant("</div>");
return sb.toSafeHtml();
}
But it doesn't draw anything. I'm very confused.
You should have two divs per graph. One goes around the whole graph (like a cover) while the other just goes around the bar itself for the graph. The cover is how you'll get your line. Set a border right on it so it should look like this:
border-right: 2px solid color;
(For the other graph just do border left)
Now I'm not sure on what you're using as I've never used "SafeHtml" but it looks like it's using the basic HTML features throughout so as long as you know where to place it this should be fine.
I'm trying to get a vertical-align to work on a div whose display is table-cell.
See http://jsfiddle.net/midnitesonnet/Rwahk/ for html/css.
I can't seem get the to display vertically align to the bottom. Any help would be much appreciated.
Thanks.
You define display:table-cell & position:absolute which create a problem. Just remove your .title DIV height.
#whats_available .title {
position: absolute;
z-index: 1000;
bottom: 0;
left: 0;
text-align: center !important;
width: 100%;
color: #fff;
}
Check this http://jsfiddle.net/Rwahk/5/
http://jsfiddle.net/Rwahk/7/ works as you wanted...
The changes made were to add display: table; to the #whats_available > div and to change the .title to position: relative;
You should change the height of the inner div to something like 30px instead of 100%
http://jsfiddle.net/Rwahk/4/
You shouldn't use dimensions attributes in pure html (the only exception could be image but it's still a bad idea).
I wrote this small jQuery function which might comes in handy to you or to other readers.
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
return this;
}
use:
$(selector).center();
Enjoy and have a great day :)
I want to increase a size of image which is used as cursor.
Currently i am not able to put image more than 128 by 128.
But i want to put it with more size.
so how to do that?
I am using
cursor: url(hand.png), auto;
You can combine css + jQuery if necessary, even if combining them is not always perfect:
JSFiddle example:
http://jsfiddle.net/n4Zbr/258/
Local example:
$(function(){
var $cursor = $('#huge-cursor');
$(document).bind('mousemove',function(e){
$cursor.css({
left: e.clientX - 15,
top: e.clientY - 15,
});
});
});
body, html {
width: 100%;
height: 100%;
margin:0; padding:0;
cursor: url("data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"), auto;
}
#huge-cursor {
position: fixed;
border-radius: 10% 90% 50% 50% / 10% 50% 50% 90%;
background: yellow;
width: 200px; height: 200px;
border: 4px solid pink;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="huge-cursor"></div>
<br><br><br><br><br><br><br><br><br><br><br>LONG<br><br><br><br><br><br><br><br><br><br>CONTENT
<br><br><br><br><br><br><br><br><br><br><br>LONG<br><br><br><br><br><br><br><br><br><br>CONTENT
<br><br><br><br><br><br><br><br><br><br><br>LONG<br><br><br><br><br><br><br><br><br><br>CONTENT
<br><br><br><br><br><br><br><br><br><br><br>LONG<br><br><br><br><br><br><br><br><br><br>CONTENT
<br><br><br><br><br><br><br><br><br><br><br>LONG<br><br><br><br><br><br><br><br><br><br>CONTENT
With CSS? I am afraid it can't be done. I think you should try to use some software which can edit icon file and re-size it.
You can use CSS (or JavaScript) to hide the 'real' cursor. Then create a div with the background and size of the new cursor which will reposition itself to where the 'real' hidden cursor is every time the mouse moves. Basically it will look like a real cursor but the disadvantages to this is that i don't think the hide cursor CSS property works in the browser Opera. If you are interested in this method, let me know I will post it up once I'm near a computer (not on an iPad)
I've searched around quite a bit and I'm fairly certain this doesn't exist, I'm mainly looking to confirm that. What I'd like to do is have a div that makes everything behind it transparent -- similar to what canvas' destination-out compositing option does.
For a little more context, here's the situation. I have an OpenGL window drawing behind a QtWebKit overlay. The OpenGL window has multiple "subwindows" that can be overlapping, which are decorated using the WebKit overlay. When they overlap though, because of this two layer system, the decorations for the overlapped windows do not get occluded.
The backup option is just to use a full-window canvas for this (the window trimmings are fairly simple), but it would be nicer not to. Note that because this is an embedded WebKit instance, it doesn't need to be cross-browser, and something WebKit (or QtWebKit) specific is fine.
EDIT
I can't answer my own question within 24 hours, so here's my solution, with thanks to #Kevin Peno
The following is a simplified version of what I was looking for. It creates two divs "visible" and "invisible". "invisible" masks off "visible" so that it displays the background image behind it instead of the "visible" div.
The real keys are -webkit-mask-image (http://www.webkit.org/blog/181/css-masks/) and -webkit-canvas (http://www.webkit.org/blog/176/css-canvas-drawing/), so this will only work with webkit-based browsers.
HTML:
<html>
<body>
<div id="visible"/>
<div id="invisible"/>
</body>
</html>
JavaScript:
function updateMask()
{
var w = $("#visible").width();
var h = $("#visible").height();
var context = document.getCSSCanvasContext("2d", "mask", w, h);
context.fillStyle = "rgba(255, 255, 255, 1.0)";
context.fillRect(0, 0, w, h);
var my_off = $("#visible").offset();
var inv_off = $("#invisible").offset();
var rel_left = inv_off.left - my_off.left;
var rel_top = inv_off.top - my_off.top;
context.clearRect(rel_left, rel_top, $("#invisible").width(), $("#invisible").height());
}
$(window).ready(function()
{
updateMask();
$("#invisible").draggable();
$("#invisible").bind("drag", function(e, ui)
{
console.log("drag");
updateMask();
e.preventDefault();
});
});
CSS:
body
{
background-image: url(http://www.google.com/images/logos/ps_logo2.png);
}
#visible
{
position: absolute;
background-color: red;
z-index: 0;
width: 1000px;
height: 1000px;
top: 0;
left: 0;
-webkit-mask-image: -webkit-canvas(mask);
}
#invisible
{
position: absolute;
z-index: 1;
width: 100px;
height: 100px;
top: 50px;
left: 50px;
cursor: move;
background-color: rgba(0, 255, 0, 0.5);
}
Here's a blog post about using css to apply an image mask to an element. It sounds pretty close to what you are looking for or will at least be good for some ideas. Let me know how it works out.
CSS Masks