使用CSS在矩形的右侧创建动态三角形大小

时间:2018-11-05 14:08:26

标签: css

我想实现以下目标:

enter image description here

但是,由于右侧区域是一段可能包含很多内容或内容很小的段落,因此im混淆了如何创建三角形但具有动态大小的三角形。

我暂时无法弄清楚结构

1 个答案:

答案 0 :(得分:1)

因此,如果您想在那里有一个三角形,那么您绝对可以使用CSS为该部分创建一个三角形。这是一个快速演示,它浮动了两个div并使用CSS三角形。

三角形CSS:

width: 0px;
height: 0px;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
border-left: 10px solid #fff;

一起:

* {
  box-sizing: border-box;
}

body {
  background: #ccc;
  margin: 0;
  padding: 0;
}

p {
  margin: 0;
  text-align: center;
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

.wrap {
  margin: 50px auto;
  width: 500px;
}

.inner {
  position: relative;
  height: 100px;
  width: 100%;
}

.left {
  float: left;
  background: #fff;
  height: 100px;
  position: relative;
  width: 30%;
}

.right {
  float: left;
  background: #4c4c4c;
  height: 100px;
  padding: 0 40px;
  width: 70%;
}

.border {
  border: 1px solid yellow;
  border-style: dashed;
  position: absolute;
  top: 0;
  left: 0;
  width: 96%;
  height: 80px;
  top: 50%;
  transform: translateY(-50%);
  right: 0;
  margin: 0 auto;
}

.arrow-left {
  width: 0px;
  height: 0px;
  position: absolute;
  top: 0;
  right: -10px;
  border-top: 50px solid transparent;
  border-bottom: 50px solid transparent;
  border-left: 10px solid #fff;
}
<div class='wrap'>
  <div class='inner'>
    <div class='left'>
      <p>Lorem Ipsum <br>Lorem ipsum dolor</p>
      <div class='arrow-left'></div>      
    </div>
    <div class='right'><p>Lorem Ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.</p></div>
    <div class='border'></div>
  </div>
</div>

JSFiddle:http://jsfiddle.net/8ogzcLhy/2/

注意:此布局使用浮点数,可以使用浮点数来使用flex-box,而 //1. Create the alert controller. let alert = UIAlertController(title: "Title", message: "Description", preferredStyle: .alert) //2. Add the text field. You can configure it however you need. alert.addTextField { (textField) in textField.placeholder = "User" } alert.addTextField { (textFieldPass) in textFieldPass.placeholder = "Password" textFieldPass.isSecureTextEntry = true } // 3. Grab the value from the text field, and print it when the user clicks OK. alert.addAction(UIAlertAction(title: "Cancelar", style: .default, handler: { [weak alert] (_) in print("cerrar") })) alert.addAction(UIAlertAction(title: "Aceptar", style: .default, handler: { [weak alert] (_) in let textField = alert?.textFields![0] let textFieldPass = alert?.textFields![1] print("Text field: \(textField!.text)") print("Text field: \(textFieldPass!.text)") self.Autentificacion(usuario: textField!.text!, clave: textFieldPass!.text!) })) // 4. Present the alert. self.present(alert, animated: true, completion: nil) 具有可用于制作更简洁布局的各种出色功能。