我已经开始直接研究基于 XLib 的 GUI 应用程序编程,我正在尝试在屏幕上创建一个居中的窗口。我不知道用于实现此目的的常用技术。我的代码(不起作用)是这样的(我使用 CodeBlocks)
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
int screen;
Display *display;
XSetWindowAttributes window_attributes;
Window mainwindow;
XEvent events;
int main(int argc, char** argv) {
display = XOpenDisplay(NULL);screen = DefaultScreen(display);
window_attributes.background_pixel = XWhitePixel(display, screen);
window_attributes.border_pixel = XBlackPixel(display, screen);
window_attributes.win_gravity = SouthWestGravity;
mainwindow = XCreateWindow(display,
RootWindow(display, screen),
1, 1,
600, 400,
0,
CopyFromParent,
InputOutput,
CopyFromParent,
CWBackPixel|CWBorderPixel,
&window_attributes
);
XMapWindow(display, mainwindow);
XFlush(display);
XSelectInput(display, mainwindow, ExposureMask|KeyPressMask|ButtonPressMask);
while (1) …Run Code Online (Sandbox Code Playgroud) 我试图将一个textview集中在一个tablerow中,它本身就在一个tablelayout中,但我想我错过了一些东西,因为TextView没有集中:s
这是我的方法:
private void insertClock() {
TableLayout table = new TableLayout(this);
table.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
table.setStretchAllColumns(true);
TableRow tbRow = new TableRow(this);
TableLayout.LayoutParams layoutRow = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
clock = new TextView(this);
TableRow.LayoutParams layoutHistory = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
clock.setLayoutParams(layoutHistory);
clock.setText(calculateClockText());
tbRow.setLayoutParams(layoutRow);
table.addView(tbRow);
clock.setGravity(Gravity.CENTER_HORIZONTAL);
tbRow.addView(clock);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢 ;)
使用 CSS 在页面上居中而不是使用标签有什么显着区别?
会影响页面布局、兼容性等吗?
非常感谢。
目标:将 a 中包含的文本居中div,并且该文本是div包含该video元素的 a 的同级文本。
问题:我正在使用 Flexbox 来查看是否可以调整 div 的内容中心并沿垂直轴对齐其项目中心。它很好地沿 x 轴居中,但不沿 y 轴居中。
有什么建议么?
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
video {
position: fixed;
top: -100px;
}
.text {
z-index: 2;
color: #fff;
font-size: 2em;
text-transform: uppercase;
position: relative;
display: flex;
justify-content: center;
align-items: center;
/*border: 1px solid black;*/
/*height: 100%;*/
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<video poster="http://www.thecanyon.com/assets/css/images/grandcanyon1.jpg" muted="true" autoplay="true">
<source src="assets/Homepagevideo.mp4" type="video/mp4"></source>
</video>
</div>
<div class="text">
<p>This is a cool …Run Code Online (Sandbox Code Playgroud)我正在使用 Bootstrap 网格系统并在每个列中显示一个图像,但我没有成功地将图像垂直和水平居中。这是我的代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7"
crossorigin="anonymous">
<style>
.center_image {
margin: auto;
margin-left: auto;
margin-right: auto;
}
.vcenter {
display: inline-block;
vertical-align: middle;
float: none;
}
</style>
</head>
<body>
<!-- images section -->
<div class="container">
<div class="row" style="display: flex; padding: 20px 0px 0px 0px;">
<!-- image col1 -->
<div style="background-color: red;" class="col-xs-6 col-sm-6 vcenter">
<img style="width: 100%;"
class="img-responsive center_image img-thumbnail" alt=""
src="http://cdn.theatlantic.com/assets/media/img/photo/2015/11/images-from-the-2016-sony-world-pho/s01_130921474920553591/main_900.jpg?1448476701">
</div>
<!--image col2 -->
<div style="background-color: red;" …Run Code Online (Sandbox Code Playgroud)我已经寻找了大约半天的解决方案。我刚刚开始网页设计,我需要将表单水平和垂直居中。现在它位于左上角。请不要介意糟糕的代码,我很快就会整理它。
form {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.trans {
background:rgba(1,1,1,0.6);
}
body {
background-image: url(wallpaper.jpg);
}
.text {
}
.box {
display: table;
width: 100%;
}Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="icon" type="image/ico" sizes"32x32" href="pths_logo32x.png">
<title>Peq Anon</title>
</head>
<body>
<div class="container">
<form>
<input class="trans text" type="text" name="Password">
<button type="submit" onclick="#">Submit</button>
</form>
</div>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我想将图标居中到 div 元素“矩形”。也欢迎任何其他替代解决方案。
body {
background-color: black;
}
.rectangle {
width: 125px;
height: 125px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
background-color: #fff;
}
h3 {
color: #fff;
}Run Code Online (Sandbox Code Playgroud)
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="rectangle">
<span><i class="fa fa-quora" aria-hidden="true" style="font-size: 75px;" align="center"></i></span>
</div>
<h3>Quora</h3>Run Code Online (Sandbox Code Playgroud)
我想将图像居中mpdf(版本 6>)。
这是我发送到 mpdf 的(缩短的)html 输出。该displayed班没有帮助。
<style>
IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto }
</style>
<img style="max-height:600px" class="displayed" src="/images/size_original/m_princezna_1.jpg"/>
Run Code Online (Sandbox Code Playgroud) 我正在复习一些基本的 CSS,我偶然发现了一个教程,上面写着:
margin: 0 auto 0 auto;
Run Code Online (Sandbox Code Playgroud)
相对于……
margin: 0 auto;
Run Code Online (Sandbox Code Playgroud)
本身,以某事为中心。
有人可以向我解释一下,将 0 auto 放入一次而不是两次有什么区别吗?当我编码时,我没有注意到有什么不同,所以我的猜测是使用 0 auto, once 是做完全相同的事情的简写。
我想将我的表格居中在它所在的水平行的中心。我认为这很简单
#control {
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
我要居中的元素是
<div id="control" class="btn">
<div id="btn_container"><img width="100" height="100" src="https://cdn3.iconfinder.com/data/icons/minecraft-icons/512/Stone_Pickaxe.png" alt="Mining pick" /></div>
<span>Start</span>
</div>
Run Code Online (Sandbox Code Playgroud)
但是,该元素仍未居中 - https://jsfiddle.net/xwdnvcy5/58/。我没有得到什么非常明显的东西,但我无法说出它是什么。