在帖子中隐藏任何文字之前的第一张图片(无可用段落)

时间:2019-05-18 12:43:10

标签: javascript jquery html css

在Blogger中,段落未包含在from Tkinter import * import serial import time from datetime import datetime ser = serial.Serial('/dev/ttyACM0', 9600, writeTimeout=0) def println(str): print(str) def handler(event): move = "" if event.char == "w": move = "Forward" current_time=time.strftime("%H:%m:%S") elif event.char == "s": move = "Backward" current_time=time.strftime("%H:%m:%S") elif event.char == "d": move = "Right" current_time=time.strftime("%H:%m:%S") elif event.char == "q": move = "left_forward" current_time=time.strftime("%H:%m:%S") elif event.char == "e": move = "right_forward" current_time=time.strftime("%H:%m:%S") elif event.char == "a": move = "Left" current_time=time.strftime("%H:%m:%S") elif event.char == "x": move = "Stop" current_time=time.strftime("%H:%m:%S") elif event.char == "j": move = "Speed set to high" elif event.char == "k": move = "Speed set to medium" elif event.char == "l": move = "Speed set to low" else: # print "Invalid Input" pass #return print current_time + " " + move global ser ser.write(str.encode(event.char)) if __name__ == "__main__": root = Tk(className=" Remote Control for RoboSapien") quitButton = Button(text='Quit', command=quit, takefocus=1) quitButton.bind("<KeyPress-H>", println) arrUp = PhotoImage(file="upArrow.gif") arrDown = PhotoImage(file="downArrow.gif") arrLeft = PhotoImage(file="leftArrow.gif") arrRight = PhotoImage(file="rightArrow.gif") stop = PhotoImage(file="stop.gif") panelU = Button(root, image=arrUp, command=lambda: println("Up")) panelD = Button(root, image=arrDown, command=lambda: println("Down")) panelL = Button(root, image=arrLeft, command=lambda: println("Left")) panelR = Button(root, image=arrRight, command=lambda: println("Right")) panelStop = Button(root, image=stop, command=lambda: println("Stop")) panelU.grid(row=1, column=2) panelD.grid(row=3, column=2) panelL.grid(row=2, column=1) panelR.grid(row=2, column=3) panelStop.grid(row=2, column=2) root.bind('<Key-w>', handler) root.bind('<Key-s>', handler) root.bind('<Key-a>', handler) root.bind('<Key-d>', handler) root.bind('<Key-q>', handler) root.bind('<Key-e>', handler) root.bind('<Key-r>', handler) root.bind('<Key-t>', handler) root.bind('<Key-x>', handler) root.bind('<Key-j>', handler) root.bind('<Key-k>', handler) root.bind('<Key-l>', handler) # panelL.bind('<Button-1>') # panelR.bind('<Button-1>') # panelStop.bind('<Button-1>') quitButton.grid(row=4, column=3, ipadx=10, ipady=10) root.mainloop() 标记中,而是显示为带有换行符(<p></p>)的纯文本。我想隐藏出现在任何文本之前的第一张图像,而不是隐藏在出现任何文本之前的第一张图像。

例如:

<br/>

在此示例中隐藏图片:

This is some text (image AFTER text should be visible):

    <img src="image.png"/>

1 个答案:

答案 0 :(得分:0)

由于无法在CSS中操作文本节点,因此这是解决问题的一种干净方法:

通过绝对定位图片使其显示在文本之前,并在父帖子div上添加填充

.post {
  padding-top: 150px;
  position: relative;
}

.post img {
  display: none;
}

.post img:first-of-type {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  height: 150px;
}
<div class="post">
  Hello there is a hidden image below Hello there is a hidden image below
  <img src="https://via.placeholder.com/350x150" />
  <img src="https://via.placeholder.com/350x150" />
  <img src="https://via.placeholder.com/350x150" />
</div>

<div class="post">
  <img src="https://via.placeholder.com/350x150" /> Hello there is a hidden image below Hello there is a hidden image below
  <img src="https://via.placeholder.com/350x150" />
  <img src="https://via.placeholder.com/350x150" />
</div>