针对html–可以扩展父容器大小的子元素的垂直对齐方式和html可扩展区域元素这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展android–linearlayout中的垂直对齐方式、css
针对html – 可以扩展父容器大小的子元素的垂直对齐方式和html可扩展区域元素这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展android – linearlayout中的垂直对齐方式、css – 为什么孩子垂直边距不能扩展父容器?、css属性设置元素的垂直对齐方式_html/css_WEB-ITnose、html – a元素和button元素的垂直位置等相关知识,希望可以帮助到你。
本文目录一览:- html – 可以扩展父容器大小的子元素的垂直对齐方式(html可扩展区域元素)
- android – linearlayout中的垂直对齐方式
- css – 为什么孩子垂直边距不能扩展父容器?
- css属性设置元素的垂直对齐方式_html/css_WEB-ITnose
- html – a元素和button元素的垂直位置
html – 可以扩展父容器大小的子元素的垂直对齐方式(html可扩展区域元素)
我正在尝试按照以下方式创建布局,其中问题的帮助文本在问题容器中垂直对齐.
我的问题是当帮助文本超出问题控件的高度时如何扩展父容器.按照:
我知道这是因为我使用绝对定位来垂直居中帮助文本,因此它不包含在父容器的流中.但是我不确定这个问题的最佳css解决方案.
position: absolute;
top: 50%;
transform: translateY(-50%);
我创建了以下小提琴来说明我现有的解决方案/问题:
jsfiddle
对于这个问题的最佳结构,我将不胜感激.
如果您之前的问题是垂直居中,我会建议您采用不同的方法.您可以将容器转换为display:table元素,并将两者作为主要内容,并将工具提示作为display:table-cell.这样,您将能够以更加可靠的方式将其放置在右侧,垂直对齐将与vertical-align:middle一起使用.
这将使您的容器适合工具提示.另外,我添加了位置:相对;左:20像素;把它放错一点,就像在你的例子中一样……
.cf:before,.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
.container {
position: relative;
border: 1px #000 solid;
display: table;
margin-bottom: 50px;
}
.content,.text {
display: table-cell;
vertical-align: middle;
}
.text {
width: 22.5%;
}
.text > div {
background-color: #ccc;
margin: 5px;
padding: 10px;
position: relative;
left: 20px;
}
android – linearlayout中的垂直对齐方式
我有一个线性布局,像这样:
你可以看到我左侧有一个箭头.它应该指向Message但是你看它是消息的顶部我怎么能像这样对齐它:
我的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/defaultprofile"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingRight="4dp" >
<TextView
android:id="@+id/tweet"https://www.jb51.cc/tag/ara/" target="_blank">arance.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#0A0A14"
android:layout_marginLeft="8dp"
android:textSize="15sp"
android:text="Tolgay Toklar"
android:fontFamily="sans-serif-condensed"
/>
<ImageView
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/sagokgri"/>
<TextView
android:id="@+id/bio"https://www.jb51.cc/tag/ara/" target="_blank">arance.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#474747"
android:layout_marginLeft="8dp"
android:maxLines="3"
android:text="Message"
android:textSize="11sp"
android:layout_marginTop="0dp"/>
</LinearLayout>
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:src="@drawable/anchor" />
</LinearLayout>
解决方法:
删除ImageView并像drawableLeft一样使用它,如下所示:
<TextView
...
android:text="Message"
android:drawableLeft="@drawable/sagokgri"
.../>
css – 为什么孩子垂直边距不能扩展父容器?
任何人都可以说明为什么会这样吗?
更新:
我发现添加任何填充或边框值给父代也修复了这一点。
Updated Example
解决方法
Floats,absolutely [and fixed] positioned elements,block containers (such as
inline-blocks,table-cells,and table-captions) that are not block
Boxes,and block Boxes with ‘overflow’ other than ‘visible’ (except
when that value has been propagated to the viewport) establish new
block formatting contexts for their contents.
这是块格式上下文的这种变化,这就是为什么在评论中给出的上述解决方案如何运作的缘故(以及前一个浮动的情况下,后续流入元素的填充)的原因。
css属性设置元素的垂直对齐方式_html/css_WEB-ITnose
vertical-align 属性设置元素的垂直对齐方式。
可能的值
值 | 描述 |
---|---|
baseline | 默认。元素放置在父元素的基线上。 |
sub | 垂直对齐文本的下标。 |
super | 垂直对齐文本的上标 |
top | 把元素的顶端与行中最高元素的顶端对齐 |
text-top | 把元素的顶端与父元素字体的顶端对齐 |
middle | 把此元素放置在父元素的中部。 |
bottom | 把元素的顶端与行中最低的元素的顶端对齐。 |
text-bottom | 把元素的底端与父元素字体的底端对齐。 |
length | |
% | 使用 "line-height" 属性的百分比值来排列此元素。允许使用负值。 |
inherit | 规定应该从父元素继承 vertical-align 属性的值。 |
{
display: inline-block;
font-size: 12px;
line-height: 16px;
vertical-align: -webkit-baseline-middle;
}
{
padding: 1px 0px 1px 3px;
display: inline-block;
overflow: hidden;
line-height: 0em;
}
立即学习“前端免费学习笔记(深入)”;
html – a元素和button元素的垂直位置
button,a { border: solid 1px black; background-color: white; color: black; font-family: 'Arial'; padding: 0 15px; font-size: 13px; height: 35px; line-height: 35px; display: inline-block; } #dummy-block { background-color: black; padding: 0; margin: 0; height: 20px; }
<div id="dummy-block"></div> <button>My Button</button> <a>My Link</a>
但是< button>元素似乎忽略了高度和我的< a>元素不会触及黑色虚拟< div>的边缘以上:
您可以在我的小提琴中测试代码:http://jsfiddle.net/gyrrcrqc/1/
解决方法
button,a { background-color: white; border: medium none; Box-shadow: 0 0 1px #000 inset; color: black; display: inline-block; font-family: "Arial"; font-size: 13px; height: 35px; line-height: 35px; padding: 0 15px; vertical-align: top; }
要么:-
button,a { background-color: white; border: medium none; vertical-align:top; color: black; display: inline-block; font-family: "Arial"; font-size: 13px; height: 35px; line-height: 35px; padding: 0 15px; border:1px solid #000; Box-sizing:border-Box }
DEMO2
DEMO
关于html – 可以扩展父容器大小的子元素的垂直对齐方式和html可扩展区域元素的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于android – linearlayout中的垂直对齐方式、css – 为什么孩子垂直边距不能扩展父容器?、css属性设置元素的垂直对齐方式_html/css_WEB-ITnose、html – a元素和button元素的垂直位置的相关知识,请在本站寻找。
本文标签: