Full size page background image ignore margins - python

I am trying to create a PDF via the python weasyprint library HTML converter. I want to use a full page background image (svg) that contains the headers/footers and overlay content on top of them.
The issue is regarding page breaks... In order for the image to be full size I set the #page margin to 0, but then of course the page doesn't break until the very bottom. If I set the margins to a decent page break distance I then can't get the image to be full page size disregarding the margins.
Is there a way to circumvent this problem or is the idea doomed to failure

I don't really see your problem, but if you want a background image that covers the full window, you could set it to the body and make the body's min-width and min-height to 100vw and 100vh like so:
body {
margin: 0;
min-width: 100vw;
min-height: 100vh;
background-image: url("YOUR_IMG_URL");
background-size: contain; /*or cover or whatever you like*/
}
<html>
<head>
</head>
<body>
</body>
</html>

<style>
image
{
margin: 0px;
width: 100%;
height: 100%;
}
</style>

Related

How to generate already modified reports in python

I write a program in python that generates 5 reports. One of them is just text and the rest is a data frame. Right now my reports have a really simple design(basic). I need to modify the program to give user ready report that looks good and clear. In 4 of them, I need to add some text before df. The text should be formatted, just like my df. I try to do it using HTML, but I have a problem. I don't know how to modify a table. I wanted to use <style> to make some modifications but there is a problem. First I will show you my code:
html = f'''
<html>
<head>
<title>Knury Hodowlane</title>
</head>
<style type="text/css">
table
{
width: 75%
height:100px;
padding: 10px;
margin: 15px auto 15px auto;
background-color: white;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
box-shadow: 5px 5px 50px grey;
-moz-box-shadow: 5px 5px 50px grey;
-webkit-box-shadow:5px 5px 50px grey;
}
</style>
<body>
<div><img src='krowa-iz.jpg' width ="170" alt="" style="float:left;"></div>
<h1><b><center>INSTYTUT ZOOTECHNIKI</center></b></h1>
<p><h1><b><center>PAŃSTWOWY INSTYTUT BADAWCZY</center></b></h1></p>
<h3><b><center>ZAKŁAD HODOWLI TRZODY CHLEWNEJ</center></b></h3>
<p></p>
<h3><p><b><center>EKSPERTYZA NR ......</center></b></p></h3>
<p><center>W ZAKRESIE REKOMENDACJI DO BRAKOWANIA TZW "MINUS WARIANTÓW" Z POŚRÓD KNURÓW STADNYCH POD WZGLĘDEM ZBIORCZEJ WARTOŚCI HODOWLANEJ (<span style="color: red">ZWH</span>)</center></p>
<p></p>
<p></p>
<h3><p>RANKING KNURÓW STADNYCH POD WZGLĘDEM <span style="color: red">ZWH</span> (ROSNĄCO)</p></h3>
{knuryDF.to_html()}
</body>
</html>
'''
with open('raport_html.html','w') as f:
f.write(html)
In my code I use f''', I need it to insert my data frame, but in this case, my code between table and </style> is no longer text and gonna generates an error. My code in style -> table is random I just wanted to check if this gonna work. Is any way to do it right? Maybe is a much better solution that I don't know. My report doesn't need to be an HTML file. In the beginning, I wanted to write it in excel but I don't know how.
Any help will be great. Thanks for any help.

Button image not showing

I'm just learning how to use Django and HTML, and I encountered such a problem that my image is not displayed on the button, I don't understand what the error is and I will be grateful if someone can help me fix it
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title></title>
<style>
button {
background-image: url("/main/static/main/img/i.jpg");
padding-left: 32px;
padding-top: 10px;
padding-bottom: 10px;
background-repeat: no-repeat;
width: 320px;
height: 320px;
}
</style>
</head>
<body>
<button></button>
</body>
</html>
<button>
<img src=path />
</button>
would be easy solution? It depends how do you want it to be displayed. As button and inside a image or just image which can be clicked on?
Your image path must exists somewhere where it can pull it from.
EDIT: If you have Firefox Web Browser you can probably see in console (by pressing F12 on keyboard) what's the error message help you identify the source of the problem. I tried your code with another path to image and it works just the image is not centered vertically nor horizontally

Arrange pictures with links in a row streamlit

I have several icons that I want to line up at the end of the application. So that when I click on the image, I was transferred to a link. How should I do it?
So far, I have only managed to add this implementation through st.markdown.but they are arranged vertically because I added a new item every time I wrote markdown.
You can create custom components in streamlit using HTML. Maybe you can create a social media component.
Create a file my_component.html
<html>
<head>
<style>
.body {
height: 64px;
}
.parent {
width: 100%;
height: auto;
display: flex;
justify-content: center;
}
.child {
margin: 5px;
height: 32px;
width: 32px;
}
</style>
</head>
<body>
<div class="parent">
<a class = "child" href="https://www.google.com"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/1200px-Google_%22G%22_Logo.svg.png" alt="alt" style="width:32px;height:32px;"></a>
<a class = "child" href="https://wwww.reddit.com"><img src="https://www.redditinc.com/assets/images/site/reddit-logo.png" alt="alt" style="width:32px;height:32px;"></a>
<a class = "child" href="https://wwww.facebook.com"><img src="https://facebookbrand.com/wp-content/uploads/2019/04/f_logo_RGB-Hex-Blue_512.png?w=512&h=512" alt="alt" style="width:32px;height:32px;"></a>
</div>
</body>
</html>
I've added 3 links to google, reddit,and facebook respectively. Add or edit these to something custom.
In the streamlit file, you can import HTML files as components using the components library. The implementation I'm sharing is a very simplified version.
import streamlit as st
import streamlit.components.v1 as components
HtmlFile = open("my_component.html", 'r', encoding='utf-8')
source_code = HtmlFile.read()
print(source_code)
st.text("Navbar Component")
components.html(source_code)
It's a bit basic but yields something like this.

css display: block is not working on flask?

I'm starting learning flask and I'm planning on makin a sorting algorithm visualizer using flask and I'm tryin to represent the elements of the array as bars (the height of the bars is = to the value of each element in the array). I'm thinking to use the display: block but it does not appear on the page. Pls help me or suggest anything if this is possible
html file:
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
<link rel="stylesheet" href="{{ url_for('static', filename='design.css') }}">
</head>
<body>
<div class="bar">
<p>test</p>
</div>
</body>
</html>
css file:
.bar{
display: inline-block;
height: 120px;
width: 5px;
background-color: red;
color: white;
}
this what only shows on my page. other css property works well this display: bar was the only problem
Normally this is an issue with browser caching. If you did not use a file and added it directly to <head> it should work
<head>
<style>
.bar{
display: inline-block; /*You want block or inline-block?*/
height: 120px;
width: 5px;
background-color: red;
color: white;
}
</style>
</head>
If you really want to use the css file, use versioning in the url:
/static/design.css/?v=1 next time /static/design.css/?v=2
But it becomes tedious. You can add a random variable like this:
import uuid
v = str(uuid.uuid4())
# url_for('static', filename='design.css', v=v)
Please clarify your answer using a screenshot of what is happening now

How do i place 2 CSS rectangles side by side? By default, they appear one below the other

Here is the code:
<head>
<meta http-equiv="refresh" content="01">
<title>
Slot Data
</title>
</head>
<body>
<style>
div
{
height: 100px;
width: 50px;
background-color: green;
}
</style>
<div></div>
<style>
div
{
height: 100px;
width: 50px;
background-color: green;
}
</style>
<div></div>
</body>
They appear exactly one below the other.
Also, I need a way to change the color "green" to "red" for a condition written in python. For which, the snippet is:
if count1 >= 0.65 * 122*85:
print "car0 absent"
cv2.rectangle(dst1,(8,8),(340,488),(0,255,0),2) #green
cv2.putText(dst1,'slot empty',(12,450), font, 1,(255,255,255),1,cv2.LINE_AA)
f = open('test.html','r')
filedata = f.read()
f.close()
newdata = filedata.replace("red","green")
f = open('test.html','w')
f.write(newdata)
f.close()
else:
print "car0 present"
cv2.rectangle(dst1,(8,8),(340,488),(0,0,255),2) #red
cv2.putText(dst1,'slot occupied',(12,450), font, 1,(255,255,255),1,cv2.LINE_AA)
f = open('test.html','r')
filedata = f.read()
f.close()
newdata = filedata.replace("green","red")
f = open('test.html','w')
f.write(newdata)
f.close()
and I have the same code for another car1.
How do i address the two rectangles differently? the replacing mechanism will replace the colors of both the CSS rectangles, which I do not want.
Any help is appreciated.
<div> are normally displayed as block level elements but can be made to display next to each other with display: inline-block.
You seem pretty new to CSS/HTML and might do well to do some research or tutorials to get a firmer grasp on things-- CSS can be strange at first, but gets much easier as you get more familiar with it.
Personally, I would use classes to target the elements appropriately. As for getting elements by class in Python, I'm not really sure-- I can't say I know off the top of my head how you are manipulating these things with Python at all-- is this displaying/executing in a browser?
I created a snippet below w/ an example.
.rect {
height: 100px;
width: 50px;
display: inline-block;
background-color: green;
}
.alert {
background-color: red;
}
<head>
<!--<meta http-equiv="refresh" content="01">-->
<title>
Slot Data
</title>
</head>
<body>
<div class="rect"></div>
<div class="rect alert"></div>
</body>
Please note, there are other ways to do this-- CSS provides all sorts of positioning/layout tools. Good luck!
You can use float:left to make them display next to eachother.
float:left
Just remember to clear it, if you want a second row. Just create a small element with the styling
clear:both;
Here's a handy fiddle that will really help in understanding how this css works:
https://jsfiddle.net/nfnneil/6jgsp9dx/

Categories

Resources