What is the easiest/best way to set the maximum width of a web page. For example assume I don't want to let the user to expand the width beyond 400px. HTML code, CSS, C#?
I am using Visual Studio 2008 C# environment.
Thanks
Bruce
If you want to limit the browser width, well you can't do that :P
Alternatively, if you want to limit a certain element's width, such as a div with an ID of #container, then you would use CSS:
#container {
max-width:400px;
}
Wrap the content of the page is some sort of container (a <div>) is usually suitable. Apply the max-width property to it.
Simply make a fixed width CSS layout set at 400px.
Trying to prevent the browser window to be greater than 400px is horrible idea, and will fail in more ways than it will work (mobile, etc).
Related
Basically, what I'm trying to do is get an image to represent a page (for quick browsing in a XAML GridView).
I have the pages URL (and it's HTML content), but now I'm not completely sure how to proceed. I could just use the Favicon, but I don't think that would scale well up to the 200x200 box I'm using to display it. The other option (as far as I can think of) is to look through the HTML source and pick out the largest image.
Is there an easier/simpler way to do that in C# other than just using Regexs to find the height/width of all the image tags and then comparing them?
Thanks!
There is no way to know for sure from the HTML source what size the images are. An img tag doesn't require the height and width parameters. If they're not specified, then the image is displayed in its actual size. If all the img tags on the page have their height and width specified, you could pick the one that has the largest values. But those are the display sizes. The actual sizes might be quite different.
The only way to be 100% sure is to download each image and get its size.
By the way, if you're parsing HTML, you probably shouldn't be doing it with regular expressions. I know it seems simple enough, but you're almost certain to get things wrong and not handle some common cases. You'll save yourself a lot of time and frustration by using something like the Html Agility Pack.
you can try
imageObject.ActualWidth
imageObject.ActualHeight
properties
I have a drop down list in asp.net. I want to increase its height. please suggest, how to icrease it.
There is a height property on the drop down list.
myDropDown.Height = 200;
BTW: There is pleny of information around on how to do it:
http://dotnetslackers.com/Community/forums/asp.net-dropdownlist-item-height/p/3151/31235.aspx
http://www.vbforums.com/showthread.php?t=419074
http://forums.asp.net/t/1300753.aspx/1
If setting the height property is not helping you,
One way of achieving this by increasing the font of the dropdown as it gets set based on the height of its contents.
Or you could set it via css (not sure will work in all browsers)
Please edit to describe your current scenario with some code
Set the Height property of the control
I'm creating an ASP.NET control that outputs <object> and <embed> tags. I want the control to have "Height" and "Width" properties, since both of those tags require them. I was also thinking of validating the height and width at runtime. I'm wondering exactly what the valid ranges are so I can be sure I have valid sizes.
These are the types of height and width settings I've seen before. Are these all valid? Where could I find all the accepted formats? Are there any values that are considered invalid, but are used as tricks for cross-browser compatibility?
1px
10%
99.99%
100
I may just go the route of letting the user input whatever they want in these fields, but now I'm curious.
See the W3C page for height under Property Values. To answer your specific question, all of those values are permitted. Omitting the px has no effect.
How can I set the dimensions of my root layout in the XAML to 100% width and height of the <object> tag that houses the Silverlight App.
I have tried specifying 100%, but the width and height properties only take unit literals (exact pixels). Is there a way I can have the Silverlight app take up all the available space in the <object> tag?
Right now (this could change in the version next of Silverlight), pretty much the only way to do this is figure out the dimensions in JavaScript on the page, then pass those to the Silverlight object.
One other option would be to use the Silverlight/JavaScript inter-op API
I'm trying to figure out if it's possible to calculate the area of a HTML element on a website? In pixels, as a percentage or whatever.
My first thoughts have been to make the assumption that the element is 100% in width and height, and then try to retrieve the size through a mapping between the HTML and CSS.
So if there's a width/height attribute in the referenced CSS-file I could possibly say that
the body element is covered by a column that takes 25% of the area (everything is based on your screen resolution of course - and I'm still trying to figure out how I'd be able to do this programmatically).
Or whether I should render the website and do my calculations based on an image with the most common screen resolution at the time).
Are there any more possible solutions?
(Currently I'm trying to solve this in Perl, but I suppose any language that's got a library for this purpose would be appreciated to know about!)
EDIT: I need to retrieve the visual area for every single element on a page.
For example; if there are elements on top of the <body> element, that covers it visually, I want to exclude that area from the <body>'s and so on. A simple raytracing to find the visible area for every element on a page.
EDIT: Let's say we exclude JavaScript - any other approaches possible?
Personally, I would use jQuery - even if you don't use a library, your best bet will be a JavaScript solution.
var $elt = $('#some-element-id'),
height = $elt.height(),
width = $elt.width(),
area = height * width; // contains the area in px^2
http://api.jquery.com/height and http://api.jquery.com/width
This is such a simple problem I don't think JQuery is necessary if you are not already using it.
Try running this:
<div id="myParent">
What's up?
<div id="myDiv">Hello there!</div>
</div>
With
var myDiv = document.getElementById("myDiv");
alert(myDiv.offsetHeight);
alert(myDiv.offsetWidth);
var myParent = myDiv.parentNode;
alert(myParent.offsetHeight);
alert(myParent.offsetWidth);
Divide resulting widths to get % of space the element takes in it's parent, or simply use the absolute pixel values.
I would recommend using jQuery to do it if possible.
alert('Size: ' + $('li').size());
http://api.jquery.com/size/
Would it be feasible to use javascript? If so you can get the width/height with something like this:
document.getElementById(YourElementsId).style.height;
document.getElementById(YourElementsId).style.width;
However this does depening on how the elements are sytled in the first place. Another option would be
document.getElementById(YourElementsId).clientHeight;
document.getElementById(YourElementsId).clientWidth;