热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

垂直中心在div内部旋转div-Verticalcenterarotateddivinsideadiv

Idontgetit;-(我不明白;-(Iwanttocenteradivwithatextcontainedinanotherdiv.Theinnerd

I don't get it ;-(

我不明白;-(

I want to center a div with a text contained in another div. The inner div is rotated by 90 degres. So far so good. My problem is that I can't get the inner div to align horizontal to the left of the outer div. How can this be done?

我想将div与另一个div中包含的文本居中。内部div旋转90度。到现在为止还挺好。我的问题是我不能让内部div在外部div的左边水平对齐。如何才能做到这一点?

Here is the fiddle

这是小提琴

HTML:

12345678901234567890

CSS:

div {
    border: 1px solid red;    
}

.outer {
    position: absolute;
    top: 0px;
    height: 300px; 
    width: 30px;   
}

.inner {
    transform: translateX(-50%) translateY(-50%) rotate(90deg);
    margin-left: 10px;
    position: relative;
    top: 50%;
    text-align: center;
}

Painted

3 个解决方案

#1


Set the inner div to position:absolute too.

将内部div设置为position:absolute。

http://jsfiddle.net/r4vrf7pg/8/

div {
    border: 1px solid red;
}
.outer {
    position: absolute;
    top: 0px;
    height: 300px;
    width: 30px;
}
.inner {
    transform: translateX(-50%) translateY(-50%) rotate(90deg);
    margin-left: 10px;
    position: absolute;
    top: 50%;
    text-align: center;
}
12345678901234567890

#2


.inner {
    ...
    transform: translateX(-50%) translateY(-50%) rotate(90deg);
    margin-left: 10px;
}

Demo

There are probably easier ways to accomplish this. Rotating the parent element would eliminate some complexity, I think.

可能有更简单的方法来实现这一目标。我认为,旋转父元素可以消除一些复杂性。

#3


EDIT: So this won't work if you plan on making more of these with different widths but for right now if I just add margin-left: -72px; to the .inner class it aligns to the left of the inside of the .outer div.

编辑:所以如果你打算用不同的宽度制作更多这些,但是现在如果我只是添加margin-left:-72px;到.inner类,它对齐.outer div内部的左边。

.inner {
    transform: translateY(-50%) rotate(90deg);
    position: relative;
    top: 50%;
    margin-left: -72px;
    text-align: center;
    width: auto;
}

推荐阅读
author-avatar
智勇双全882602900857_984
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有