是否可以在hr标签上设置宽度并将其浮动到左侧?

时间:2016-12-17 19:49:31

标签: css html5 css3

我希望通过设置hr来控制max-width: 250px;标记的大小,但这也会使元素居中。你能告诉我如何将元素放在左边吗?我已经尝试float:left,但hr已取消

.dash{
  border: 0 none;
  border-top: 2px dashed #322f32;
  background: none;
  height:0;
   max-width: 250px;

} 
<hr class="dash" />

2 个答案:

答案 0 :(得分:3)

只需添加margin-left:0;

即可

.dash {
  border: 0 none;
  border-top: 2px dashed #322f32;
  background: none;
  height: 0;
  max-width: 250px;
  margin-left: 0;
}
<hr class="dash" />

答案 1 :(得分:0)

您可以考虑使用div包装hr并将max-width应用于div元素而不是hr

检查代码段

# List of possible types:
possible_types = ["Low_Economy", "Standard_Economy", "High_Economy", "Business", "First", "Residence"]

class SeatBooking:
    # a set of possible types:
    possible_types = frozenset(seat_type.lower() for seat_type in possible_types)

    def __init__(self, seat):
        # Just check if it's in the possible types otherwise raise an Exception.
        if seat.lower() not in self.possible_types:
            raise ValueError("Sorry, but this is not a valid answer.")
        self.seat = seat

# Use the `while` loop where you expect the `input`:
while True:
    seat_type = input("What type of ticket would you like? The possible types "
                      "are: {}. ".format(possible_types))
    try:
        # Try to create an instance and if it works break out of the loop
        seat = SeatBooking(seat_type)
        break
    except ValueError as exc:
        # Print the string saved in the exception.
        print(exc)
.dash {
  height: 0;
  max-width: 250px;
}
.dash hr {
  border: 0 none;
  border-top: 2px dashed #322f32;
  background: none;
}

希望有所帮助