Python 破折号 Div 整页背景图片
Python dash Div full page background image
抱歉,我是 dash 的新手,css,html 编码。
我在 Python 上使用 Dash,我想要一个带有图像的简单整页背景。
我正在使用这个 CSS:https://codepen.io/chriddyp/pen/bWLwgP.css
我尝试使用不同的 CSS (https://necolas.github.io/normalize.css/8.0.1/normalize.css) 因为我读到这是一个保证金问题但它没有用
我已经阅读了很多关于这个问题的讨论,但我无法为我的目的修复它
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__,
external_stylesheets = external_stylesheets)
app.title = "Q"
colors = {'background': '#ffffff',
'bg_home': '#666666',
'text': '#ffa500',
'background_plot': '#cccccc',
'text_plot': '#000000'}
app.config['suppress_callback_exceptions']=True
image = 'url(https://c.wallhere.com/photos/a1/fc/1920x1080_px_Albert_Einstein_Formula_mathematics_physics_science_Special_Relativity-549404.jpg!d)'
app.layout = html.Div(
className='row',
style={
'verticalAlign':'middle',
'textAlign': 'center',
'background-image':image,
},
children= [
html.Div(
id='Username',
style={'textAlign': 'center',
'verticalAlign':'middle',
},
children= [
html.H3('Login',
style={'textAlign': 'center',
'color':'orange',
'fontWeight': 'bold',
},
),
html.Div(
className='row',
children=[
dcc.Input(id = 'user',
style={'margin-top':20},
type='text',
placeholder='Username'
)
]
),
html.Div(className='row',
children=[
dcc.Input(id = 'psw',
style={'margin-top':20},
type='text',
placeholder='Password'
)
]
),
html.Div(className='row',
children=[
html.Button('Login',
id='log',
style={'background-color':'white',
'color':'black',
'margin-top': 20,
'textAlign':'right'},
),
]
)
])
]
)
if __name__ == '__main__':
app.run_server(debug=True,host='0.0.0.0',port=8050)
我没有收到错误,但我只看到 1/3(或多或少)带有背景图片和登录名的页面 Div,页面的其余部分完全是白色的。
我只想要一个带有背景图片并在中心登录的完整页面
谢谢大家
在 css 中,body
标签定义了文档的整个主体,而 div
是其中的一部分,有两种方法可以实现此功能。
- 使
div
覆盖整个页面并将图像设置为div
参考这里:
Making a div that covers the entire page
修改了一些代码,
className='row',
style={
'verticalAlign':'middle',
'textAlign': 'center',
'background-image':image,
'position':'fixed',
'width':'100%',
'height':'100%',
'top':'0px',
'left':'0px',
'z-index':'1000'
},
- 将
external_stylesheet
中的body
标签修改为属性background-image
,
body {
'background-image' : url(url!d);
}
抱歉,我是 dash 的新手,css,html 编码。
我在 Python 上使用 Dash,我想要一个带有图像的简单整页背景。
我正在使用这个 CSS:https://codepen.io/chriddyp/pen/bWLwgP.css
我尝试使用不同的 CSS (https://necolas.github.io/normalize.css/8.0.1/normalize.css) 因为我读到这是一个保证金问题但它没有用
我已经阅读了很多关于这个问题的讨论,但我无法为我的目的修复它
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__,
external_stylesheets = external_stylesheets)
app.title = "Q"
colors = {'background': '#ffffff',
'bg_home': '#666666',
'text': '#ffa500',
'background_plot': '#cccccc',
'text_plot': '#000000'}
app.config['suppress_callback_exceptions']=True
image = 'url(https://c.wallhere.com/photos/a1/fc/1920x1080_px_Albert_Einstein_Formula_mathematics_physics_science_Special_Relativity-549404.jpg!d)'
app.layout = html.Div(
className='row',
style={
'verticalAlign':'middle',
'textAlign': 'center',
'background-image':image,
},
children= [
html.Div(
id='Username',
style={'textAlign': 'center',
'verticalAlign':'middle',
},
children= [
html.H3('Login',
style={'textAlign': 'center',
'color':'orange',
'fontWeight': 'bold',
},
),
html.Div(
className='row',
children=[
dcc.Input(id = 'user',
style={'margin-top':20},
type='text',
placeholder='Username'
)
]
),
html.Div(className='row',
children=[
dcc.Input(id = 'psw',
style={'margin-top':20},
type='text',
placeholder='Password'
)
]
),
html.Div(className='row',
children=[
html.Button('Login',
id='log',
style={'background-color':'white',
'color':'black',
'margin-top': 20,
'textAlign':'right'},
),
]
)
])
]
)
if __name__ == '__main__':
app.run_server(debug=True,host='0.0.0.0',port=8050)
我没有收到错误,但我只看到 1/3(或多或少)带有背景图片和登录名的页面 Div,页面的其余部分完全是白色的。
我只想要一个带有背景图片并在中心登录的完整页面
谢谢大家
在 css 中,body
标签定义了文档的整个主体,而 div
是其中的一部分,有两种方法可以实现此功能。
- 使
div
覆盖整个页面并将图像设置为div
参考这里: Making a div that covers the entire page
修改了一些代码,
className='row',
style={
'verticalAlign':'middle',
'textAlign': 'center',
'background-image':image,
'position':'fixed',
'width':'100%',
'height':'100%',
'top':'0px',
'left':'0px',
'z-index':'1000'
},
- 将
external_stylesheet
中的body
标签修改为属性background-image
,
body {
'background-image' : url(url!d);
}