I have a HTML element:
<div id=... class="pie-chart-container"></div>
I'm trying to change the size of this div depending on whether media type is screen or print.
Originally, my CSS styles defined the size of the screen version, and then #media print to change the size of the printed version. This wasn't working as I expected, so I swapped around the styles to define the print version, and then use #media screen to control the size of the screen version, as follows:
.pie-chart-container {
width: 20cm;
height: 25cm;
margin: auto;
}
#media screen {
.pie-chart-container {
width: 80vw;
height: 100vh;
}
}
However, this also seems to be behaving strangely, as when I change the width and height inside the media query, the dimensions of the div are changed in the print version (and also the screen version). Changing the width and height in the first selector, outside the media query, also has an effect on the printed version, but not in the same way as changing the values inside the media query - changing the values in the selector outside the query seems to increase the space the div takes up, without changing the size of the elements inside the div very much, although the elements inside do move around a little.
If anyone has any knowledge on what/why this is happening, I would be very greatful if you shared it.
Note: I am using Chrome's print preview to view the effects of the styles on the printed version.
Update: This div contains a Google Chart, so there is a massive amount of code inside. The top few levels look like this:
<div id="donutchart2" class="pie-chart-container">
<div style="position: relative">
<div dir="ltr" style="position: relative; width: 1138px; height: 653px">
<div
aria-label="A chart."
style="
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
"
>
</div>
</div>
</div>
<div
aria-hidden="true"
style="
display: none;
position: absolute;
top: 663px;
left: 1148px;
white-space: nowrap;
font-family: Arial;
font-size: 15px;
font-weight: bold;
"
>
</div>
<div></div>
</div>
</div>
Related
I am developing a little Fantasy Football web. For the lineup, I want to put some div's with the players data above an image of a football field, and want to make it responsive too.
My example code:
HTML:
<div class="container" style="position: relative;" >
<div class="tag">player</div>
<img class="img-fluid" id="image" src="<?php echo base_url() ?>assets/img/grass.jpg">
</div>
CSS:
<style type="text/css">
.tag {
float: left;
position: absolute;
left: 55px;
top: 100px;
z-index: 1000;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
}
The problem comes when the browser resizes or it's in mobile version, since the position of the divs goes elsewhere, even out of the image. There is way to establish the div's position relative to the image itself? So no matter if I access through a desktop or a cellphone it maintains its position and I can see the players in the position that I want. And in this case, it's better to have an image or maybe a div with a image background? Or maybe a bootstrap method/class can do something similar.
Desktop:
Mobile:
What I want to accomplish (edited with paint):
The problem is to get the players positioned correctly relative to the grass image whatever the device dimensions.
You can get a container div to take on the size of its contents by making it display: inline-block. Then you want the grass to fill as much as possible of the screen - but it must keep its aspect ratio. The method you have (using img rather than background-image) is probably the better one to use here because the sizing will occur automatically.
Once you have done that you can position your players in the x and y directions by giving their percentage positions. Also if you alter your HTML slightly so that the img comes first in the container it will always be behind the players you put afterwards. The players are positioned with absolute, as you have done, so that they do not effect each others' positions.
* {
margin: 0;
padding: 0;
}
.container {
position: relative;
width: auto;
height: auto;
display: inline-block;
}
.tag {
position: absolute;
left: 55%;
top: 80%;
background-color: #92AD40;
padding: 5px;
color: #FFFFFF;
font-weight: bold;
font-size: 2vw;
}
#image {
width:100vw;
max-width: 100vh;
}
<div class="container" >
<img class="img-fluid" id="image" src="https://i.stack.imgur.com/3I0Ie.jpg">
<div class="tag">player</div>
</div>
I have rather arbitrarily set the font-size to be proportional to viewport width, so it shrinks proportionally, but you probably want to think about whether the smallest devices need a larger font size to be readable.
I'm using Vue.js & vuetify to make a SPA.
I have a component that has a background image onto which I'm overlaying a grid. The image adjusts its aspect ratio when I change the width of the page. I want the same behavior on the grid.
I generated the grid using divtable.com/generate. It just gave me a 12x12 table of divs and some css selectors for them. I wanted to have precise control of how I overlay the forms on top of this so decided to go this route.
I'm having trouble adjusting height of the div table cells. The width adjusts just fine and stays aligned, but the height of the cells is constant no matter what. I'm also bit of a css noob. I don't know if vuetify or vue is doing some overriding of the css in the background.
I tried a lot of things. Just setting the height property doesn't work for some reason. I tried to use "scoped" on the style in case something is being overridden. For some reason the height of the cell won't change no matter what. Any help is appreciated. j
A verbatim example of the code can be found here: http://divtable.com/generator/
The only difference is I have the following selectors before the table of divs:
img {
width: 100%;
}
.image-container {
position: relative;
width: 100%;
height: 100%;
}
.image-container .after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Thank you. Wouldn't ask if I wasn't in a bit of a rush to figure this out by tomorrow. Any help is appreciated.
Note: I tried setting a min height. Making it scoped and all sorts of other stuff I found.
I decided for the sake of time just to not use an grid overlay at all and just adjust the components over the image using relative positions. There was no real advantage to using a grid overlay in this case.
From a technical standpoint, I wasn't able to find the exact problem, but it likely wasn't any framework magic, just lack of time in finding the correct CSS selector to adjust.
Thanks for any help. Much appreciated.
img {
width: 100%;
}
.image-container {
position: relative;
width: 95%;
height: 100%;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
margin-left: 10px;
}
.image-container .after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
min-height: 100px;
}
#loadControlDevices {
position: relative;
margin-top: 10.5%;
margin-left: 1.15%;
}
<div class="image-container" >
<div style="height: 100%;">
<img src="scope.ami.png" />
</div>
<div class="after">
<div id="loadControlDevices">
<v-checkbox id="loadControlCB" name="loadControlCB" label="" filled></v-checkbox>
</div>
... other divs following this ...
</div>
</div>
I need to make a page without scrolling in landscape version.
The height of the page to be 100%.
I've tried everything.
In Safari, I always get to scroll the lower region.
And I get a hidden area.
I can not hide the bottom bar.
And I can not reduce the height. I can not make it smaller than 320.
The browser creates an additional white area at the bottom of the page.
(Also, i can't use JS)
I will be grateful to anyone reply.
P.S. In the screenshots is not my site, only to show an effect
There are a few ways you can accomplish this. First, you may be able to simply use a table that fills the entire viewport so that each element is then spaced evenly when switching orientations. You could also solve this using simple CSS so you will have more control and have the ability to take advantage of media queries.
See this working fiddle
First you want to wrap all of your content in a single parent container that fills the entire view. This will prevent content from existing outside of the view.
HTML
<div class="wrapper">
<div class="menu">
The Menu
</div>
<div class="hero">
The Hero
</div>
<div class="head">
Text
</div>
<div class="content">
This is content.
</div>
</div>
CSS
.wrapper {
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
}
From here you can then set each element to take up a certain percentage of the parent container so that rescaling recalculates the elements proportions instead of forcing a scroll.
.menu, .hero, .head, .content {
position: absolute;
left: 0;
width: 100%;
}
.menu {
top: 0;
height: 10%;
background: #eee;
}
.hero {
top: 10%;
height: 20%;
background: #aee;
}
.head {
top: 30%;
height: 10%;
background: #eae;
}
.content {
top: 40%;
height: 60%;
background: #eea;
}
Implementing it this way will allow you to have a bit more control of the behavior of each element as the view size changes.
Is it possible to change the height of an HTML element when the viewport resizes with pure CSS? It's hard to explain the problem, but I'm still going to try:
What I want, is a page with a header, content and a footer, like most webpages. As I'm working with a 1920x1080 monitor, I'm using that as my standard. The problem however is that not everyone is using a 1080p monitor. Some are using the older standard, 1280x1024 or using a tablet where the height can be 2560px (I'm not doing smartphones, as they will have a completely different design due to the small screen width). On my page I have images, covering a fixed width. If this width is greater than the width of the viewport, the images will be displayed underneath each other:
(Right-click on the image and select "show image" to view at full size)
As you can see in this image, when the viewport is smaller, the images will stack and will fall from the background. The 'Follow me on:' section even felt of entirely. What I want to do is, when this happens, to make the content div larger, so all of the content stays on the page. I know this is possible using height: auto, but when you do that, the fixed height of the footer will follow after it, and on a screen with a large height, there might be a white border because the document height is smaller than the viewport height.
Take some time to learn min-width, min-height, max-width, max-height, (css attributes) and device-width, device-height (css default values of the client viewports). I can not guarantee they would refresh while you drag/resize the browser window or viewports in devices, but I think they help your style rules.
It's slightly unclear to me what your end-goal is with this so I did my best interpretation. If it's not what you're looking for, give me a good mental image of what you're trying to do and I'll try to correct it.
Live Demo
CSS:
html, body {
box-sizing: border-box;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#wrap {
position: fixed;
top: 0;
bottom: 0;
width: 100%;
}
#header, #content, #footer {
position: absolute;
width: 100%;
}
#header {
top: 0;
height: 70px;
background: lightblue;
}
#content {
overflow-y: auto;
top: 70px;
bottom: 70px;
background: limegreen;
}
#footer {
bottom: 0;
height: 70px;
background: purple;
}
HTML:
<div id="wrap">
<div id="header">Header</div>
<div id="content">Content</div>
<div id="footer">Footer</div>
</div>
First of all, want to say, that I'm not a front-end engineer and my skills of UI and UX are very low.
So my question is:
I have a div with p tags inside. I want to have it width: 700px when the browser window is maximized. But if I put this property in CSS of my div. The text will not shrink if I resize the window. So I want to have it up to a certain point while window is maximized and shrink it if you resize the window, without affecting side-bar div.
To be more clear I will give you an example:
Maximazed Browser window:
Minimized Browser window:
HTML
<!-- HOME -->
<div id="home" class="content">
<h2>Home</h2>
<p>AAAAAAAAAAAAAAAAAAA</p>
<p>BBBBBBBBBBBBBBBBBBBB</p>
</div>
CSS
.content {
padding-bottom: 30px;
position: absolute;
left: 280px;
right: 40px;
top: 0px;
}
.content h2 {
font-size: 110px;
color: #fff;
color: rgba(255,255,255,0.9);
padding: 10px 0 20px 0;
margin-top: 50px;
}
.content p {
color: black;
font-size: 16px;
line-height: 24px;
display: inline-block;
}
You don't need to use Media Queries in your case, but that would be the case in more complicated cases (different breakpoints for example).
Just use max-width: 700px and you're done.
Normal behavior: your paragraph is never wider than 700px.
With very small widths, paragraph occupies the whole width as would any block element and it's still smaller than 700px so no need for MQ!
See this fiddle to see it into effect: http://jsfiddle.net/LQbgJ/ (I used 200px instead of 700)
Compatibility should be IE7+
What you want are Media Queries. Take a look at the W3C recommendations for them.
Basically, the syntax is as follows:
#media screen and (min/max-width: ){
//do something
}
These are called 'break points'. Which means, at the point where the browser reaches the min/max width you provide, you can over-rule other css. So you can make your p and div sizes different.
#media screen and (min/max-width: ){
div {
width: 200px;
}
p {
font-size: 20px;
}
}
Also take a look at Smashing Magazine's tutorial on how to use them.