单独使用CSS移动元素

时间:2018-07-24 19:04:42

标签: css html

由于某些原因,我无法编辑下面提到的代码(由于它是由Wordpress插件生成的),我只能通过CSS进行控制和更改,因此我的问题是我可以使元素e1和e2彼此平行吗其他?并排?单独使用CSS?

@class='attribute-value'

2 个答案:

答案 0 :(得分:1)

如@Krzysiek Drozdz所述,您可以使用浮点数。

这里是一个示例: https://codepen.io/junkrig/pen/bjRgdO

<div class="layer-content">
<a target="_self" class="element element_0 title_link" href="http://example.com/wordpress/index.php/2018/07/23/student/">STUDENT 1’S NEW</a>


<div id="e1" class="element element_1 author">admin</div> // Element1
<div id="e2" class="element element_2 post_date">July 23, 2018</div> // element2


<div class="element element_3 excerpt">Nick is a Sophomore</div>
<div class="element element_4 categories"><a href="http://example.com/wordpress/index.php/category/music-videos/" title="IDEOS">VIDEOS</a> 
</div>
</div>

您只需要一个

.element_1 {
    float: left;
    height: 100px;
    width: 200px;
}
.element_2 {
    margin-left: 200px;
    height: 100px;
}

或容器div将其移动到标题为“ STUDENT 1’S NEW”下。例如:

<br />

您可以使用百分比代替宽度/左边距值,例如:

<div class="container">
    <div id="e1" class="element element_1 author">admin</div> 
    <div id="e2" class="element element_2 post_date">July 23, 2018</div> 
</div>

答案 1 :(得分:0)

是的,您可以尝试以下操作:

.layer-content{
  width: 200px;
  height:auto;
  position:relative;
  overflow:hidden;
}
.layer-content .container{
  width:100%;
  height:auto;
  overflow:hidden;
  position:relative;
  border:1px solid rgba(0,0,0,0.1);
}
.layer-content .container #e1{
  width:50%;
  float:left;
  position:relative;
  text-align:center;
  padding:5px;
  box-sizing:border-box;
}
.layer-content .container #e2{
  width:50%;
  float:right;
  position:relative;
  text-align:center;
  padding:5px;
  box-sizing:border-box;
  background-color:#4bbfee;
  color:#fff;
}
<div class="layer-content">
  <a target="_self" class="element element_0
  title_link"href="http://example.com/wordpress/index.php/2018/07/23/student/">STUDENT 1’S NEW</a>


  <div class="container">
    <div id="e1" class="element element_1 author">admin</div>
    <div id="e2" class="element element_2 post_date">July 23, 2018</div>
  </div>


  <div class="element element_3 excerpt">Nick is a Sophomore</div>
  <div class="element element_4 categories"><a      href="http://example.com/wordpress/index.php/category/music-videos/"      title="IDEOS">VIDEOS</a> 
  </div>
</div>